473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

'wiring-up' event handlers when creating a webform dynamically

I'm using VS2005.

I am dynamically adding a Textbox control to a Placeholder control in the
page_load event of the form, but the event handler isn't firing. What am I
doing wrong?

Thanks
Bill

Protected Sub Page_Load....
Dim tb as new Textbox
AddHandler tb.TextChanged, AddressOf tbEventHandler
PlaceHolder1.controls.add (tb)
end sub

sub tbEventHandler
runCode
end sub

Apr 7 '06 #1
1 1395
Hi Bill,

Are you providing everything that is required for the event to fire? You
might be missing Autopostback.

Here's some demo code that might get you going. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
' Quick sample of creating objects
' and including events using AddHandler
' Ken Cox April 9, 2006
Dim lbl As New Label
lbl.ID = "lblText"
lbl.Text = "Nothing"
PlaceHolder1.Controls.Add(lbl)

Dim lit As New Literal
lit.ID = "lit1"
lit.Text = "<br />"
PlaceHolder1.Controls.Add(lit)

Dim btn As New Button
btn.Text = "Click me"
btn.ID = "btn1"
AddHandler btn.Click, AddressOf but_click

PlaceHolder1.Controls.Add(btn)
Dim tb As New TextBox
tb.ID = "Textbox1"
tb.AutoPostBack = True
AddHandler tb.TextChanged, AddressOf tbEventHandler
PlaceHolder1.Controls.Add(tb)
End Sub

Sub tbEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lbl As Label
lbl = Page.FindControl("lblText")
If Not IsNothing(lbl) Then
lbl.Text = "The textbox changed!"
End If
End Sub

Sub but_click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lbl As Label
lbl = Page.FindControl("lblText")
If Not IsNothing(lbl) Then
lbl.Text = "The button was clicked!"
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Addhandler</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>

</div>
</form>
</body>
</html>
"bill" <be****@datamti.com> wrote in message
news:uk**************@TK2MSFTNGP02.phx.gbl...
I'm using VS2005.

I am dynamically adding a Textbox control to a Placeholder control in the
page_load event of the form, but the event handler isn't firing. What am
I doing wrong?

Thanks
Bill

Protected Sub Page_Load....
Dim tb as new Textbox
AddHandler tb.TextChanged, AddressOf tbEventHandler
PlaceHolder1.controls.add (tb)
end sub

sub tbEventHandler
runCode
end sub

Apr 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Leonardo Henrique Machado | last post by:
Is is possible to create a link that opens a xterm window? The person clicks on the links and a funcion calls /usr/bin/X11/xterm -e ssh <IP> which gives the person a shell on that IP...
11
by: Midas | last post by:
In my "main" code, I would like to create two new objects (ObjectA and ObjectB) and have ObjectA directly call an ObjectB method. In order to do this I believe ObjectA must hold a reference to...
65
by: Miklós | last post by:
Ok, seems like we have @decorators. It's a nice tribute to Intercal. But I'd prefer #decorators. We have metaclasses for pleasure brain-melting. We have generators, new-style classes and...
2
by: Daniel Heneghan, GT Solutions | last post by:
There never was a computer progrmming shortage. Industry and ethnic lobbyist convinced congress to admit over 1 million H1B's over the past 8 years. Now you can't find a job. Well get off your a**...
4
by: marcus | last post by:
Hi <xml>Gurus</xml> :-) I've a scenario where the system configuration is maintained in the server as xml dom tree. clients can change the system config either entirely or in parts. when the...
7
by: Bill Reed via AccessMonster.com | last post by:
I have a field called "Wiring" in a query which is boolean. If I place "True Or False" in the criteria for the field, I get all records (there are no nulls in the recordset). Likewise if I place...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
4
by: Mikael Olofsson | last post by:
I am interested in peoples experience with communicating with DLLs under Linux. Situation: I'm an electrical engineer that finds pleasure in using my soldering iron from time to time. I also...
40
by: PJ6 | last post by:
I want to rant, but I'm too busy at the moment. Who else hates working in C#? What's your biggest pet peeve? Paul
18
by: Port Pirie | last post by:
Hi, I ran the program below. It should print out 2 but actually it prints out 1. What's going on? Should I report a bug against the compiler? Thanks. void main() {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.