Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autopostback prevents button click

I have an asp.net page and on it there are a number of controls, including:

  1. A textbox with autopostback = true and the server side textchanged event implemented

  2. A button with the server side click event implemented

The textbox performs the postback as soon as the user leaves the control (ie, focus is lost). The problem is that if the user happens to change the value and then press the button without leaving the textbox, then on button click the textbox will perform the postback but the button click will be lost.

How can i force both the textbox and the button events to fire consecutively in such cases?

Thanks

like image 354
user1365247 Avatar asked Oct 24 '13 08:10

user1365247


People also ask

How can disable postback on button click in asp net VB?

The postback on submit button can be avoided by giving return=false in the event handler function as below.

Can you explain AutoPostBack?

Autopostback is the mechanism by which the page will be posted back to the server automatically based on some events in the web controls. In some of the web controls, the property called auto post back, if set to true, will send the request to the server when an event happens in the control.

What is AutoPostBack in asp net with example?

Definition and Usage The AutoPostBack property is used to set or return whether or not an automatic post back occurs when the user selects an item in a list control. If this property is set to TRUE the automatic post back is enabled, otherwise FALSE.


1 Answers

Try:

ASPX:

<asp:TextBox ID="TextBox1" clientidmode="Static" runat="server" onkeypress="return EnterEvent(event)"></asp:TextBox>    
<asp:Button ID="Button1" runat="server" style="display:none" Text="Button" />

JS:

function EnterEvent(e) {
        if (e.keyCode == 13) {
            __doPostBack('<%=Button1.UniqueId%>', "");
        }
    }

CS:

protected void Button1_Click1(object sender, EventArgs e)
    {

    }
like image 109
Monika Avatar answered Oct 18 '22 22:10

Monika