Implement the control to first execute the server-side code and load the client-side code

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.