环境:win2003 + asp.net2.0 + AJAX 在一个UpdatePanel内,一个TextBox,一个RequiredFieldValidator验证TextBox不为空,按钮"Btn_GetValue"用于获取某一值显示于前台,再由“Btn_Modify”按钮事件修改该值,这里方便测试,按钮"Btn_GetValue"无事件。 问题:步骤(1)如果一打开页面,不按"Btn_GetValue",那么按“Btn_Modify”时候,如果TextBox为空,则RequiredFieldValidator显示错误提示,如果不为空的话,弹出对话框“已验证”;步骤(2) 打开新页面,按"Btn_GetValue",没有定义任何时间,无反应。之后点击“Btn_Modify”,RequiredFieldValidator没有提示错误信息,没有弹出对话框“已验证”或“未验证”,说明RequiredFieldValidator起效果,但是就是RequiredFieldValidator不提示信息,望高手解答!
前台页面:Ajax.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="activ_Ajax" %><!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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="不能为空" ValidationGroup="group_1"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Btn_GetValue" runat="server" CausesValidation="False" Text="功能A" />
<asp:Button ID="Btn_Modify" runat="server" OnClick="Btn_Modify_Click" Text="验证测试"
ValidationGroup="group_1" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>后台:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 activ_Ajax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Btn_Modify_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, GetType(), "note1", "alert('已验证!');", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, GetType(), "note1", "alert('未验证!');", true);
}
}
}
前台页面:Ajax.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="activ_Ajax" %><!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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="不能为空" ValidationGroup="group_1"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Btn_GetValue" runat="server" CausesValidation="False" Text="功能A" />
<asp:Button ID="Btn_Modify" runat="server" OnClick="Btn_Modify_Click" Text="验证测试"
ValidationGroup="group_1" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>后台:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 activ_Ajax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Btn_Modify_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, GetType(), "note1", "alert('已验证!');", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, GetType(), "note1", "alert('未验证!');", true);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货