Prevent (Stop) firing Button Click on TextBox TextChanged event in ASP.Net

Last Reply 2 months ago By pandeyism

Posted 2 months ago

i have enable auto postback on textbox ,when i enter value in textbox and press enter then button is also get click .

so i want postack on textbox remain but don't get auto click on button a ,when i insert value in textbox and press enter..

so how it will get done..

 

Posted 2 months ago

Hi akhter,

Refer below sample.

HTML

Name : <asp:TextBox runat="server" ID="txtName" AutoPostBack="true" OnTextChanged="Save" />

Code

C#

protected void Save(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('" + txtName.Text + "');", true);
}

VB.Net

Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "", "alert('" & txtName.Text & "');", True)
End Sub

Screenshot