Saturday, March 10, 2012

User Control for Validation Summary in Modal Popup

Try replacing

{var x= $find("ModalExtnd1");

with

{var x= $find("<%= ModalExtnd1.ClientID %>");


That worked great. Thanks!


Okay, well that was working great... I was trying to do some modifications to the page and it stopped working on me and I cannot figure out what I did wrong. Now I receive the same NULL reference message on the below line:

<script type="text/javascript">
function ShowModalDialog()
{var x= $find("<%= ModalExtnd1.ClientID %>");
Page_ClientValidate();
if(!Page_IsValid)
x.show(); // ERROR ON THIS LINE
}

function init()
{document.getElementById('SummaryDiv').style.display='none';}
</script>

Look at the source, it appears that the ModalExtnd1 object is never being created, which would explain why it comes up as NULL when you try to set properties on it. I'm at a loss as why this happens though. I tried to backup to what I had when it was working, but I must be missing something. Maybe someone can look at my code and tell?

.ascx file:

<%@. Control Language="VB" AutoEventWireup="false" CodeFile="ModalPopUpClient.ascx.vb" Inherits="CommonUI_ModalPopUpClient" %>

<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


<style type="text/css">
.popupdiv{background-color:ivory;border:solid 1px skyblue;width:250px;display:block}
.popupbg{background-color:gray; filter: alpha(opacity=60); opacity:0.60}
.hidelbl{display:none;}
</style>




<script type="text/javascript">
function ShowModalDialog()
{var x= $find("<%= ModalExtnd1.ClientID %>"); // ERROR ON THIS LINE
Page_ClientValidate();
if(!Page_IsValid)
x.show();
}

function init()
{document.getElementById('SummaryDiv').style.display='none';}
</script>

<body onload="init();"></body>


<ajaxToolkit:ModalPopupExtender ID="ModalExtnd1" runat="server"
TargetControlID="lblHidden"
PopupControlID="SummaryDiv"
BackgroundCssClass="popupbg"
/>


<asp:Button ID="btnSubmit" runat="server" Text="Submit Form" />

<div id="SummaryDiv" class="popupdiv">

<table width="100%" cellpadding="4" cellspacing="0">
<tr>
<td style="background-color: skyblue">Errors on this page:</td>
</tr>
<tr>
<td>

<asp:ValidationSummary id="ValidationSummary1" runat="server"
Font-Names="Arial"
/>

</td>
</tr>
<tr>
<td align="center">
<input type="button" value="OK" onclick="$find('<%= ModalExtnd1.ClientID %>').hide();"/>
</td>
</tr>
</table>

</div>

<asp:Label ID="lblHidden" runat="server" CssClass="hidelbl" Visible="false" />

ascx.vb file:

PartialClass CommonUI_ModalPopUpClientInherits System.Web.UI.UserControl

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

'MessageHeading = "Errors on this page:"

EndSub

ProtectedSub Page_PreRender(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.PreRender

btnSubmit.Attributes.Add("onmouseup","ShowModalDialog();")

EndSub

EndClass


Uh, you deleted the "{" after "if (!Page_IsValid)".


Okay... very strange, the label needs to be visible... otherwise it doesn't work.

No comments:

Post a Comment