效果显示
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>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 109px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2">
</td>
<td>
学生成绩录入</td>
</tr>
<tr>
<td class="style2">
学生姓名:</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtName" ErrorMessage="姓名不能为空" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
英语成绩:</td>
<td>
<asp:TextBox ID="txtScore" runat="server" style="margin-left: 0px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtScore" ErrorMessage="英语成绩不能为空" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtScore" ErrorMessage="成绩应在0-100之间" ForeColor="Red"
MaximumValue="100" MinimumValue="0"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red"
ShowMessageBox="True" ShowSummary="False" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1" Text="提交"
Width="71px" />
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
</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_Click1(object sender, EventArgs e)
{
Label1.Text = "学生姓名:" + txtName.Text + "<br>英语成绩:" + txtScore.Text;
}
}