ASP.NET虽然提供强大的验证控件,但这也给服务器加大了负担,我们可以利用server controns 的客户端脚本功能,把一些基本的验证放在客户端,以减轻服务器的负担!
下面是删除动作前执行询问操作者, 包含了显示用户确认弹出式对话框的函数。请注意确认对话框包含了“确认”和“取消”两个按钮控件,这与警告对话框不同,整个JavaScript代码是动态构建的。同样输入信息必须填写的,不然显示用户提示函数,并不执行服务器端动作!好了,下面是代码:
gcba.aspx
<%@ Page language="c#" Codebehind="gcba.aspx.cs" AutoEventWireup="false" Inherits="MessageManage.qualityinspect.gcba" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>jgys</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="gcba" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 126px; POSITION: absolute; TOP: 99px" runat="server" Text=" 测 试"></asp:Button>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 128px; POSITION: absolute; TOP: 147px" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 103; LEFT: 128px; POSITION: absolute; TOP: 202px" runat="server"></asp:TextBox>
<asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 265px; POSITION: absolute; TOP: 99px" runat="server" Text="数据完整性"></asp:Button>
</form>
</body>
</HTML>
gcba.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MessageManage.qualityinspect
{
///
/// jgys 的摘要说明。
///
public class gcba : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string bb="fsd";
System.Text.StringBuilder Msg = new System.Text.StringBuilder();
Msg.Append(" ");
string clientConfrimDeleteJS = Msg.ToString();
if(!IsClientScriptBlockRegistered("confrimDelete"))
{
RegisterClientScriptBlock("confrimDelete",clientConfrimDeleteJS);
}
Msg.Remove(0,Msg.Length);
Msg.Append(" ");
&