this is a sample about how to use UpdatePanel and ScriptManager to implement ajax performance.
OK, let's go!
Client Code:
<body>
<form id="form1" runat="server">
<div>
<center>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering=true>
</asp:ScriptManager>
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true" Width="170px" OnSelectedIndexChanged="ddl1_SelectedIndexChanged">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
<asp:ListItem>Four</asp:ListItem>
<asp:ListItem>Five</asp:ListItem>
</asp:DropDownList>
<br /><br /><br />
</center>
<asp:updatepanel runat="server" ID="updatepanel1">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddl1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lbl1" runat=server Text="" ></asp:Label>
</ContentTemplate>
</asp:updatepanel>
</div>
</form>
</body>
Code Behind:
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
this.lbl1.Text = "You selected :" + ddl1.SelectedValue.ToString();
}
Attention: You have to put ScriptManager in the front of the all controls when you use it, or you will get a error, and you can try it to put it at last code.
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment