ComboBoxAutoPostBack.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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 Button1_Click(object sender, EventArgs e)
{
ComboBox1.AutoPostBack = false;
Label1.Text = "ComboBox AutoPostBack Now: False";
}
protected void Button2_Click(object sender, EventArgs e)
{
ComboBox1.AutoPostBack = true;
Label1.Text = "ComboBox AutoPostBack Now: True";
}
protected void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox1.ForeColor = System.Drawing.Color.FromName(ComboBox1.SelectedItem.Text);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ajax ComboBox - How to set change ComboBox AutoPostBack programmatically in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
ASP.NET Ajax ComboBox - How to set change ComboBox
<br /> AutoPostBack programmatically in asp.net
</h2>
<hr width="525" align="left" color="Pink" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="Green"
>
</asp:Label>
<br /><br />
<asp:ComboBox
ID="ComboBox1"
runat="server"
DropDownStyle="DropDown"
AutoCompleteMode="None"
CaseSensitive="false"
RenderMode="Block"
AutoPostBack="true"
OnSelectedIndexChanged="ComboBox1_SelectedIndexChanged"
Font-Names="Comic Sans MS"
Font-Size="Large"
ForeColor="SeaGreen"
>
<asp:ListItem Text="Red"></asp:ListItem>
<asp:ListItem Text="Green"></asp:ListItem>
<asp:ListItem Text="Blue"></asp:ListItem>
<asp:ListItem Text="DeepPink"></asp:ListItem>
<asp:ListItem Text="SkyBlue"></asp:ListItem>
</asp:ComboBox>
<br /><br /><br />
<br /><br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Set AutoPostBack False"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
<asp:Button
ID="Button2"
runat="server"
OnClick="Button2_Click"
Text="Set AutoPostBack True"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
No comments:
Post a Comment