I’ve got a Login Control set to come up inside a jQuery dialog box. However, the login button doesn’t work when in the dialog box, it works fine when I remove the dialog box. There are some field validators on the username and password that do some javascript validation, so I think there might be some conflict but I can’t figure it out. Any ideas?
Here is my markup:
<div id="loginBox">
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
<LayoutTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<div class="accountInfo" style="float: left; width: 220px;">
<fieldset class="login">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry" Width="190"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="red-text" ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password" >Password:</asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password" Width="190"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="red-text" ErrorMessage="Password is required." ToolTip="Password is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator><br/>
<asp:CheckBox ID="RememberMe" runat="server" style="display: inline-block;" />
<asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" style="display: inline-block; font-weight: normal;">Remember Me</asp:Label>
</fieldset>
<p class="submitButton">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup" />
</p>
</div>
<div style="float: left; width: 170px; padding-top: 15px;">
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="red-text" ValidationGroup="LoginUserValidationGroup" />
</div>
<div class="clearfix"></div>
</LayoutTemplate>
</asp:Login>
</div>
The jQuery:
<script type="text/javascript">
$(document).ready(function () {
// Dialog
$('#loginBox').dialog({
autoOpen: true,
width: 420,
modal: true,
draggable: false,
title: "<h2 style='margin-bottom: 0px;'>Log In</h2>",
closeOnEscape: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
resizable: false,
show: { effect: "fade", duration: 1500 }
});
})
</script>
Nothing in the code behind file. I notice when I inspect the login button after the page has been rendered it has this on it:
<input type="submit" name="ctl00$mainbody$LoginUser$LoginButton" value="Log In" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$mainbody$LoginUser$LoginButton", "", true, "LoginUserValidationGroup", "", false, false))" id="mainbody_LoginUser_LoginButton">
So I am guessing that javascript isn’t being run for some reason when it appears in the dialog box, but I am not sure how to fix it.
Maybe the “dialog” is placed outside/below of the “form” tag in page. Check using Firebug or other tool I’m right. If so reattach the server side controls to form via javascript.