onload called only once

H

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?
 
V

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top