效果显示
HTML页面显示
HTML代码
<%@ 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>
<h3>在线学习系统注册</h3>
<br />
<asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="性别:"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList3" RepeatDirection="Horizontal" runat="server">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="所学专业:"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="Horizontal" runat="server">
<asp:ListItem>软件技术</asp:ListItem>
<asp:ListItem>网络技术</asp:ListItem>
<asp:ListItem>电子商务</asp:ListItem>
<asp:ListItem>互联网技术</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Label ID="Label5" runat="server" Text="所学语言:"></asp:Label>
<br />
<asp:RadioButtonList ID="RadioButtonList2" RepeatDirection="Horizontal" runat="server">
<asp:ListItem>Java</asp:ListItem>
<asp:ListItem>Python</asp:ListItem>
<asp:ListItem>PHP</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
</asp:RadioButtonList>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="清除" onclick="Button2_Click" />
<br />
<asp:Label ID="Label6" runat="server"></asp:Label>
</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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = "用户名:" + TextBox1.Text + "<br><br>密码:" + TextBox2.Text +
"<br><br>性别: " + RadioButtonList3.SelectedItem.Text + "<br><br>专业:" + RadioButtonList1.SelectedItem.Text +
"<br><br>所学语言:" + RadioButtonList2.SelectedItem.Text;
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = null;
TextBox2.Text = null;
RadioButtonList3.Text = null;
RadioButtonList1.Text = null;
RadioButtonList2.Text = null;
Label6.Text = null;
}
}