473,657 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

addhandler problem

i have a simple page, with one button button1.
when click it creates a new button button 2 and adds a event handler to it.

but when button 2 is clicked nothing happens, why?

Partial Class test_buttons

Inherits System.Web.UI.P age

Dim bt2 As Button

Dim bt3 As Button

Dim test1 As Boolean = False

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click

bt2 = New Button

bt2.Text = "Button2"

AddHandler bt2.Click, AddressOf bt2Click

form1.Controls. Add(bt2)

Response.Write( "Button 1")

End Sub

Sub bt2Click(ByVal sender As Object, ByVal e As System.EventArg s)

If test1 = True Then

Response.Write( "Button 2")

End If

End Sub

End Class
Dec 30 '06 #1
5 2201
When button2 is clicked, the page postback. At this point button2 doesn't
exist any more. You may think that the ViewState takes care of this, but it
only takes care of maintaing values, not actual controls.

You need to re-create button2 on or before the Load event and hook up it's
event handler to have it work. As a matter of fact, you don't even need to
do the AddHandler in the Button1 click, the AddHandler needs to be done on
postback before/during the load event.

One way people often do this is by storing values in the viewstate,
something like:

Button1_Click(. ..)
dim bt2 as button = new Button()
...
form1.Controls. Add(bt2)
ViewState.Add(" LoadButton2", true)
end sub

OnLoad(...)
if Page.IsPostBack then
if not ViewState("Load Button2") is nothing AndAlso
cbool(ViewState ("LoadButton2") ) == true then
dim bt2 as button = new Button()
Addhandler bt2.Click ....
Form1.Controls. Add(bt2)
end if
end if
end sub

Denis Bauer has a special PlaceHolderCont rol that will do all of this for
you. It's free:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

You should check it out and you might be interested in looking at thee
source code to gain a better fundamental understanding of how it works...

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Slim" <me@here.comwro te in message
news:%2******** *******@TK2MSFT NGP02.phx.gbl.. .
>i have a simple page, with one button button1.
when click it creates a new button button 2 and adds a event handler to
it.

but when button 2 is clicked nothing happens, why?

Partial Class test_buttons

Inherits System.Web.UI.P age

Dim bt2 As Button

Dim bt3 As Button

Dim test1 As Boolean = False

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click

bt2 = New Button

bt2.Text = "Button2"

AddHandler bt2.Click, AddressOf bt2Click

form1.Controls. Add(bt2)

Response.Write( "Button 1")

End Sub

Sub bt2Click(ByVal sender As Object, ByVal e As System.EventArg s)

If test1 = True Then

Response.Write( "Button 2")

End If

End Sub

End Class

Dec 30 '06 #2
Thanks your example worked fine.
I did try something like this before that made the button persist but did
not add handlers, but all working fine now, thanks allot

"Karl Seguin" <ka********@rem oveopenmymindre movemetoo.andme netwrote in
message news:OC******** *****@TK2MSFTNG P04.phx.gbl...
When button2 is clicked, the page postback. At this point button2 doesn't
exist any more. You may think that the ViewState takes care of this, but
it only takes care of maintaing values, not actual controls.

You need to re-create button2 on or before the Load event and hook up it's
event handler to have it work. As a matter of fact, you don't even need to
do the AddHandler in the Button1 click, the AddHandler needs to be done on
postback before/during the load event.

One way people often do this is by storing values in the viewstate,
something like:

Button1_Click(. ..)
dim bt2 as button = new Button()
...
form1.Controls. Add(bt2)
ViewState.Add(" LoadButton2", true)
end sub

OnLoad(...)
if Page.IsPostBack then
if not ViewState("Load Button2") is nothing AndAlso
cbool(ViewState ("LoadButton2") ) == true then
dim bt2 as button = new Button()
Addhandler bt2.Click ....
Form1.Controls. Add(bt2)
end if
end if
end sub

Denis Bauer has a special PlaceHolderCont rol that will do all of this for
you. It's free:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

You should check it out and you might be interested in looking at thee
source code to gain a better fundamental understanding of how it works...

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Slim" <me@here.comwro te in message
news:%2******** *******@TK2MSFT NGP02.phx.gbl.. .
>>i have a simple page, with one button button1.
when click it creates a new button button 2 and adds a event handler to
it.

but when button 2 is clicked nothing happens, why?

Partial Class test_buttons

Inherits System.Web.UI.P age

Dim bt2 As Button

Dim bt3 As Button

Dim test1 As Boolean = False

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventAr gs) Handles Button1.Click

bt2 = New Button

bt2.Text = "Button2"

AddHandler bt2.Click, AddressOf bt2Click

form1.Controls. Add(bt2)

Response.Write( "Button 1")

End Sub

Sub bt2Click(ByVal sender As Object, ByVal e As System.EventArg s)

If test1 = True Then

Response.Write( "Button 2")

End If

End Sub

End Class


Dec 31 '06 #3
Actualy i still have a problem

on this page
http://worldgolfdata.com/Enter/Default.aspx
i have a list of countries when you click on them you get a list of states,
click on a state youi get a list of golf courses from that state.

I have a little bit of test data in it, if you go to Australia, then select
either Victoria or Western Australia you will get a list of 1 or 2 courses
repectivly.

I also have a lale that shows what event handler has fired.

if you have a play you will se that when you change state from victoria to
western australia then click on a course the lable shows that the event
handler does not fire till you click the second time.

Can you tell me why and suggets a fix or a workaround?

here is the code

Partial Class Enter_Default
Inherits System.Web.UI.P age

Protected Sub Page_PreLoad(By Val sender As Object, ByVal e As
System.EventArg s) Handles Me.PreLoad
buildCountrys()
If ViewState("buil dStates") <"" Then
buildStates()
End If
If ViewState("buil dCourses") <"" Then
buildCourses()
End If
End Sub

Sub buildCountrys()
Dim oCountries As Countries
oCountries = New Countries
Dim i As Integer
For i = 0 To UBound(oCountri es.getCountries )
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkCountry As LinkButton = New LinkButton
AddHandler linkCountry.Cli ck, AddressOf CountryButtClic k
linkCountry.OnC lientClick = "waitForIt( )"
linkCountry.Att ributes.Add("cl ass", "dButtons")
linkCountry.Com mandArgument = oCountries.getC ountries(i).id
linkCountry.Tex t = oCountries.getC ountries(i).Nam e
td.Controls.Add (linkCountry)
tr.Cells.Add(td )
countryTable.Ro ws.Add(tr)
Next
End Sub

Sub buildStates()
stateTable.Rows .Clear()
courseTable.Row s.Clear()
Dim oCountry As Country
oCountry = New Country(ViewSta te("buildStates "))
Dim i As Integer
For i = 0 To UBound(oCountry .getStates)
'On Error Resume Next
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkState As LinkButton = New LinkButton
AddHandler linkState.Click , AddressOf StateButtClick
linkState.OnCli entClick = "waitForIt( )"
linkState.Attri butes.Add("clas s", "dButtons")
linkState.Comma ndArgument = oCountry.getSta tes(i).id
linkState.Text = oCountry.getSta tes(i).Name
td.Controls.Add (linkState)
tr.Cells.Add(td )
stateTable.Rows .Add(tr)
Next
End Sub

Sub buildCourses()
courseTable.Row s.Clear()
Dim oState As State
oState = New State(ViewState ("buildCourses" ))
Dim i As Integer
For i = 0 To UBound(oState.g etCourses)
If oState.countCou rses 0 Then
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkCourse As LinkButton = New LinkButton
AddHandler linkCourse.Clic k, AddressOf CourseButtClick
linkCourse.OnCl ientClick = "waitForIt( )"
linkCourse.Attr ibutes.Add("cla ss", "dButtons")
linkCourse.Comm andArgument = oState.getCours es(i).id
linkCourse.Text = oState.getCours es(i).Name
td.Controls.Add (linkCourse)
courseTable.Row s.Add(tr)
tr.Cells.Add(td )
Else
End If
Next
End Sub

Sub CountryButtClic k(ByVal sender As Object, ByVal e As EventArgs)
ViewState.Add(" buildStates", sender.CommandA rgument)
Label1.Text = "country clicked"
buildStates()

End Sub

Sub StateButtClick( ByVal sender As Object, ByVal e As EventArgs)
ViewState.Add(" buildCourses", sender.CommandA rgument)
Label1.Text = "state clicked"
buildCourses()

End Sub

Sub CourseButtClick (ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = "course clicked"
End Sub

End Class

"Slim" <me@here.comwro te in message
news:O5******** ******@TK2MSFTN GP04.phx.gbl...
Thanks your example worked fine.
I did try something like this before that made the button persist but did
not add handlers, but all working fine now, thanks allot

"Karl Seguin" <ka********@rem oveopenmymindre movemetoo.andme netwrote in
message news:OC******** *****@TK2MSFTNG P04.phx.gbl...
>When button2 is clicked, the page postback. At this point button2 doesn't
exist any more. You may think that the ViewState takes care of this, but
it only takes care of maintaing values, not actual controls.

You need to re-create button2 on or before the Load event and hook up
it's event handler to have it work. As a matter of fact, you don't even
need to do the AddHandler in the Button1 click, the AddHandler needs to
be done on postback before/during the load event.

One way people often do this is by storing values in the viewstate,
something like:

Button1_Click( ...)
dim bt2 as button = new Button()
...
form1.Controls. Add(bt2)
ViewState.Add(" LoadButton2", true)
end sub

OnLoad(...)
if Page.IsPostBack then
if not ViewState("Load Button2") is nothing AndAlso
cbool(ViewStat e("LoadButton2" )) == true then
dim bt2 as button = new Button()
Addhandler bt2.Click ....
Form1.Controls. Add(bt2)
end if
end if
end sub

Denis Bauer has a special PlaceHolderCont rol that will do all of this for
you. It's free:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

You should check it out and you might be interested in looking at thee
source code to gain a better fundamental understanding of how it works...

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Slim" <me@here.comwro te in message
news:%2******* ********@TK2MSF TNGP02.phx.gbl. ..
>>>i have a simple page, with one button button1.
when click it creates a new button button 2 and adds a event handler to
it.

but when button 2 is clicked nothing happens, why?

Partial Class test_buttons

Inherits System.Web.UI.P age

Dim bt2 As Button

Dim bt3 As Button

Dim test1 As Boolean = False

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventA rgs) Handles Button1.Click

bt2 = New Button

bt2.Text = "Button2"

AddHandler bt2.Click, AddressOf bt2Click

form1.Controls. Add(bt2)

Response.Write( "Button 1")

End Sub

Sub bt2Click(ByVal sender As Object, ByVal e As System.EventArg s)

If test1 = True Then

Response.Write( "Button 2")

End If

End Sub

End Class



Dec 31 '06 #4
Clicking australia doesn't bring anything up for me.

I would look at Denis Bauer's control if you are dealing with that many
dynamic controls.

An alternative would be to forgo the postback mechanism and simply use the
QueryString - this would have the added benefit of being
bookmarkable... sometimes old tricks work best.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Slim" <me@here.comwro te in message
news:Od******** ******@TK2MSFTN GP06.phx.gbl...
Actualy i still have a problem

on this page
http://worldgolfdata.com/Enter/Default.aspx
i have a list of countries when you click on them you get a list of
states, click on a state youi get a list of golf courses from that state.

I have a little bit of test data in it, if you go to Australia, then
select either Victoria or Western Australia you will get a list of 1 or 2
courses repectivly.

I also have a lale that shows what event handler has fired.

if you have a play you will se that when you change state from victoria to
western australia then click on a course the lable shows that the event
handler does not fire till you click the second time.

Can you tell me why and suggets a fix or a workaround?

here is the code

Partial Class Enter_Default
Inherits System.Web.UI.P age

Protected Sub Page_PreLoad(By Val sender As Object, ByVal e As
System.EventArg s) Handles Me.PreLoad
buildCountrys()
If ViewState("buil dStates") <"" Then
buildStates()
End If
If ViewState("buil dCourses") <"" Then
buildCourses()
End If
End Sub

Sub buildCountrys()
Dim oCountries As Countries
oCountries = New Countries
Dim i As Integer
For i = 0 To UBound(oCountri es.getCountries )
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkCountry As LinkButton = New LinkButton
AddHandler linkCountry.Cli ck, AddressOf CountryButtClic k
linkCountry.OnC lientClick = "waitForIt( )"
linkCountry.Att ributes.Add("cl ass", "dButtons")
linkCountry.Com mandArgument = oCountries.getC ountries(i).id
linkCountry.Tex t = oCountries.getC ountries(i).Nam e
td.Controls.Add (linkCountry)
tr.Cells.Add(td )
countryTable.Ro ws.Add(tr)
Next
End Sub

Sub buildStates()
stateTable.Rows .Clear()
courseTable.Row s.Clear()
Dim oCountry As Country
oCountry = New Country(ViewSta te("buildStates "))
Dim i As Integer
For i = 0 To UBound(oCountry .getStates)
'On Error Resume Next
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkState As LinkButton = New LinkButton
AddHandler linkState.Click , AddressOf StateButtClick
linkState.OnCli entClick = "waitForIt( )"
linkState.Attri butes.Add("clas s", "dButtons")
linkState.Comma ndArgument = oCountry.getSta tes(i).id
linkState.Text = oCountry.getSta tes(i).Name
td.Controls.Add (linkState)
tr.Cells.Add(td )
stateTable.Rows .Add(tr)
Next
End Sub

Sub buildCourses()
courseTable.Row s.Clear()
Dim oState As State
oState = New State(ViewState ("buildCourses" ))
Dim i As Integer
For i = 0 To UBound(oState.g etCourses)
If oState.countCou rses 0 Then
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkCourse As LinkButton = New LinkButton
AddHandler linkCourse.Clic k, AddressOf CourseButtClick
linkCourse.OnCl ientClick = "waitForIt( )"
linkCourse.Attr ibutes.Add("cla ss", "dButtons")
linkCourse.Comm andArgument = oState.getCours es(i).id
linkCourse.Text = oState.getCours es(i).Name
td.Controls.Add (linkCourse)
courseTable.Row s.Add(tr)
tr.Cells.Add(td )
Else
End If
Next
End Sub

Sub CountryButtClic k(ByVal sender As Object, ByVal e As EventArgs)
ViewState.Add(" buildStates", sender.CommandA rgument)
Label1.Text = "country clicked"
buildStates()

End Sub

Sub StateButtClick( ByVal sender As Object, ByVal e As EventArgs)
ViewState.Add(" buildCourses", sender.CommandA rgument)
Label1.Text = "state clicked"
buildCourses()

End Sub

Sub CourseButtClick (ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = "course clicked"
End Sub

End Class

"Slim" <me@here.comwro te in message
news:O5******** ******@TK2MSFTN GP04.phx.gbl...
>Thanks your example worked fine.
I did try something like this before that made the button persist but did
not add handlers, but all working fine now, thanks allot

"Karl Seguin" <ka********@rem oveopenmymindre movemetoo.andme netwrote in
message news:OC******** *****@TK2MSFTNG P04.phx.gbl...
>>When button2 is clicked, the page postback. At this point button2
doesn't exist any more. You may think that the ViewState takes care of
this, but it only takes care of maintaing values, not actual controls.

You need to re-create button2 on or before the Load event and hook up
it's event handler to have it work. As a matter of fact, you don't even
need to do the AddHandler in the Button1 click, the AddHandler needs to
be done on postback before/during the load event.

One way people often do this is by storing values in the viewstate,
something like:

Button1_Click (...)
dim bt2 as button = new Button()
...
form1.Controls. Add(bt2)
ViewState.Add(" LoadButton2", true)
end sub

OnLoad(...)
if Page.IsPostBack then
if not ViewState("Load Button2") is nothing AndAlso
cbool(ViewSta te("LoadButton2 ")) == true then
dim bt2 as button = new Button()
Addhandler bt2.Click ....
Form1.Controls. Add(bt2)
end if
end if
end sub

Denis Bauer has a special PlaceHolderCont rol that will do all of this
for you. It's free:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

You should check it out and you might be interested in looking at thee
source code to gain a better fundamental understanding of how it
works...

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Slim" <me@here.comwro te in message
news:%2****** *********@TK2MS FTNGP02.phx.gbl ...
i have a simple page, with one button button1.
when click it creates a new button button 2 and adds a event handler to
it.

but when button 2 is clicked nothing happens, why?

Partial Class test_buttons

Inherits System.Web.UI.P age

Dim bt2 As Button

Dim bt3 As Button

Dim test1 As Boolean = False

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.Event Args) Handles Button1.Click

bt2 = New Button

bt2.Text = "Button2"

AddHandler bt2.Click, AddressOf bt2Click

form1.Controls. Add(bt2)

Response.Write( "Button 1")

End Sub

Sub bt2Click(ByVal sender As Object, ByVal e As System.EventArg s)

If test1 = True Then

Response.Write( "Button 2")

End If

End Sub

End Class


Dec 31 '06 #5

"Karl Seguin" <ka********@rem oveopenmymindre movemetoo.andme netwrote in
message news:OB******** ******@TK2MSFTN GP04.phx.gbl...
Clicking australia doesn't bring anything up for me.
you may of visited the site whne i was working on it.
I would look at Denis Bauer's control if you are dealing with that many
dynamic controls.

An alternative would be to forgo the postback mechanism and simply use the
QueryString - this would have the added benefit of being
bookmarkable... sometimes old tricks work best.
I would like to work it out al the same

thanks
>
Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Slim" <me@here.comwro te in message
news:Od******** ******@TK2MSFTN GP06.phx.gbl...
>Actualy i still have a problem

on this page
http://worldgolfdata.com/Enter/Default.aspx
i have a list of countries when you click on them you get a list of
states, click on a state youi get a list of golf courses from that state.

I have a little bit of test data in it, if you go to Australia, then
select either Victoria or Western Australia you will get a list of 1 or 2
courses repectivly.

I also have a lale that shows what event handler has fired.

if you have a play you will se that when you change state from victoria
to western australia then click on a course the lable shows that the
event handler does not fire till you click the second time.

Can you tell me why and suggets a fix or a workaround?

here is the code

Partial Class Enter_Default
Inherits System.Web.UI.P age

Protected Sub Page_PreLoad(By Val sender As Object, ByVal e As
System.EventAr gs) Handles Me.PreLoad
buildCountrys()
If ViewState("buil dStates") <"" Then
buildStates()
End If
If ViewState("buil dCourses") <"" Then
buildCourses()
End If
End Sub

Sub buildCountrys()
Dim oCountries As Countries
oCountries = New Countries
Dim i As Integer
For i = 0 To UBound(oCountri es.getCountries )
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkCountry As LinkButton = New LinkButton
AddHandler linkCountry.Cli ck, AddressOf CountryButtClic k
linkCountry.OnC lientClick = "waitForIt( )"
linkCountry.Att ributes.Add("cl ass", "dButtons")
linkCountry.Com mandArgument = oCountries.getC ountries(i).id
linkCountry.Tex t = oCountries.getC ountries(i).Nam e
td.Controls.Add (linkCountry)
tr.Cells.Add(td )
countryTable.Ro ws.Add(tr)
Next
End Sub

Sub buildStates()
stateTable.Rows .Clear()
courseTable.Row s.Clear()
Dim oCountry As Country
oCountry = New Country(ViewSta te("buildStates "))
Dim i As Integer
For i = 0 To UBound(oCountry .getStates)
'On Error Resume Next
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkState As LinkButton = New LinkButton
AddHandler linkState.Click , AddressOf StateButtClick
linkState.OnCli entClick = "waitForIt( )"
linkState.Attri butes.Add("clas s", "dButtons")
linkState.Comma ndArgument = oCountry.getSta tes(i).id
linkState.Text = oCountry.getSta tes(i).Name
td.Controls.Add (linkState)
tr.Cells.Add(td )
stateTable.Rows .Add(tr)
Next
End Sub

Sub buildCourses()
courseTable.Row s.Clear()
Dim oState As State
oState = New State(ViewState ("buildCourses" ))
Dim i As Integer
For i = 0 To UBound(oState.g etCourses)
If oState.countCou rses 0 Then
Dim tr As TableRow = New TableRow
Dim td As TableCell = New TableCell
Dim linkCourse As LinkButton = New LinkButton
AddHandler linkCourse.Clic k, AddressOf CourseButtClick
linkCourse.OnCl ientClick = "waitForIt( )"
linkCourse.Attr ibutes.Add("cla ss", "dButtons")
linkCourse.Comm andArgument = oState.getCours es(i).id
linkCourse.Text = oState.getCours es(i).Name
td.Controls.Add (linkCourse)
courseTable.Row s.Add(tr)
tr.Cells.Add(td )
Else
End If
Next
End Sub

Sub CountryButtClic k(ByVal sender As Object, ByVal e As EventArgs)
ViewState.Add(" buildStates", sender.CommandA rgument)
Label1.Text = "country clicked"
buildStates()

End Sub

Sub StateButtClick( ByVal sender As Object, ByVal e As EventArgs)
ViewState.Add(" buildCourses", sender.CommandA rgument)
Label1.Text = "state clicked"
buildCourses()

End Sub

Sub CourseButtClick (ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = "course clicked"
End Sub

End Class

"Slim" <me@here.comwro te in message
news:O5******* *******@TK2MSFT NGP04.phx.gbl.. .
>>Thanks your example worked fine.
I did try something like this before that made the button persist but
did not add handlers, but all working fine now, thanks allot

"Karl Seguin" <ka********@rem oveopenmymindre movemetoo.andme netwrote in
message news:OC******** *****@TK2MSFTNG P04.phx.gbl...
When button2 is clicked, the page postback. At this point button2
doesn't exist any more. You may think that the ViewState takes care of
this, but it only takes care of maintaing values, not actual controls.

You need to re-create button2 on or before the Load event and hook up
it's event handler to have it work. As a matter of fact, you don't even
need to do the AddHandler in the Button1 click, the AddHandler needs to
be done on postback before/during the load event.

One way people often do this is by storing values in the viewstate,
something like:

Button1_Clic k(...)
dim bt2 as button = new Button()
...
form1.Controls. Add(bt2)
ViewState.Add(" LoadButton2", true)
end sub

OnLoad(... )
if Page.IsPostBack then
if not ViewState("Load Button2") is nothing AndAlso
cbool(ViewSt ate("LoadButton 2")) == true then
dim bt2 as button = new Button()
Addhandler bt2.Click ....
Form1.Controls. Add(bt2)
end if
end if
end sub

Denis Bauer has a special PlaceHolderCont rol that will do all of this
for you. It's free:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

You should check it out and you might be interested in looking at thee
source code to gain a better fundamental understanding of how it
works...

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Slim" <me@here.comwro te in message
news:%2***** **********@TK2M SFTNGP02.phx.gb l...
>i have a simple page, with one button button1.
when click it creates a new button button 2 and adds a event handler
to it.
>
but when button 2 is clicked nothing happens, why?
>
Partial Class test_buttons
>
Inherits System.Web.UI.P age
>
Dim bt2 As Button
>
Dim bt3 As Button
>
Dim test1 As Boolean = False
>
Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.Even tArgs) Handles Button1.Click
>
bt2 = New Button
>
bt2.Text = "Button2"
>
AddHandler bt2.Click, AddressOf bt2Click
>
form1.Controls. Add(bt2)
>
Response.Write( "Button 1")
>
End Sub
>
Sub bt2Click(ByVal sender As Object, ByVal e As System.EventArg s)
>
If test1 = True Then
>
Response.Write( "Button 2")
>
End If
>
End Sub
>
End Class
>
>


Dec 31 '06 #6

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

Similar topics

0
1167
by: Supra | last post by:
how do i do get menuitem "Connect" in addhandler ? Private Sub mnuIrc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuIrcConnect.Click, mnuIrcPref.Click, mnuIrcExit.Click Dim mi As MenuItem = CType(sender, MenuItem) Select Case mi.Text Case "Connect" Dim p As Integer = 6667
0
1103
by: Jeffrey A. Voigt | last post by:
Can someone take a quick glace at my code and tell me why my AutoPostBackHandler function does not get fired off at all? What I'm trying to do is get all of the Buttons and DropDownList controls that have an AutoPostBack property set to true to fire off the AutoPostBackHandler function dynamically. I achive this by going through all controls that are on the WebPage and seting up the handler on the fly. I've debugged this and know for a...
3
1656
by: Nathan Sokalski | last post by:
I am using the AddHandler statement to add a CheckedChanged event handler to a series of RadioButtons that I create in a loop. However, the handler is not being called for a reason I cannot determine. What is the problem? Here is my code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load currpoem = Server.UrlDecode(Request.QueryString("poem")) Dim ratinglabels As New TableRow Dim...
1
2223
by: Luis Esteban Valencia Muñoz | last post by:
Have a dropdownlist created in my LoadMain() which is called from the Page_load: ************************PAGE LOAD********************8Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try 'Initialize. Main.SetBodyURL(Page) conSess = MySession.Connection(Session) objPP = MySession.ProdPres(Session, Req.ID(Request))
4
2366
by: DJ | last post by:
Good morning, Still new at this so please bear with me. I am creating a table dynamically using webcontrols based on the output of a sproc from my database.The table represents test instances that the test proctor who is viewing the page has currently assigned to him or heir. Each row of the table corresponds to a single test instance and includes required info about that test. At the end of the row I create a button control. Based on...
2
2760
by: Just Me | last post by:
When a document is to be printed I call a method that contains an AddHandler statement. I just realized that if a second copy is to be printed the method is called and the AddHandler is executed again. Is doing AddHandler a second time wrong? I did check and even though I do AddHandler 3 times the handler is only called once.
6
9145
by: Carlo3030 | last post by:
Been reading Dino Esposito's Article "A DetailsView Control for ASP.NET 1.x" found in the msdn Library. His example was created using VB.NET. I am trying to convert the example (DetailsView control) to C#. The Issue is I converted this line (in VB): AddHandler _insertButton.Click, AddressOf OnApplyInsertMode to C#.NET with this:
5
2603
by: ugavnholt | last post by:
Hi All, I'm having a problem with a small bit of code: Dim deleteButton = New System.Web.UI.WebControls.ImageButton deleteButton.imageURL = "images/icondelete.gif" deleteButton.ToolTip = "Delete Data Source" deleteButton.CommandArgument = "Delete1" AddHandler deleteButton.Click, AddressOf DeleteDataSource_Click
15
2058
by: Nathan Sokalski | last post by:
I have a section of my code that dynamically creates LinkButtons to allow the user to go to the page containing a question they have not answered. The code that creates the LinkButton is called, as well as the AddHandler line (I ran a Debug and saw that it executes this code, and the links are displayed on the page afterwards). However, the eventhandler is not called when the LinkButton is clicked. Here is the code that dynamically...
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.