Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.net Text change in TextBox triggers button event

Posted on 2016-09-19
5
Medium Priority
?
107 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Murray Brown
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:Murray Brown
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 2000 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:Murray Brown
ID: 41811265
Great. Thanks for the help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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