Click here to Skip to main content
15,348,881 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to stop textbox textchanged event on button click event in
OriginalGriff 2-Jun-14 7:21am
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Amir Mohammad Nasrollahi 18-Apr-15 11:45am
poor question

1 solution

Try this solution:
in the aspx page, add a hidden field to store the state of button click
<asp:textbox runat="server" ID="TextBox1" ontextchanged="TextBox1_TextChanged" AutoPostBack="true"></asp:textbox>
<asp:HiddenField ID="HiddenField1" runat="server" Value="false" />
<asp:Button ID="Button1" runat="server" OnClientClick="setButtonClicked();" onclick="Button1_Click" Text="Button" />

in the header of aspx page, add the javascript:
    function setButtonClicked() {
        document.getElementById('<%= HiddenField1.ClientID %>').value = 'true';

on the code behind:
protected void TextBox1_TextChanged(object sender, EventArgs e)
    if (HiddenField1.Value == "false") // No Button1_Click
        // do something
    else // button1_click
        HiddenField1.Value = "false"; // reset the hiddenfield1 value
zeqe 6-Mar-20 16:57pm
Thanks.. It worked like a charm
Member 15310520 24-Aug-21 8:16am
I implemented the solution in the same way. But in the TextBox Change event, Hidden Field.Value is always false, even if I clicked the button. What can that be? Are there any prerequisites that have to be installed or present?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900