ASP.NET单选按钮变化 [英] ASP.NET radio button change

查看:146
本文介绍了ASP.NET单选按钮变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出为什么这个code不火的单选按钮更改事件。

这里的ASP页面code 2单选按钮

 < ASP:单选按钮ID =rdoButton1组名=组1文本=是值=是=服务器OnCheckedChanged =Group1_CheckedChanged/>
  < ASP:单选按钮ID =rdoButton2组名=组1文本=否值=否=服务器OnCheckedChanged =Group1_CheckedChanged/>

和这里的背后code:

 保护无效Group1_CheckedChanged(对象发件人,EventArgs的发送)
{
    如果(rdoButton1.Checked){
        panel1.Visible = TRUE;
    }    如果(rdoButton2.Checked){
        panel1.Visible = FALSE;
    }
}


解决方案

您需要指定属性和值<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.autopostback.aspx\"><$c$c>AutoPostBack=\"true\"为了告诉ASP.NET是不断变化的的元素会触发回发。它应适用于您要进行回传每个单选按钮。

I am trying to figure out why this code doesn't fire the radio button change event.

here's the ASP page code for 2 radio buttons

  <asp:RadioButton ID="rdoButton1" GroupName="Group1" Text="Yes" Value="Yes"  runat="server" OnCheckedChanged="Group1_CheckedChanged" />
  <asp:RadioButton ID="rdoButton2" GroupName="Group1" Text="No" Value="No" runat="server" OnCheckedChanged="Group1_CheckedChanged" />

And here's the code behind:

protected void Group1_CheckedChanged(Object sender, EventArgs e)
{
    if (rdoButton1.Checked) {
        panel1.Visible = true;
    }

    if (rdoButton2.Checked) {
        panel1.Visible = false;
    }
}

解决方案

You'll need to specify the attribute and value AutoPostBack="true" in order to tell ASP.NET that changing of that element should trigger a postback. It should be applied to each individual RadioButton which you wish to cause a postback.

这篇关于ASP.NET单选按钮变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆