|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
onload called only onceI have a function foo() which gets called on <body onload=foo()> but i want
this function to run only once, once the application loads, all subsequent postbacks should not fire this function. give me a complete solution. How to handle this? -- Hemant Singh Software Programmer Hi Dear Hemant,
In the Page_Load Event Handler Call your Function. As an Example I am showing this If Not Page.IsPostBack then Your Function End If Example: If Not Page.IsPostBack then Dim strConn as string = "server=(local);uid=UID;pwd=PWD;database=Northwind" Dim MySQL as string = "Select LastName from Employees" Dim MyConn as New SQLConnection(strConn) Dim objDR as SQLDataReader Dim Cmd as New SQLCommand(MySQL, MyConn) MyConn.Open() objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection) DropDownList.DataSource = objDR DropDownList.DataBind() End If *********************************************************************** in C# protected void Page_Load ( Object Src, EventArgs E ) { if ( !IsPostBack ) { Your Funciton } } Example: protected void Page_Load ( Object Src, EventArgs E ) { if ( !IsPostBack ) { string query = "select distinct Type from Products"; mySelect.DataSource = fetchData ( query, "gear" ); mySelect.DataBind ( ); } } Bye Venkat_KL For Anything and Everything, Please Let Me Know |
|||||||||||||||||||||||