Monday, October 29, 2007

Ajax UpdatePanel (11) ScriptManager 2

Asp.net Ajax provide similar functions:

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

<%= DateTime.Now %>

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />

</ContentTemplate>

</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">

<ContentTemplate>

<%= DateTime.Now %>

</ContentTemplate>

</asp:UpdatePanel>

</form>



protected void Button1_Click1(object sender, EventArgs e)

{

ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdatePanel1", "alert(1)", true);

ScriptManager.RegisterStartupScript(this.UpdatePanel2, this.GetType(), "UpdatePanel2", "alert(2)", true);

}

In this code, when Button1 is clicked, only 'alert 1' will pop up, because UpdatePanel2 is conditional.

blog comments powered by Disqus