asp.net – ModalPopupExtender和验证问题

前端之家收集整理的这篇文章主要介绍了asp.net – ModalPopupExtender和验证问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到的问题是,当页面上有验证,我正在尝试显示模型弹出窗口时,弹出窗口不会显示.并且通过使用fire-bug,我注意到一个错误被抛出.

用于显示弹出窗口的按钮导致验证设置为false,所以我被卡住导致错误的原因.

我创建了一个示例页面来隔离我遇到的问题,任何帮助将不胜感激.

错误

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>

代码背后

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();
        }
    }
}

解决方法

这是使用ValidationSummary和ModalPopup的问题.

见:http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835

问题是缺少“;”两个注入脚本之间.

他们的解决方案是创建/使用从ValidationSummary继承的自定义服务器控件,它注入一个“;”进入页面启动脚本来修复错误

[ToolBoxData("")]
public class AjaxValidationSummary : ValidationSummary
{
  protected override void OnPreRender(EventArgs e)
  {
    base.OnPreRender(e);
    ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(),this.ClientID,";",true);
  }
}
原文链接:https://www.f2er.com/aspnet/249467.html

猜你在找的asp.Net相关文章