Solved

ASP.net Text change in TextBox triggers button event

Posted on 2016-09-19
5
52 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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…

808 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