简体   繁体   中英

textbox onblur event not fired when i click the exit button in asp.net

I have one modelpopup extender, in that one textbox and two asp.net buttons(save,exit), textbox i wrote the onblur event (in that event textbox entered value check the database valid or not , not valid display the alert message ) now that condition is working but when i click the Exit button, i have work the onclick or onclientclik event( close the modelpopup code) but now fires textbox blur event validation and display the alert message , how to slove that issue please give me any idea about that. my code is

<asp:TextBox ID="txtForgotUserId" runat="server" ClientIDMode="Static" onblur="CheckUserId()"></asp:TextBox>
<asp:Button ID="btnForgotExit" runat="server" Text="Exit" CssClass="art-button" ClientIDMode="Static" OnClientClick="hidepop()"/>

<script type="text/javascript">
    function hidepop() {
        $find('MpForgot').hide();
        return true;
    }

    function CheckUserId() {
        document.getElementById('btnCheckUserId').click();
    }
</script>

The code is working as expected since onblur is called as soon as the TextBox loses focus. I would recommend calling CheckUserId() at a different point - maybe when a button is clicked - as opposed to the TextBox onblur.

If you must call CheckUserId() during the onblur, then you could use a timer like so:

<asp:TextBox ID="txtForgotUserId" runat="server" 
    ClientIDMode="Static" onblur="startCheckUserIdTimer()"></asp:TextBox>
<asp:Button ID="btnForgotExit" runat="server" Text="Exit" 
    CssClass="art-button" ClientIDMode="Static" OnClientClick="hidepop()"/>

<script type="text/javascript">
    var timer;

    function hidepop() {
        clearTimeout(timer);
        $find('MpForgot').hide();
    }

    function startCheckUserIdTimer() {
        clearTimeout(timer);
        timer = setTimeout("CheckUserId()", 100);
    }

    function CheckUserId() {
        clearTimeout(timer);
        document.getElementById('btnCheckUserId').click();
    }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM