asp.net c# tutorials and examples code for web developers

Wednesday, November 11, 2009

How to use AsyncPostBackTrigger in asp.net ajax Triggers

AsyncPostBackTrigger in asp.net ajax Triggers
UsingAsyncPostBackTrigger.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToLongTimeString();
    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label2.ForeColor = Color.FromName(RadioButtonList1.SelectedItem.Text);
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Ajax AsyncPostBackTrigger - How to use AsyncPostBackTrigger in asp.net ajax Triggers</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Crimson; font-style:italic;">Ajax Triggers Example: Using AsyncPostBackTrigger</h2>
        <hr width="450" align="left" color="Salmon" />
        <asp:ScriptManager 
            ID="ScriptManager1"
            runat="server"
            >
        </asp:ScriptManager>
        <asp:Label 
            ID="Label1"
            runat="server"
            ForeColor="SeaGreen"
            Font-Size="Medium"
            Font-Bold="true"
            >
        </asp:Label>
        <br /><br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label 
                    ID="Label2"
                    runat="server"
                    Text="Select RadioButton for change Label color."
                    Font-Bold="true"
                    Font-Italic="true"
                    Font-Names="Comic Sans MS"
                    Font-Size="Large"
                    >
                </asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="RadioButtonList1" EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>
        <br /><br />
        <asp:RadioButtonList 
            ID="RadioButtonList1"
            runat="server"
            ForeColor="DarkSeaGreen"
            BorderColor="LawnGreen"
            BorderWidth="1"
            OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
            AutoPostBack="true"
            RepeatColumns="3"
            >
            <asp:ListItem>Crimson</asp:ListItem>
            <asp:ListItem>RosyBrown</asp:ListItem>
            <asp:ListItem>DarkSeaGreen</asp:ListItem>
            <asp:ListItem>DodgerBlue</asp:ListItem>
            <asp:ListItem>Salmon</asp:ListItem>
            <asp:ListItem>DarkSalmon</asp:ListItem>
            <asp:ListItem>Cyan</asp:ListItem>
            <asp:ListItem>CornFlowerBlue</asp:ListItem>
        </asp:RadioButtonList>
    </div>
    </form>
</body>
</html>
Related asp.net examples