Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to stop text_changed event on a particular button click

How to stop text_changed event on a particular button click

Scheduled Pinned Locked Moved ASP.NET
jsonhelptutorial
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A amittinku

    Hi, There are some text boxes , one "back" and one "reset" button on screen. One text box is employee id. After entering employee id, it populates the rest details in other text boxes. This code is written in text_changed event. it works fine. Issue is with following scenario: Suppose I enter emp id in text box and directly jump to Back button and click it. Now text_changed event take place, rest of details will be populated, we will not go to back page. We will have to reclick back button to go back. Same holds true for reset. So how to avoid this i.e. data should not be populated when we directly jump from text box to back button, should go to back page. same for reset button.

    A Offline
    A Offline
    Anurag Gandhi
    wrote on last edited by
    #2

    What are you doing to go back to previous page? Could you please provide the code.

    Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.

    A 1 Reply Last reply
    0
    • A Anurag Gandhi

      What are you doing to go back to previous page? Could you please provide the code.

      Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.

      A Offline
      A Offline
      amittinku
      wrote on last edited by
      #3

      I let u know about a simple reproducable code. Drag an asp text box control. Drag an HTML button control. Make the autopost back of textbox=TRUE protected void TextBox2_TextChanged(object sender, EventArgs e)       {                Response.Write("hi");       } function Button1_onclick() { alert('clicked button'); } Run it. Enter any text in text box and click on button. Button will display "hi", it will not trigger its own event. So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.

      C 1 Reply Last reply
      0
      • A amittinku

        I let u know about a simple reproducable code. Drag an asp text box control. Drag an HTML button control. Make the autopost back of textbox=TRUE protected void TextBox2_TextChanged(object sender, EventArgs e)       {                Response.Write("hi");       } function Button1_onclick() { alert('clicked button'); } Run it. Enter any text in text box and click on button. Button will display "hi", it will not trigger its own event. So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #4

        amittinku wrote:

        Drag an asp text box control. Drag an HTML button control.

        Well, that sucks. Anyone who uses the designer, is obviously on the wrong track. The designer sucks.

        amittinku wrote:

        So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.

        That sounds like a real bug in ASP.NET. I assume you have other buttons, which would still fire the text changed ? It's a real bug if the text change event on the server, stops the client side onclick from working. Perhaps instead of using OnClientClick, you should use onclick directly ?

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        A 1 Reply Last reply
        0
        • C Christian Graus

          amittinku wrote:

          Drag an asp text box control. Drag an HTML button control.

          Well, that sucks. Anyone who uses the designer, is obviously on the wrong track. The designer sucks.

          amittinku wrote:

          So I want that on button click, TextBox2_TextChanged event should not take place. IN any other condition, it shold work fine.

          That sounds like a real bug in ASP.NET. I assume you have other buttons, which would still fire the text changed ? It's a real bug if the text change event on the server, stops the client side onclick from working. Perhaps instead of using OnClientClick, you should use onclick directly ?

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          A Offline
          A Offline
          amittinku
          wrote on last edited by
          #5

          Hi Christian, You are right. After entering emp id in text box, if i directly click on any button, textchanged event takes place. So could not get any solution yet how to stop textchanged event if we click on a button. Note:As button is HTML control, so i am using onclick event only.

          C 1 Reply Last reply
          0
          • A amittinku

            Hi Christian, You are right. After entering emp id in text box, if i directly click on any button, textchanged event takes place. So could not get any solution yet how to stop textchanged event if we click on a button. Note:As button is HTML control, so i am using onclick event only.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #6

            So perhaps you need to use an ASP.NET button for it to hook into the ASP.NET events engine properly ?

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            A 1 Reply Last reply
            0
            • C Christian Graus

              So perhaps you need to use an ASP.NET button for it to hook into the ASP.NET events engine properly ?

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              A Offline
              A Offline
              amittinku
              wrote on last edited by
              #7

              whether use asp button or html button, does not matter.

              C 1 Reply Last reply
              0
              • A amittinku

                whether use asp button or html button, does not matter.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #8

                You're saying that ASP.NET is fundamentally broken. I'd google to see what other people have done, because surely other people have had the same issue.

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                1 Reply Last reply
                0
                • A amittinku

                  Hi, There are some text boxes , one "back" and one "reset" button on screen. One text box is employee id. After entering employee id, it populates the rest details in other text boxes. This code is written in text_changed event. it works fine. Issue is with following scenario: Suppose I enter emp id in text box and directly jump to Back button and click it. Now text_changed event take place, rest of details will be populated, we will not go to back page. We will have to reclick back button to go back. Same holds true for reset. So how to avoid this i.e. data should not be populated when we directly jump from text box to back button, should go to back page. same for reset button.

                  A Offline
                  A Offline
                  Arindam Tewary
                  wrote on last edited by
                  #9

                  This happens because in asp textbox if AautoPostBack is set to true, page is posted back when user leaves the control ( here textbox). So basically, when you click the button, first you leave the textbox control and then you click on the button. Hence TextBox' postback the data to server and as the page is reloaded you dont see any alert message. Subsequent click on button shows the alert message. I just replicated your situation.

                  <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
                  <input type="button" id="btnOK" value="OK" onclick="return Button1_onclick();"/>

                  <script language="javascript" type="text/javascript">
                  function Button1_onclick()
                  {
                  alert('clicked button');
                  return false;
                  }
                  </script>

                  Thanks, Arindam D Tewary

                  C A 2 Replies Last reply
                  0
                  • A Arindam Tewary

                    This happens because in asp textbox if AautoPostBack is set to true, page is posted back when user leaves the control ( here textbox). So basically, when you click the button, first you leave the textbox control and then you click on the button. Hence TextBox' postback the data to server and as the page is reloaded you dont see any alert message. Subsequent click on button shows the alert message. I just replicated your situation.

                    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
                    <input type="button" id="btnOK" value="OK" onclick="return Button1_onclick();"/>

                    <script language="javascript" type="text/javascript">
                    function Button1_onclick()
                    {
                    alert('clicked button');
                    return false;
                    }
                    </script>

                    Thanks, Arindam D Tewary

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #10

                    Of course, that's what auto postback means. :doh: I've never used it, so I didn't really think it through, I just assumed that the event fired when he pushes a button to post back.

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    1 Reply Last reply
                    0
                    • A Arindam Tewary

                      This happens because in asp textbox if AautoPostBack is set to true, page is posted back when user leaves the control ( here textbox). So basically, when you click the button, first you leave the textbox control and then you click on the button. Hence TextBox' postback the data to server and as the page is reloaded you dont see any alert message. Subsequent click on button shows the alert message. I just replicated your situation.

                      <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
                      <input type="button" id="btnOK" value="OK" onclick="return Button1_onclick();"/>

                      <script language="javascript" type="text/javascript">
                      function Button1_onclick()
                      {
                      alert('clicked button');
                      return false;
                      }
                      </script>

                      Thanks, Arindam D Tewary

                      A Offline
                      A Offline
                      amittinku
                      wrote on last edited by
                      #11

                      That I got. But what's the solution?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups