开发者

asp.net button doesn't cause post back when clicked repeatedly

开发者 https://www.devze.com 2023-03-17 20:58 出处:网络
If I click a button very fast after page load, the post back won\'t be fired. The following example illustrates this (you have to click the button twice and very fast):

If I click a button very fast after page load, the post back won't be fired. The following example illustrates this (you have to click the button twice and very fast):

<form id="form1" runat="server">
    <div>
        <span id="submitText"></span>
        <br />
        <asp:Button ID="btnSubmitTest" runat="server" Text="Button" 
        OnClientClick="document.getElementById('submitText').innerText='you should not see this after postback';"  />
    </div>
</form>

The submitText, the button set's before firing, should not be visible after the postback. But if you click at the button very fast, it happens, that the event doesn't fire.

I think, that the 开发者_StackOverflow中文版page isn't loaded completely at this moment. Or is there any other reason for that behaviour? How do you handle this?


You will loose all javascript dom updates on postback. What you have explained sounds correct... you see the client click event fire just before page posts back and the dom is reset.

Try the same exercise by populating a textbox. In that instance the value will maintain as the textbox relies on viewstate. You could put a runat="server" on the span, but I believe you would have to manually assign the value to viewstate as I don't believe htmlgenericcontrols automatically utilize viewstate.

0

精彩评论

暂无评论...
验证码 换一张
取 消