If Ajax is not required, the method for running a js Code segment in cs can be:
Page. ClientScript. RegisterStartupScript (Page. GetType (), "", "<script> window. open ('default2. aspx ') </script> ");
If Ajax is used on the page, the above Code is ineffective even if executed. To cope with this situation, we usually adopt:
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" nClick = "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.