我做了一对男女的单选框 我选了男 的确显示出了性别男。。但是我选性别女时。。。单选框男的那个还在.
我想写个if判断那样可以解决...但是我在想..是否能从page_load这方面来想...
而且我还想请高手讲哈子ispostback 这个东东..!
Default.aspx.cs
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Male.Checked = false;
Female.Checked = false;
Message.Text = " ";
}
}
protected void submit_Click(object sender, EventArgs e)
{
if (Male.Checked)
{
Message.Text = "男";
}
if (Female.Checked)
{
Message.Text = "女";
}
}
}
***************************************************
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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="Male" runat="server" Text="男" AutoPostBack="True" CausesValidation="True" />
<asp:RadioButton ID="Female" runat="server" Text="女" AutoPostBack="True" CausesValidation="True" /><br />
你的性别是:<asp:Label ID="Message" runat="server" Text="" Width="58px"></asp:Label><br />
<br />
<asp:Button ID="submit" runat="server" Text="提交" OnClick="submit_Click" /></div>
</form>
</body>
</html>