Scriptmanager. registerstartupscript Method

Source: Internet
Author: User

If Ajax is not needed on the page, run a JS section in CS.CodeThe method can be:
Page. clientscript. registerstartupscript (page. GetType (), "", "<SCRIPT> window. Open ('default2. aspx ') </SCRIPT> ");
If Ajax is used on the page, the above CodeEven execution is ineffective. In this case, we usually use:
Scriptmanager. registerstartupscript (this. button1, this. GetType (), "alertscript", "window. Open ('default2. aspx ');", true );
The first parameter is the Control ID of the script to be registered. Try it as long as it is on this page.
The second parameter is the registered script control type. It can be the control or GetType () of this, and the typeof (string) parameter is OK.
The name of the third Script Function.
The fourth is the script content.
The fifth parameter indicates whether to add a script tag. If the fourth parameter contains the <SCRIPT> </SCRIPT> tag, the value is false. Otherwise, the value is true.

Note: The aspx code is as follows:

< Div >
< ASP: updatepanel ID = "Updatepanel1" Runat = "Server" >
< Contenttemplate >
< ASP: textbox Runat = "Server" ID = "Textbox2"   >
</ ASP: textbox >
< ASP: button Runat = "Server" Text = "Button" ID = "Button1" Onclick = "Button#click"   />
</ Contenttemplate >
< Triggers >
< ASP: postbacktrigger Controlid = "Button1"   />
</ Triggers >
</ ASP: updatepanel >
</ Div >

When I register a script in the button#click event, I must add the red part. Otherwise, I will always be prompted not to parse anything!

In addition, JS cannot interfere with the CS code. Therefore, once the script is successfully registered, JS and CS code will run independently.

 

The above content comes from others'ArticleNow, let's talk about your usage: register a script in The onclick event of the button button1 and write it like this: scriptmanager. registerstartupscript (this.Updatepanel1, Page. getType (), system. datetime. now. ticks. tostring (), "window. open ('default2. aspx '); ", true); the red part of the page can also be removed. Note the third parameter "Name of the script function,

If you use this method to register two scripts in the onclick event. If the two registered script functions have the same name, the Second Script Function will not be executed. Because the script Manager uses this string to analyze whether a script has been loaded. If it has been loaded, it will not be rendered again. So the second one won't load the execution.

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.