Solved

ASP.net Text change in TextBox triggers button event

Posted on 2016-09-19
5
56 Views
Last Modified: 2016-09-22
Hi. I have a text box that I add using the following code. I have a button on the same page. When I change text in the text box it triggers the click event of the button. I have no idea why this is happening. Why would it

  Dim tb As New TextBox
   tb.ID = oControlName
  tb.CssClass = "xTextBoxHundredPercent"
 Me.Panel_Controls.Controls.Add(tb)

'Here is the markup for the button
  <asp:Button ID="btnSave" runat="server" Text="Button" Width="100%" />

'Here is the click event for the button that gets triggered when the text in the text box added with above code is changed
    Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Call oSave()
    End Sub
0
Comment
Question by:murbro
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 41804507
how did you attached btnSave_Click event to the button?
0
 

Author Comment

by:murbro
ID: 41804571
As I said above
'Here is the click event for the button that gets triggered when the text in the text box added with above code is changed
     Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
         Call oSave()
     End Sub
0
 

Author Comment

by:murbro
ID: 41804572
The event is triggered when I click Enter. This is Visual Studio 2015 and it wouldn't have happened in visual Studio 2010
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 500 total points
ID: 41804593
It might be that your save button on the page have focus and when you click enter it executes the click event.

Put following code in you text changed event sub

If e.KeyCode = Keys.Enter Then

'do nothing here...

End If

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 41811265
Great. Thanks for the help
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question