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.