Ajax and ScriptManager. RegisterStartupScript
The method for running a js Code segment in Ajax and cs can be:
Page. ClientScript. RegisterStartupScript (Page. GetType (), "", "<script> window. open ('default2. asp tutorial x') </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>
I have registered the script in the button#click event and must add the red part. Otherwise, I will always prompt that nothing can be parse.