0

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>
hmk
  • 969
  • 10
  • 38
  • 70

1 Answers1

1

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>
kevev22
  • 3,737
  • 21
  • 32
  • It is not working same problem occurred please give me another solution – hmk Apr 19 '12 at 04:40
  • Did you change the onblur event to call `startCheckUserIdTimer()` instead of `CheckUserId()`? Understand that this is kind of a hack but I don't see why it wouldn't work. You also might want to change onblur to onchange so that it only checks the user id if the value has changed. – kevev22 Apr 19 '12 at 12:45