When asp.net use LinkButton to do the login button, the carriage return fails to submit the solution __.net

Source: Internet
Author: User

LinkButton belongs to a label, you must obtain the focus before you can use $ ("#<%=this.lbtnlogin.clientid%>"). Click ();
WORKAROUND: Direct trigger LinkButton postback event javascript: __doPostBack (' Lbtnlogin ', ');

<asp:textbox id= "txtloginname" cssclass= "TXT" runat= "server" tabindex= "1" placeholder= "username" ></asp:textbox >

 <asp:textbox id= "txtpassword" cssclass= "TXT" textmode= "Password" runat= "Server" tabindex= "2" 
placeholder= "Password" ></asp:TextBox>

<asp:linkbutton id= "Lbtnlogin" validationgroup= "Login" runat= " Server "width=" 173 "height=" 
onclientclick= "return valid ()" onclick= "Lbtnlogin_click" > Login </asp: Linkbutton>

<script type= "Text/javascript" > function valid () {var loginname = $ ("#<%=this.txtloginname.c
            Lientid%> "). Val (). Replace (" username "," ");
            var Loginpassword = $ ("#<%=this.txtpassword.clientid%>"). Val (). replace ("password", ""); if (LoginName = = "" | | Loginpassword = = "") {if (LoginName = = "" && Loginpassword = "") {$ ("#<% =this.validmessage.clientid%> "). Text (" Enter your username and password. ")
                    ");
                $ ("#<%=this.txtloginname.clientid%>"). focus (); else if (LoginName = "") {$ ("#<%=this.validmessage.clientid%>"). Text ("Please fill in the username.")
                    "); $ ("#<%=this.validmessage.clientid%>"). Text ("Please enter a username and password.)
                "); else {$ ("#<%=this.validmessage.clientid%>"). Text ("Enter your password.
                    ");
                $ ("#<%=this.txtpassword.clientid%>"). focus (); } $ ("#<%=this.validsuMmary.
                ClientID%> "). Show ();
            return false;
            else {return true; } $ (function () {$ ("#<%=this.txtloginname.clientid%>"). KeyUp (function (event) {//select already Account password Login return event for KeyDown, prevent event conflict, commit login using KeyUp event var e = Events | | window.event | |
                Arguments.callee.caller.arguments[0]; if (e && e.keycode = 13) {//Login box, carriage return event var Loginpassword = $ ("#<%=this.txtpassword.clientid
                    %> "). Val (). replace (" password "," "); if (Loginpassword = = "") {$ ("#<%=this.txtpassword.clientid%>"). focus ();/Enter, the detection password is not filled, then fixed to the password
                    box return;
                        } if (valid ()) {//form validation passed, submit login javascript: __dopostback (' Lbtnlogin ', ');
                        LinkButton belongs to a label, you must obtain the focus before you can use $ ("#<%=this.lbtnlogin.clientid%>"). Click (); Solution: Direct Triggering LinKbutton the postback Event &nbsp}});
                $ ("#<%=this.txtpassword.clientid%>"). KeyUp (function (event) {//Select Existing account password login return event is KeyDown, prevent event conflict, commit login use KeyUp event var e = Event | | window.event | |
                Arguments.callee.caller.arguments[0]; if (e && e.keycode = 13) {//Password box, carriage return event if (valid ()) {//form validation through Javascrip
        T: __doPostBack (' Lbtnlogin ', ');//Commit login}}});
    }); </script>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.