Hi,
I think it is important for you to understand how a webform can be
submitted in ASP.NET.
The form is submitted with no _EVENTTARGET which will
result in no event being fired.Eventhough the page events will fire.
The clent side _doPostBack event is fired before the form is submitted.This
will set an _EVENTTARGET, and fire an event server
side.After the form is submitted the submitting button contrbutes a
name/value pair which will override any value you pre-set in the
_EVENTTARGET hidden field.
Let me come back to your specific case :
You can post back the form using javascript using the
keyup or keydown events and an <input type=submit>(no need it to be
runat="server") button.
For eg:
If you have a TextBox server control with ID TextBox1 and input submit
button with id,Button1 and the id of the webform is Form1,
You can add a client side keyup event on Page_Load by
putting the below code :
TextBox1.Attributes.Add("onkeyup","document.Form1.Button1.click();return
false;");
If you want it for a specific key or keys you need
to modify the javascript with checking event.keyCode.
This will add the client side event to the TextBox1 which
will call the click event of the submit button when the onkeyup event
happens for TextBox1.
This will cause your webform to be submitted !!!!
And now some additional TIP:
If you want to Pre-Set the
_EVENTTARGET you can do it by
If you have a server control with ID Button2,
Page.RegisterHiddenField( "__EVENTTARGET", "Button2" );
This will
cause the event in Button2 to be fired when the Web Form is submitted!!
I am not very clear about your
requirement.Anyway hope this helps.
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com
mg said:
What code (javascript) will cause a WebForm to be submited (runatserver)
whenever a new character is typed into a TextBox from the keyboard?