RSS

Search Engine

Wednesday, May 19, 2010

ASP.Net RadioButton AutoPostback Property

The AutoPostBack property of the ASP.Net RadioButton control provides the functionality to allow the server side post back event of the web page when user clicks the radio button to change its inactive state to selected state. You can get the value of checked state of the radio button control at the Page Load event of ASP.Net web page to perform the server side action based on the checked state of radio button. The AutoPostBack property is a Boolean type property that accepts value as true/false to enable or disable the auto post back functionality of the radio button control to the server side when user selects it. You can declare its value in two ways such as in HTML code block as an inline attribute of radio button control or by declaring it programmatically when page loads.

Sample Code for ASP.Net RadioButton AutoPostBack Property

we have used 2 ASP.Net radio button controls declared with their GroupName property and AutoPostBack property. The GoupName property enables you to create a group of radio buttons so that the user could select only one radio button among multiple set of options. The AutoPostBack property is used in the sample to allow the controls for posting the web form data to the server when user will click any of the radio button control. Other than the radio button controls we have used ASP.Net Panel controls also to illustrate the additional functionality that can be provided along with the AutoPostBack feature of radio button controls. When the user will select the first radio button then it will set the first panel control to be visible on the web page where as the second radio button will hide the first panel control and display the second panel control associated to it.

C# Code:

protected void Page_Load(object sender, EventArgs e)
{
Panel1.Visible = RadioButton1.Checked;
Panel2.Visible = !RadioButton1.Checked;
}

The C# code shows that you can get the value of checked property of radio button controls at the Page Load event of ASP.Net web page when the AutoPostBack property of radio button controls is specified with value "true".

0 comments:

Post a Comment