我在页面中加入了三个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。不知道为什么
<%@ 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。不知道为什么
解决方案 »
- asp.net服务器控件样式属性(写在style中的)跟CSSCLASS中属性文件的差别?
- 读取数据的问题?
- 求一段关于页面在会员登录前后变化的代码
- 客户端改变checkbox的字体颜色(我的失败了)
- 什么样的作品才拿得出手?
- 声明变量
- 请教:如何让Response.write("<input...").. 出来的按钮,参与服务器端的事件?
- seesion cookie?怎么实现这个功能?
- 为什么客户端的activeX控件不能显示?
- 能否开发本地程序直接处理网上服务器的数据?是否比web程序的速度快,大概怎么开发?
- 100分 全送了 一个小小的问题
- 用SqlHelper的问题,这个类里的方法调用完之后好像都没有关闭数据库连接,这是怎么回事啊?
{
if(!this.IsPostBack)
{
RadioButton1.Checked = true;
TextBox2.Enabled = false;
TextBox3.Enabled = false;
}
}
这样不就行了?就是不知道是不是符合你的想法