ASP.NET C#结合,做了两个单选按钮RadioButton,有两个Label控件,一个TEXTBOX

2024-11-27 04:13:28
推荐回答(4个)
回答1:

页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>





无标题页





oncheckedchanged="RadioButton1_CheckedChanged" AutoPostBack="true"/>









后台
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (this.RadioButton1.Checked)
{
this.Label1.Visible = true;
this.TextBox1.Visible = true;
}
else
{
this.Label1.Visible = false;
this.TextBox1.Visible = false;
}
}

}

ps:注意 oncheckedchanged="RadioButton1_CheckedChanged" AutoPostBack="true"/> radiobutton的autopostback属性,要设置成true

回答2:

你点单选按钮后要回发到服务器才能生效,
你也可以写在按钮的单击事件里面,
我写的没问题
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButton1.Checked)
{
TextBox1.Visible = false;
}
else
{
TextBox1.Visible = true;
}
}

回答3:

RadioButton2.Checked=true;吧

回答4:

if (RadioButton2.Checked)这个条件没有满足