Registering a starter script, an important feature of Ajax!

Source: Internet
Author: User
Tags object datetime net sleep string thread
ajax|| Script

The atlas July CTP has been used in recent projects, and since Atlas was officially renamed, the Beta and Beta2 two editions have been rolled out continuously, but I've been watching because the beta version is unstable and the upgrades are too cumbersome. A day by chance to see this essay Yangdan, suddenly found that ScriptManager can register in the client part of the refresh UpdatePanel registered after the start of the javascript! This is a problem that has plagued me for a long time! This allows you to use the JavaScript pop-up dialog box without using UpdatePanel, or to enable the control's start script to execute when you develop a server control that uses JavaScript scripts. Such original and UpdatePanel incompatible controls can easily be changed to Ajax enabled ^_^.
However, it is puzzling that do not know what to consider, RegisterStartupScript function is actually implemented for the class static function, but there is no ScriptManager UpdatePanel can not perform Ah, so you need to hit a few more words! Also, note that the first parameter is an instance of UpdatePanel, and if there is more than one UpdatePanel in the page, if each UpdatePanel UpdateMode is "always" [Default value], Then you can use that UpdatePanel instance as a parameter, and if each Updaepanel updatemode=conditional, then you must use the UpdatePanel that is being updated as an argument so that the script will work. Here's a simple example of what I've done:
Page marks
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>

untitled page

Please waiting the retrieving data from server

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

public partial class
protected void Page_Load (object sender, EventArgs e)

protected void LinkButton1_Click (object sender, EventArgs e)
System.Threading.Thread.Sleep (1000);
TextBox1.Text = DateTime.Now.ToLongTimeString ();
TextBox2.Text = TextBox1.Text;
String js = "alert (' OK button1 clicked! ')";
Microsoft.Web.UI.ScriptManager.RegisterStartupScript (UpdatePanel2, this. GetType (), "btn1clicked", JS, True);
protected void Linkbutton2_click (object sender, EventArgs e)
System.Threading.Thread.Sleep (900);
TextBox2.Text = DateTime.Now.ToLongTimeString ();
TextBox1.Text = TextBox2.Text;
String js = "alert (' OK button 2 clicked! ')";

Microsoft.Web.UI.ScriptManager.RegisterStartupScript (UpdatePanel2, this. GetType (), "btn2clicked", JS, True);

BTW, I found a problem when using, do not know is a bug or I use improper, I found in the debug updatepanel.isinpartialrendering value is always false! Hope to have an expert to guide:).


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: 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.