Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange reaction in dynamically created textbox and addhandler

Status
Not open for further replies.

fig00000

Programmer
Dec 19, 2023
1
0
0
US
Hi,

Just moved back to vb.net after years of C#. Due to some unknowns in the amount of a certain entity (i.e. a variable number of buildings each having it's own screen) I decided to write the code entirely dynamically. All variables are "Dimed"and there is no declarative code in the section I am writing. I have been successful up to a point. However I Dimed a text box and set up a click event using addhandler. The weird thing that happens is that when I type some numbers and click return in txtStartDate it does not go to the Private Sub below. What is even weirder is that it does go to an image button click event in the Site.Master page that is connected to the page where the rest of the code is. So despite the fact that the image button is not in the page where the code below is, it acts like the image button in Site.Master has been clicked when it hasn't. It's almost like the txtStartDate.TextChanged that occurs when i click enter in the textbox is somehow creating a click of the image button in Site.master.

Very confused. Any help would be appreciated.

Dim txtStartDate = New TextBox
txtStartDate.ID = "StartDate"
txtStartDate.AutoPostBack = True

AddHandler txtStartDate.TextChanged, AddressOf txtStartDate_TextChanged

Private Sub txtStartDate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If CType(sender, Date) < CType("May 6, 2014", Date) Then
Dim a As Integer
a = 3
End If
End Sub

Here is the imagebutton click event in the site.master file.

Protected Sub ibHome_Click(sender As Object, e As ImageClickEventArgs) Handles ibHome.Click
Response.Redirect("~/Default.aspx")
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top