我在页面中加入了三个RadioButton,三个TextBox,我希望用这三个 radiobutton控制textbox,效果是选中任意一个RadioButton的时候,相应的TextBox为可以输入,其他两个无效。页面代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmEnterpriseInfo.aspx.cs" Inherits="frmEnterpriseInfo" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>企業情報一覧画面</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" GroupName="1"
            OnCheckedChanged="RadioButton1_CheckedChanged" Style="z-index: 100; left: 34px;
            position: absolute; top: 30px" />
        <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" GroupName="1"
            OnCheckedChanged="RadioButton2_CheckedChanged" Style="z-index: 106; left: 18px;
            position: absolute; top: 112px" />
        <asp:RadioButton ID="RadioButton3" runat="server" AutoPostBack="True" GroupName="1"
            OnCheckedChanged="RadioButton3_CheckedChanged" Style="z-index: 102; left: 24px;
            position: absolute; top: 180px" />
        <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 103; left: 20px; position: absolute;
            top: 73px"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server" Style="z-index: 104; left: 21px; position: absolute;
            top: 149px"></asp:TextBox>
        <asp:TextBox ID="TextBox3" runat="server" Style="z-index: 105; left: 20px; position: absolute;
            top: 210px"></asp:TextBox>
    
    </div>
    </form>
</body>
</html>CS:public partial class frmEnterpriseInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        RadioButton1.Checked = true;        
        TextBox2.Enabled = false;
        TextBox3.Enabled = false;      
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        TextBox1.Enabled = true;
        TextBox2.Enabled = false;
        TextBox3.Enabled = false;
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        TextBox1.Enabled = false;
        TextBox2.Enabled = true;
        TextBox3.Enabled = false;
    }
    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        TextBox1.Enabled = false;
        TextBox2.Enabled = false;
        TextBox3.Enabled = true;
    }
}
现在的效果是,画面初始化的时候第一个RadioButton选中,第一个TextBox可输入,其他两个TextBox无效。点击第二个和第三个RadioButton都可以产生预期效果但是,再点击第一个RadioButton发现没有反应,似乎是RadioButton1_CheckedChanged()这个方法没有调用,或者是没有PostBack。不知道为什么