asp.net - show error msg for bootstrap login modal -
i using bootstrap modal create modal, appears automatically when user visit home page:
at top of default.aspx
have javascript code show modal every time user visit home page:
$(document).ready(function () { $(".modal").modal('show').css({ top: "30%" }); });
then created bootstrap modal inside update panel, created scriptmanager @ top update panel, below modal code:
<asp:scriptmanager id="scriptmanager1" runat="server"></asp:scriptmanager> <asp:updatepanel id="loginupdatepanel" runat="server" updatemode="conditional" enableviewstate="true"> <contenttemplate> <asp:panel id="mymodal" runat="server" class="modal fade animated zoomin"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> ×</button> <h4 class="modal-title">welcome</h4> </div> <div class="modal-body"> <asp:panel id="login" runat="server"> <div class="login-form"> <asp:label id="lblsignin" runat="server"><h4>sign in</h4></asp:label> <asp:label id="lblmsg" cssclass="text-danger" runat="server"></asp:label> <div class="form-group"> <asp:textbox id="tbemail" runat="server" cssclass="form-control" placeholder="your email address"></asp:textbox> </div> <div class="form-group"> <asp:textbox id="tbpassword" runat="server" cssclass="form-control" placeholder="your password" textmode="password"></asp:textbox> </div> <div class="row"> <div class="col-md-6 col-xs-12"> <asp:checkbox id="chkremember" runat="server" cssclass="text-danger" text=" remember me" visible="false" /> </div> </div> </div> <br /> </asp:panel> </div> <div class="modal-footer"> <a href="register.aspx" class="pull-left">create account</a> <asp:button runat="server" id="btnlogin" text="login" class="btn btn-default" onclick="btnlogin_click" usesubmitbehavior="false" causesvalidation="true" /> <button type="button" class="btn btn-default" data-dismiss="modal"> close</button> </div> </div> </div> </asp:panel> </contenttemplate> </asp:updatepanel>
when user enter valid information login process work , redirect user users account home page , c# code :
protected void page_load(object sender, eventargs e) { if (!string.isnullorempty(session["user"] string)) { //check session user logged in hide modal mymodal.visible = false; } else { mymodal.visible = true; } } protected void btnlogin_click(object sender, eventargs e) { string email = tbemail.text.tostring(); string pass = tbpassword.text.tostring(); if (email != "" && pass != "") { //check user authentication using method isauthenticated in userslist class if (userslist.isauthenticated(email, pass)) { session["user"] = email; response.redirect("~/account.aspx"); } else { lblmsg.text = "wrong user name or password"; } } else { lblmsg.text = "all field required"; } }
my problem when user enter wrong data or keep fields empty login form inside modal disappear without generating error msg inside lblmsg.text
this picture of modal before login process:
instead of getting error when user enter wrong data i'am getting background still disabled black screen login form disappear:
can 1 me please generate error msg inside lblmsg if login failed ?
i'm not entirly sure, think problem update panel.
when hit login_btn , set error message in case of wrong password, '$(document).ready(function ()' isn't executed anymore.
clicking on login button tells bootstrap unload modal, partial update not trigger show function more because page insn't reloaded. partial update takes place , document.ready isn't triggerd. bootstrap modal isn't shown more.
is update panel realy needed here? whithout think work ok.
in case needed, need execute bit of javascript code on partial postback modal shown again.
Comments
Post a Comment