Autopostback and submit button

E

Edward Diener

I have a textbox-like control on a web form which has AutoPostBack set
to true. If I press the Submit button on my web form after changing the
text of the control, the handler for the AutoPostBack for the
textbox-like control is evoked but the handler for the Submit button is
never subsequently called in that particular postback. Does anybody know
why ? I want both handlers to be called before issuing a response back
to the client.
 
A

Alessandro Zifiglio

hi Edward, this behavior you are getting is due to the fact that the textbox
control is subscribed to a clientside onchange event.
In effect this the render output of a textbox control with postback enabled
:
<input name="TextBox1" type="text" value="ok dood"
onchange="javascript:setTimeout('__doPostBack(\'TextBox1\',\'\')', 0)"
onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;"
id="TextBox1" />

Behavior of the onchange event in msdn documentation :
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onchange.asp

"This event is fired when the contents are committed and not while the value
is changing. For example, on a text box, this event is not fired while the
user is typing, but rather when the user commits the change by leaving the
text box that has focus. In addition, this event is executed before the code
specified by onblur when the control is also losing the focus."

Note the last line where its said that the event fires "when the control
loses focus". This is exactly what is happening, when the text is changed
and you hit the submit button, the textbox loses focus causing it to
postback, and your submit button never gets to issue a postback =P

By the way, do you really need autopostback set to true ? The textchanged
event of the textbox will fire without needing to set an autopostback
trigger, specially since you already have a submit button you might not need
this.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top