ModalPopupExtender和验证问题 [英] ModalPopupExtender and validation problems
问题描述
我现在面临的问题是,当有验证页面上,我试图显示模式弹出,是没有得到显示弹出。并用火的bug我已经注意到,被抛出的错误。
这是用来显示弹出按钮导致验证设置为false,所以我坚持,什么是造成错误。
我创建了一个示例页面隔离,我有这个问题,任何帮助将大大AP preciated。
的错误
函数(){Array.remove(Page_ValidationSummaries,的document.getElementById(ValidationSummary1));}(函数(){VAR FN =功能(){AjaxControlToolkit.ModalPopupBehavior.invokeViaServer (mpeSelectClient,真); Sys.Application.remove_load(FN);}; Sys.Application.add_load(FN);})不是一个函数
HTTP://本地主机:1131 / WebForm1.aspx
136线
ASP
<%@页面语言=C#AutoEventWireup =真正的codeBehind =WebForm1.aspx.cs中继承=CLIck10.WebForm1%>
<%@注册议会=AjaxControlToolkit中命名空间=AjaxControlToolkit中标签preFIX =ajaxToolkit%>
!< DOCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< HTML的xmlns =http://www.w3.org/1999/xhtml>
<头=服务器>
<冠军>< /标题>
< /头>
<身体GT;
<表格ID =Form1的=服务器>
< ASP:ScriptManager的ID =ScriptManager1=服务器>
< / ASP:ScriptManager的>
< DIV>
< ASP:按钮的ID =btnPush=服务器文本=推的CausesValidation =假的onclick =btnPush_Click/>
< ASP:文本框ID =txtVal=服务器/>
< ASP:使用RequiredFieldValidator ID =RequiredFieldValidator1=服务器的ControlToValidate =txtVal的ErrorMessage =使用RequiredFieldValidator/>
< ASP:的ValidationSummary ID =ValidationSummary1=服务器/>
< ASP:面板ID =pnlSelectClient风格=显示:无的CssClass =框中的=服务器>
< ASP:UpdatePanel的ID =upnlSelectClient=服务器>
<的ContentTemplate>
< ASP:按钮的ID =btnOK=服务器UseSubmitBehavior =真正的文本=OK的CausesValidation =假的OnClick =btnOK_Click/>
< ASP:按钮的ID =btnCancel=服务器文本=取消的CausesValidation =假的OnClick =btnCancel_Click/>
< /的ContentTemplate>
< / ASP:UpdatePanel的>
< / ASP:面板>
<输入ID =popupDummy=服务器的风格=显示:无/>
< ajaxToolkit:ModalPopupExtender ID =mpeSelectClient=服务器
的TargetControlID =popupDummy
PopupControlID =pnlSelectClient
OkControlID =popupDummy
BackgroundCssClass =modalBackground
CancelControlID =btnCancel
阴影效果=真/>
< / DIV>
< /形式GT;
code背后
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
命名空间CLIck10
{
公共部分类WebForm1的:System.Web.UI.Page
{
保护无效的Page_Load(对象发件人,EventArgs的)
{
}
保护无效btnOK_Click(对象发件人,EventArgs的)
{
mpeSelectClient.Hide();
}
保护无效btnCancel_Click(对象发件人,EventArgs的)
{
mpeSelectClient.Hide();
}
保护无效btnPush_Click(对象发件人,EventArgs的)
{
mpeSelectClient.Show();
}
}
}
这是一个问题,同时使用的ValidationSummary和ModalPopup。
在这里看到:<一href="http://ajaxcontroltoolkit.$c$cplex.com/WorkItem/View.aspx?WorkItemId=12835">http://ajaxcontroltoolkit.$c$cplex.com/WorkItem/View.aspx?WorkItemId=12835
的问题是,存在丢失的;两个注入脚本之间。
他们的解决方案是创建/使用自定义服务器控件继承的ValidationSummary,是注入了;进入页面启动脚本以修复该错误:
[ToolboxData()]
公共类AjaxValidationSummary:的ValidationSummary
{
保护覆盖无效在preRender(EventArgs的五)
{
base.On preRender(E);
ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(),this.ClientID,;,真);
}
}
The problem I am facing is that when there is validation on a page and I am trying to display a model pop-up, the pop-up is not getting displayed. And by using fire-bug I have noticed that an error is being thrown.
The button that is used to display the pop-up has cause validation set to false so I am stuck as to what is causing the error.
I have created a sample page to isolate the problem that I am having, any help would be greatly appreciated.
The Error
function () {Array.remove(Page_ValidationSummaries, document.getElementById("ValidationSummary1"));}(function () {var fn = function () {AjaxControlToolkit.ModalPopupBehavior.invokeViaServer("mpeSelectClient", true);Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);}) is not a function
http://localhost:1131/WebForm1.aspx
Line 136
ASP
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CLIck10.WebForm1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:Button ID="btnPush" runat="server" Text="Push" CausesValidation="false" onclick="btnPush_Click" />
<asp:TextBox ID="txtVal" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtVal" ErrorMessage="RequiredFieldValidator" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:Panel ID="pnlSelectClient" Style="display: none" CssClass="box" runat="server">
<asp:UpdatePanel ID="upnlSelectClient" runat="server">
<ContentTemplate>
<asp:Button ID="btnOK" runat="server" UseSubmitBehavior="true" Text="OK" CausesValidation="false" OnClick="btnOK_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancel_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<input id="popupDummy" runat="server" style="display:none" />
<ajaxToolkit:ModalPopupExtender ID="mpeSelectClient" runat="server"
TargetControlID="popupDummy"
PopupControlID="pnlSelectClient"
OkControlID="popupDummy"
BackgroundCssClass="modalBackground"
CancelControlID="btnCancel"
DropShadow="true" />
</div>
</form>
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CLIck10
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
mpeSelectClient.Hide();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeSelectClient.Hide();
}
protected void btnPush_Click(object sender, EventArgs e)
{
mpeSelectClient.Show();
}
}
}
This is an issue with using both ValidationSummary and ModalPopup.
see here: http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835
The problem is that there is a missing ";" between the two injected scripts.
Their solution is to create/use a custom server control that inherits from ValidationSummary, that injects a ";" into the page startup script to fix the bug:
[ToolboxData("")]
public class AjaxValidationSummary : ValidationSummary
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
}
}
这篇关于ModalPopupExtender和验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!