Search:
Namespaces
Discussions
.NET v1.1
Feedback
Adding Handlers to controls programmatically (event handler not firing)
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngvb' list
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Eric Landes (VIP)
I have added a control programmatically to a page and have added an =
event
handler. This particular event handler is for clicking a button. =
However
when I step through the code, the click event does not fire. Any ideas =
why?
(below is the code:
Dim oSubmitButton As New System.Web.UI.WebControls.
Button
()
oSubmitButton.Text =3D "View Report"
AddHandler oSubmitButton.Click, AddressOf PCRMButtonClicked
Page
.Controls(1).Controls.Add(oSubmitButton)
Public Sub PCRMButtonClicked(ByVal sender As System.
Object
, ByVal e =
As
System.EventArgs)
do something
End Sub
TIA
*************************=20
Eric Landes=20
Senior Programmer/Analyst (Partners Health Plan)=20
For Articles on Crystal.Net, Datagrids and more check out
http://www.aspalliance.com/corporatecoder/
*************************=20
All statements expressed are my own, and do not reflect the opinion of =
my
employer, unless stated otherwise.=20
Confidentiality Notice: This e-mail message, including any
attachments, is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.
PARTNERS Health Plan Phone: 574-233-4899
100 E. Wayne St., Suite 502 Fax: 574-234-7484
South Bend, IN 46601 www.partnersindiana.com
Reply to this message...
Eric Landes (VIP)
Darren,
Thanks again for the help. For anyone interested, and for the archives, I
fixed this using a combination of things. The ID on all my objects was a
main part (as Darren suggested). Also, I placed all my dynamically created
controls inside a panel. By using panel1.controls.add(controlname), this
worked. Now on to bigger and better things! I also found this web page at
msdn helpful: (watch for wrapping)
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/vbcon/html
/" target="_blank">
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/vbcon/html
/
vbtskAddingControlsToWebFormsPageProgrammatically.asp
<
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/vbcon/html
/vbtskAddingControlsToWebFormsPageProgrammatically.asp>=20
=20
Eric =20
-----Original Message-----
From: Eric Landes=20
Sent: Monday, August 19, 2002 9:39 AM
To: 'aspngvb'
Subject: RE: [aspngvb] Adding Handlers to controls programmatically (event
handler not firing)
I've added the id to the button so my code looks like this:
Dim oSubmitButton As New System.Web.UI.WebControls.
Button
()
oSubmitButton.Text =3D "View Report"
oSubmitButton.ID =3D "ReportButton"
AddHandler oSubmitButton.Click, AddressOf PCRMButtonClicked
But when you say to add the mybutton.click to my code, that loses the
ability I want of dynamically adding a button, and attaching code to the
click event. My reading of the docs, indicates that using the addhandler
statment accomplishes the same goal. Is that correct?
Also, I believe that I am losing all my dynamically created objects in
postback, so perhaps I am doing something wrong there?
Appreciate any ideas.
Eric
-----Original Message-----
From: Darren Neimke [mailto:
Click here to reveal e-mail address
]
Sent: Friday, August 16, 2002 6:17 PM
To: aspngvb
Subject: RE: [aspngvb] Adding Handlers to controls programmatically (event
handler not firing)
You need to give the
Button
an ID:
=20
oSubmitButton.ID =3D "MyButton"
Then add the Handles statement to the method that will handle its click
event:
=20
Public Sub ...(...) Handles MyButton.Click
...
End Sub=20
-----Original Message-----=20
From: Eric Landes [mailto:
Click here to reveal e-mail address
]=20
Sent: Sat 8/17/2002 5:27 AM=20
To: aspngvb=20
Cc:=20
Subject: [aspngvb] Adding Handlers to controls programmatically (event
handler not firing)
I have added a control programmatically to a page and have added an event
handler. This particular event handler is for clicking a button. However
when I step through the code, the click event does not fire. Any ideas why?
(below is the code:
Dim oSubmitButton As New System.Web.UI.WebControls.
Button
()
oSubmitButton.Text =3D "View Report"
AddHandler oSubmitButton.Click, AddressOf PCRMButtonClicked
Page
.Controls(1).Controls.Add(oSubmitButton)
Public Sub PCRMButtonClicked(ByVal sender As System.
Object
, ByVal e As
System.EventArgs)
do something
End Sub
TIA
*************************
Eric Landes
Senior Programmer/Analyst (Partners Health Plan)
For Articles on Crystal.Net, Datagrids and more check out
http://www.aspalliance.com/corporatecoder/
<
http://www.aspalliance.com/corporatecoder/
>=20
*************************
All statements expressed are my own, and do not reflect the opinion of my
employer, unless stated otherwise.
Confidentiality Notice: This e-mail message, including any
attachments, is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.
PARTNERS Health Plan Phone: 574-233-4899
100 E. Wayne St., Suite 502 Fax: 574-234-7484
South Bend, IN 46601 www.partnersindiana.com
------_=_NextPart_001_01C24796.681BE400
Content-Type: text/html;
charset="UTF-8"
Reply to this message...
Darren Neimke
WW91IG5lZWQgdG8gZ2l2ZSB0aGUgQnV0dG9uIGFuIElEOg0KIA0KICAgIG9TdWJtaXRCdXR0b24u
SUQgPSAiTXlCdXR0b24iDQoNClRoZW4gYWRkIHRoZSBIYW5kbGVzIHN0YXRlbWVudCB0byB0aGUg
bWV0aG9kIHRoYXQgd2lsbCBoYW5kbGUgaXRzIGNsaWNrIGV2ZW50Og0KIA0KICAgIFB1YmxpYyBT
dWIgLi4uKC4uLikgSGFuZGxlcyBNeUJ1dHRvbi5DbGljaw0KICAgICAgICAuLi4NCiAgICBFbmQg
U3ViIA0KDQoNCgktLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLSANCglGcm9tOiBFcmljIExhbmRl
cyBbbWFpbHRvOmVsYW5kZXNAcGFydG5lcnNpbmRpYW5hLmNvbV0gDQoJU2VudDogU2F0IDgvMTcv
MjAwMiA1OjI3IEFNIA0KCVRvOiBhc3BuZ3ZiIA0KCUNjOiANCglTdWJqZWN0OiBbYXNwbmd2Yl0g
QWRkaW5nIEhhbmRsZXJzIHRvIGNvbnRyb2xzIHByb2dyYW1tYXRpY2FsbHkgKGV2ZW50IGhhbmRs
ZXIgbm90IGZpcmluZykNCgkNCgkNCg0KCUkgaGF2ZSBhZGRlZCBhIGNvbnRyb2wgcHJvZ3JhbW1h
dGljYWxseSB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wgaHR0cDovL3d3dy5hc3BsaXN0cy5jb20vYXNwbGlzdHMvYXNwbmd2Yi5hc3AgPSBKT0lOL1FV
SVQNCgkNCg0K
Reply to this message...
Eric Landes (VIP)
I've added the id to the button so my code looks like this:
Dim oSubmitButton As New System.Web.UI.WebControls.
Button
()
oSubmitButton.Text =3D "View Report"
oSubmitButton.ID =3D "ReportButton"
AddHandler oSubmitButton.Click, AddressOf PCRMButtonClicked
But when you say to add the mybutton.click to my code, that loses the
ability I want of dynamically adding a button, and attaching code to the
click event. My reading of the docs, indicates that using the addhandler
statment accomplishes the same goal. Is that correct?
Also, I believe that I am losing all my dynamically created objects in
postback, so perhaps I am doing something wrong there?
Appreciate any ideas.
Eric
-----Original Message-----
From: Darren Neimke [mailto:
Click here to reveal e-mail address
]
Sent: Friday, August 16, 2002 6:17 PM
To: aspngvb
Subject: RE: [aspngvb] Adding Handlers to controls programmatically (event
handler not firing)
You need to give the
Button
an ID:
=20
oSubmitButton.ID =3D "MyButton"
Then add the Handles statement to the method that will handle its click
event:
=20
Public Sub ...(...) Handles MyButton.Click
...
End Sub=20
-----Original Message-----=20
From: Eric Landes [mailto:
Click here to reveal e-mail address
]=20
Sent: Sat 8/17/2002 5:27 AM=20
To: aspngvb=20
Cc:=20
Subject: [aspngvb] Adding Handlers to controls programmatically (event
handler not firing)
I have added a control programmatically to a page and have added an event
handler. This particular event handler is for clicking a button. However
when I step through the code, the click event does not fire. Any ideas why?
(below is the code:
Dim oSubmitButton As New System.Web.UI.WebControls.
Button
()
oSubmitButton.Text =3D "View Report"
AddHandler oSubmitButton.Click, AddressOf PCRMButtonClicked
Page
.Controls(1).Controls.Add(oSubmitButton)
Public Sub PCRMButtonClicked(ByVal sender As System.
Object
, ByVal e As
System.EventArgs)
do something
End Sub
TIA
*************************
Eric Landes
Senior Programmer/Analyst (Partners Health Plan)
For Articles on Crystal.Net, Datagrids and more check out
http://www.aspalliance.com/corporatecoder/
<
http://www.aspalliance.com/corporatecoder/
>=20
*************************
All statements expressed are my own, and do not reflect the opinion of my
employer, unless stated otherwise.
Confidentiality Notice: This e-mail message, including any
attachments, is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.
PARTNERS Health Plan Phone: 574-233-4899
100 E. Wayne St., Suite 502 Fax: 574-234-7484
South Bend, IN 46601 www.partnersindiana.com
| [aspngvb] member
Click here to reveal e-mail address
=3D YOUR ID
|
http://www.asplists.com/asplists/aspngvb.asp
<
http://www.asplists.com/asplists/aspngvb.asp
> =3D JOIN/QUIT
Confidentiality Notice: This e-mail message, including any
attachments, is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not
the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message.
PARTNERS Health Plan Phone: 574-233-4899
100 E. Wayne St., Suite 502 Fax: 574-234-7484
South Bend, IN 46601 www.partnersindiana.com
------_=_NextPart_001_01C2478E.224CECB0
Content-Type: text/html;
charset="UTF-8"
Reply to this message...
System.EventArgs
System.Object
System.Web.UI.Page
System.Web.UI.WebControls.Button
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com