Reputation: 155
I am using Visual Studio 2010, and I created a site (.aspx).
I have 2 radiobuttons, and a DropDownList. I want to have an invisible dropdownlist and whenever I click on the one radiobutton then the downdownlist to appear! I have added a code like this but nothing changes and I can't understand why!!
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
DropDownList4.Visible = true;
else
DropDownList4.Visible = false;
}
protected void Page_Load(object sender, EventArgs e)
{
DropDownList4.Visible=false;
}
The only thing I am getting, is an invisible dropdownlist than never becomes visible! Both of my radiobuttons have the same action "radiobutton_checkedchanged" ..
Thank you!
Upvotes: 2
Views: 2373
Reputation: 4129
your code is ok , set AutoPostBack property of radiobutton to true
since RadioButton_CheckedChanged(object sender, EventArgs e)
events occurs after page load
it will work no need for checking !IsPostBack
Upvotes: 6
Reputation: 3746
Modify your code as below:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DropDownList4.Visible=false;
}
}
Upvotes: 1