473,503 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve htmlbutton ID from placeholder

Hi!

I hope someone can assist... this has been driving me crazy!!

I have dynamically added several htmlbuttons to a placeholder control
using...
AddHandler btnReports.ServerClick, AddressOf Get_Date_Range

In the Get_Date_Range sub, I am trying to find out which button was
clicked. Each button I dynamically created has a unique ID and text
value.

I need to get the ID of the clicked button to pass to another
sub-routine. The number of htmlbutton's within this placeholder does
vary depending on the current user's role (role-based forms
authentication).

Any advice would be very much appreciated!!!

Thanks,

John.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
4 1370
John,

You don't need to retrieve the clicked button id from the placeholder. It
comes to Get_Date_Range as the first parameter in the function call. It's
always the event sender. Typecast to your button type.

Eliyahu

"John Mason" <wo*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi!

I hope someone can assist... this has been driving me crazy!!

I have dynamically added several htmlbuttons to a placeholder control
using...
AddHandler btnReports.ServerClick, AddressOf Get_Date_Range

In the Get_Date_Range sub, I am trying to find out which button was
clicked. Each button I dynamically created has a unique ID and text
value.

I need to get the ID of the clicked button to pass to another
sub-routine. The number of htmlbutton's within this placeholder does
vary depending on the current user's role (role-based forms
authentication).

Any advice would be very much appreciated!!!

Thanks,

John.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2
Hi Eliyahu

Thank-you very much for your response.

Here is the placeholder code snipet:

Do While objDataReader.Read()
btnReports = New HtmlButton()
btnReports.Attributes.Add("class","btnClass")
btnReports.InnerHtml = objDataReader("DistrictName")
btnReports.ID = objDataReader("DistrictID")
AddHandler btnReports.ServerClick, AddressOf Get_District_Report
DistrictButtons.Controls.Add(btnReports)
Loop

Here is the Get_District_Report sub:

Sub Get_District_Report(sender As Object, e As System.EventArgs)
Dim b As System.Web.UI.WebControls.Button
Dim DistrictID as String
b = CType(sender, System.Web.UI.WebControls.Button)
DistrictID = b.ID

When I run this and click on the placeholder button, I get an error...

System.InvalidCastException: Specified cast is not valid.

This error refers to the line that begins with:

b = Ctype...

Any ideas?

Thanks,

John.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3
Certainly, HtmlButton and WebControls.Button are not same classes, and do not
have sub-base class relationship. The type cast will be failed. I guess,
you’ve already figured out the problem.

Shaw
"John Mason" wrote:
Hi Eliyahu

Thank-you very much for your response.

Here is the placeholder code snipet:

Do While objDataReader.Read()
btnReports = New HtmlButton()
btnReports.Attributes.Add("class","btnClass")
btnReports.InnerHtml = objDataReader("DistrictName")
btnReports.ID = objDataReader("DistrictID")
AddHandler btnReports.ServerClick, AddressOf Get_District_Report
DistrictButtons.Controls.Add(btnReports)
Loop

Here is the Get_District_Report sub:

Sub Get_District_Report(sender As Object, e As System.EventArgs)
Dim b As System.Web.UI.WebControls.Button
Dim DistrictID as String
b = CType(sender, System.Web.UI.WebControls.Button)
DistrictID = b.ID

When I run this and click on the placeholder button, I get an error...

System.InvalidCastException: Specified cast is not valid.

This error refers to the line that begins with:

b = Ctype...

Any ideas?

Thanks,

John.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #4
System.Web.UI.HtmlControls.HtmlButton

Of course! How silly of me...
Thank-you Shaw.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #5

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

Similar topics

5
4123
by: Info 3000 | last post by:
Hi there, Simple question, but headache ! I have a PHP Page like : <HTML> <HEAD> <TITLE>Sunny day !</TITLE> </HEAD>
2
4715
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the...
0
1569
by: shark | last post by:
I have a placeholder in a control that is in turn, used as a control in a placeholder in a form. I am getting a viewstate error so I believe I have to clear my placeholder before I load the...
1
5355
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My...
1
1005
by: Michael | last post by:
Only difference I noticed is in VS.NET, where I can see the events in the Properties window for the Button Web server control. Thanks.
3
1900
by: Bob | last post by:
Hi, I 'm starting asp.net and i saw two ways to make buttons. Which way to use? Are the htmlbuttons in specific case better than webbuttons? Are there advantages? Thanks Bob htmlbutton:...
0
1559
by: sydney.luu | last post by:
Hello, I have a web page where I dynamically create a TABLE with rows and cells. I fill these cells with application data. As I am building the cell, I add it to a PlaceHolder, which is a...
3
1981
by: Kees de Winter | last post by:
Hi, If I have a TextBox place inside a content placeholder then at runtime the TextBox's name changes to ctl00_ContentPlaceHolder1_tbCity. What is the best way to get the value of the TextBox...
6
2084
by: David Colliver | last post by:
Hi, using vb.net 1.1 I am trying to add a control to a placeholder but am having problems with it. I do it practically the same way as i do in C# (I have more C# skill than VB.NET)and I...
0
7205
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,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
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
7349
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
5594
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,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
399
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...

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.