开发者

my invisible dropdownlist does not become visible again at visual studio

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!


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


Modify your code as below:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
       DropDownList4.Visible=false;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜