Ajax and ScriptManager. RegisterStartupScript

Source: Internet
Author: User

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.

Related Article

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.