这是我的aspx.cs文件
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
TextBox2.Visible = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.ReadOnly = false;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
TextBox2.Visible = false;
}
为什么检查CREDIT / DEBIT radioButton
时文本框不会出现?
答案 0 :(得分:0)
您必须使用AutoPostBack="true"
,然后才能使用以下代码。它的工作
<强> .aspx的强>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Stack_Overflow.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:RadioButton ID="RadioButton1" AutoPostBack="true" runat="server" Text="Credit" OnCheckedChanged="RadioButton1_CheckedChanged" GroupName="a">
</asp:RadioButton>
<asp:RadioButton ID="RadioButton2" AutoPostBack="true" runat="server" Text="Debit" OnCheckedChanged="RadioButton2_CheckedChanged" GroupName="a" />
<br />
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
代码隐藏文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Stack_Overflow
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
Label6.Visible = true;
Label7.Visible = true;
Label8.Visible = true;
TextBox2.Visible = true;
TextBox3.Visible = true;
TextBox4.Visible = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.ReadOnly = false;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
Label6.Visible = false;
Label7.Visible = false;
Label8.Visible = false;
TextBox2.Visible = false;
TextBox3.Visible = false;
TextBox4.Visible = false;
}
}
}
如果您遇到任何问题,请告诉我