简体   繁体   中英

AutoPostBack doesn't work

i am trying to learn how to use autopostback, so i wrote this:

<asp:TextBox runat="server"  AutoPostBack="true" OnTextChanged="check" ID="Tz"></asp:TextBox>

and code behind:

protected void check(object sender, EventArgs e)
{
    Response.Write("checked");
}

i assumed that when i would trigger the autopostback by changing the text in the textbox, i'll see checked written on the screen, but nothing happaned.

there was a window that poped up and said that there is an unhandled exception, in addion it showed me this while i was running the debugger:

    <script type="text/javascript">
//<![CDATA[
var theForm = document.forms['register'];
if (!theForm) {
    theForm = document.register;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

the line theForm.submit(); was marked.

This code should work.

The only thing I can think of is that you may be expecting the autopostback to trigger when you type something in the textbox but it is actually only fired when the textbox loses focus like after you click anywhere outside of the textbox.

i found the solution. all i had to do was change the id of the submit button from submit to something else.

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