In web pages, JavaScript is often used, and many times server-side cooperation is also required.
There is a problem here. I need to click the button to perform the initialization operations. These operations need to be executed on the server side and in the user control, and the master is used, in addition, user controls are dynamically loaded, which often results in overwriting operations executed by the client by the server.
The following shows how to bind a client event to a web button.
Btnsave. Attributes. Add ("onclick", "setdropin ();");
The client function defined below
Function setdropin ()
{
If (document. getelementbyid ('dropin1 '))
SetTimeout ("resizedisplayscreensize ()", 200 );
Else
SetTimeout ("setdropin ()", 200 );
}
Because the user control has not been loaded during client operations, client scripts often encounter errors that do not exist. Therefore, we first determine whether the object exists or not. If the object does not exist, we use setTimeout to set a time interval before calling ourselves. If the object already exists, we call the function that actually executes the client script operation. The time interval is a little shorter, and the effect will be good.
This method can also be expanded to execute server-side events first, and then execute the client-side event application, as long as the judgment conditions change, such as judging the values in a hidden text box.