为什么在C#net中单击信用/借记单选按钮时不显示文本框?
这是我的aspx.cs文件为什么在C#net中单击信用/借记单选按钮时不显示文本框?,c#,asp.net,visual-studio-2017,C#,Asp.net,Visual Studio 2017,这是我的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_CheckedCha
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;
}
为什么选中贷方/借方
单选按钮时文本框不出现?您必须使用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>
如果您遇到任何问题,请务必让我知道什么是“贷记/借记”单选按钮
?如果没有查看您的.aspx
代码,我们将无法帮助您。请同时发布您的aspx代码,非常感谢。很好用
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;
}
}
}