• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

No leave event on object added on the fly

I have a form and I added a textbox on the fly with code:

DefaultForm = Form1
Form1.Show()
Form1.Activate()
textBox1 = new TextBox()
textBox1.AutoSize = true
textBox1.Location = new Point(90, 80)
textBox1.Name = `textBox1`
textBox1.Size = new Size(100, 30)
textBox1.TabIndex = 2
textBox1.Text = `Enter Data Here`
Controls.Add(textBox1)

Open in new window


But, I do not get a Leave event on the textbox. Yet, I do get leave events as usual on other objects on the form. What am I missing?
0
silentreproach
Asked:
silentreproach
  • 4
  • 2
  • 2
2 Solutions
 
CodeCruiserCommented:
How are you trying to get the leave event? If you want to add an event handler, use

AddHandler textbox1.Leave, Addressof functionname
0
 
CluskittCommented:
The event handler has to exist at page load, just like the textbox. That means that, at each postback, you have to add the event again to the textbox, else it won't fire.
0
 
p_davisCommented:
i get it in mine.Intellisense
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
p_davisCommented:
you don't have any semi-colons after your lines.
0
 
p_davisCommented:
also you need double quotes instead of single for text.
0
 
p_davisCommented:
for c# that is
0
 
CodeCruiserCommented:
@Cluskitt

>The event handler has to exist at page load, just like the textbox. That means that, at each postback, you have to add the event again to the textbox, else it won't fire.

Form1.Show() in ASP.NET?
0
 
CluskittCommented:
Yes, I realized later that this is VB.Net app, not web. Been programming too much web lately :P

Anyway, this seems to be VB code, which means that you shouldn't be using single quotes for strings. Replacing them with double quotes should fix it. I'm actually surprised VS compiler doesn't complaint about it.
0

Featured Post

Independent Software Vendors: 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!

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now