简体   繁体   English

当我单击asp.net中的退出按钮时,不会触发textbox onblur事件

[英]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. 我有一个modelpopup扩展程序,其中一个文本框和两个asp.net按钮(保存,退出),文本框我编写了onblur事件(在该事件中,文本框输入的值检查数据库是否有效,无效则显示警报消息)该条件有效,但是当我单击“退出”按钮时,我已经处理了onclick或onclientclik事件(关闭modelpopup代码),但是现在触发文本框模糊事件验证并显示警报消息 ,如何解决该问题,请给我任何关于那。 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. 该代码按预期工作,因为一旦TextBox失去焦点,就会调用onblur。 I would recommend calling CheckUserId() at a different point - maybe when a button is clicked - as opposed to the TextBox onblur. 我建议在不同点调用CheckUserId() -也许在单击按钮时-与TextBox onblur相反。

If you must call CheckUserId() during the onblur, then you could use a timer like so: 如果必须在onblur期间调用CheckUserId() ,则可以使用如下计时器:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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