3

I have a web form with textbox and button. I want after "ENTER" key click on textbox postbak form.

I am using next code:

onkeypress=" if(event.keyCode==13)
 { alert(2);
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$ContentPlaceHolder1$btnSearch', '', true, '', '', false, false));
alert(2); 
return false;}

where WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$ContentPlaceHolder1$btnSearch', '', true, '', '', false, false));

is javascript code for button event onclick.

I get two alerts, but postback doesnot happen.

Any ideas what is wrong?

2 Answers 2

11

ASP.NET already creates a client side javascript method __doPostBack to support postback.

Example: __doPostBack('__Page', 'MyCustomArgument');

Sign up to request clarification or add additional context in comments.

Comments

0

Easier way of doing it is to enclose the controls in a panel and use defaultbutton attribute on the panel, like this:

<asp:Panel ID="pan1" runat="server" DefaultButton="btnSave">
    <asp:TextBox ID="txt1" runat="server" />
    <asp:Button ID="btnSave" runat="server" />
</asp:Panel>

Then when you press 'enter' after entering the value in the text box it will behave as if you clicked on the btnSave button.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.