Here, we are going to learn about autopostback property in asp.net with the dropdownlist control.
AutoPostBack of the ASP.Net DropDownList control provides the functionality to allow the server side post back event of the web page when user Select the DropDownlist Item from control while running programm.
Here we will make an example for understand Autopostback property.
When we select Item from DropDownlist the Selected Item will be Displayed in TextBox Control in ASP.Net C#.
First we design the asp.net web page with one textbox control along with the one DropDwonlist control.
The HTML Design code for asp.net web page is like:
<table>
<tr>
<td style=”width: 100px; text-align: right”>
Select Value :</td>
<td style=”width: 100px; text-align: left”>
<asp:DropDownList ID=”Drpvalue” runat=”server” AutoPostBack=”True” OnSelectedIndexChanged=”Drpvalue_SelectedIndexChanged”
Width=”128px”>
<asp:ListItem Value=”0″>SELECT</asp:ListItem>
<asp:ListItem Value=”1″>Meera</asp:ListItem>
<asp:ListItem Value=”2″>Academy</asp:ListItem>
<asp:ListItem Value=”3″>ASP</asp:ListItem>
<asp:ListItem Value=”4″>PHP</asp:ListItem>
<asp:ListItem Value=”5″>SQL</asp:ListItem>
</asp:DropDownList></td>
<td style=”width: 100px; text-align: left”>
</td>
</tr>
<tr>
<td style=”width: 100px; text-align: right”>
Answer :
</td>
<td style=”width: 100px; text-align: left”>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox></td>
<td style=”width: 100px; text-align: left”>
</td>
</tr>
</table>
The ASP.Net Autopostback example of DropDownlist control design output is :
Now, open the property windows of DropDownlist control and change the Autopostback property.
AutoPostBack = True
write below code on DropDownList SelectedIndexChanged Event on code behind page:
protected void Drpvalue_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = Drpvalue.SelectedItem.Text;
}
After writing this coding, when you select Item from dropdownlist the Item display in the TextBox control because we changed the AutoPostBack=True of DropDownlList control.
The ASP.Net Autopostback DropDownlist control output:
I hope this asp.net dropdownlist autopostback event example will help you….