Home All Groups Group Topic Archive Search About
Author
7 Dec 2005 12:43 PM
hemant
I 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

Author
7 Dec 2005 1:10 PM
Venkat_KL
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

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com