JavaScript's execution foreground function

Source: Internet
Author: User

1, OnClientClick (VS2003 does not support this method)

<ID= "button"  runat= "Server"  Text= "button" OnClientClick = "Client_click ()" OnClick = "Button1_Click" />

Client_click () is a method of JavaScript.

2, Backstage add Button.Attributes.Add ("onclick", "Return Client_click ()");
"Client_click ()" is a foreground method that can be replaced by a generic script such as: Retrun confirm (' OK to delete? ‘)

3. Write script with Response.Write method
For example, after you click the button, the database is finished, the display is finished, you can write in the last place to call
Response.Write ("<script type= ' Text/javascript ' >alert ();</script>");
One drawback of this approach is that you cannot invoke a custom function in a script file, only call an intrinsic function, and call a custom function to write the function definition only in Response.Write.

such as Response.Write ("<script type= ' Text/javascript ' >function myfun () {...} </script> ");

4. Add scripts dynamically with the ClientScript class
Use the following: Add code where you want to invoke a JavaScript script function, and be sure that Myfun has already been defined in the script file.

" MyScript " " <script>myfun ();</script> "

This method is more convenient than Response.Write, you can directly invoke the custom function in the script file.

StringBuilder SB =New StringBuilder (); sb. Append ( "<script language= ' JavaScript ' > "); Sb. Append ( "button2_onclick (' "  "); Sb. Append ( "</script>  "); Clientscript.registerstartupscript (this. GetType (),  "loadpicscript  ", sb. ToString ());  

JavaScript's execution foreground function

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.