get ID attribute from HTML buttons?

R

RN

I am dynamically adding a number of HTML buttons to a page...

<input type="submit" name="alwaysthesame" id="different1"
value="alwaysthesame">
<input type="submit" name="alwaysthesame" id="different2"
value="alwaysthesame">
<input type="submit" name="alwaysthesame" id="different3"
value="alwaysthesame">

I want them all to have the same name NAME attribute and the same VALUE
attribute, but different ID attributes. This way I can have a bunch of
buttons and easily check for which one was pressed. Like having a "radio
button group" but instead it will be a "command button group" with each
button in a different place. I don't want to dynamically add server-side
controls because it would be really hard to have different NAME fields
considering that the number of buttons I have to create is different
depending upon the data.

The problem with "html only" way of sending the data is that I can't figure
out to how read the "id" value back from the server on postback. Is there
a way?
 
G

Guest

Hi

When you are creating HTML only buttons no need for you to have different ID
to use. You can have all the button have a single name and in the server side
just say, Request["htmlButtonName"] you will get the value of the button that
was clicked. So just have different value for each of the button and you will
come to know which one was clicked.

I would suggest have multiple server buttons and write only one function
which handles click of all the button. You can use the Commandevent Args to
see which button was clicked.

regards
Lohith
Blore,
India
 
R

RN

Yes, but the value attribute stupidly is what appears on the face of the
button and I want to store an ID number. Thus I WANT to use the ID
attribute. Is there a way of retrieve that?


kashypa said:
Hi

When you are creating HTML only buttons no need for you to have different ID
to use. You can have all the button have a single name and in the server side
just say, Request["htmlButtonName"] you will get the value of the button that
was clicked. So just have different value for each of the button and you will
come to know which one was clicked.

I would suggest have multiple server buttons and write only one function
which handles click of all the button. You can use the Commandevent Args to
see which button was clicked.

regards
Lohith
Blore,
India
RN said:
I am dynamically adding a number of HTML buttons to a page...

<input type="submit" name="alwaysthesame" id="different1"
value="alwaysthesame">
<input type="submit" name="alwaysthesame" id="different2"
value="alwaysthesame">
<input type="submit" name="alwaysthesame" id="different3"
value="alwaysthesame">

I want them all to have the same name NAME attribute and the same VALUE
attribute, but different ID attributes. This way I can have a bunch of
buttons and easily check for which one was pressed. Like having a "radio
button group" but instead it will be a "command button group" with each
button in a different place. I don't want to dynamically add server-side
controls because it would be really hard to have different NAME fields
considering that the number of buttons I have to create is different
depending upon the data.

The problem with "html only" way of sending the data is that I can't figure
out to how read the "id" value back from the server on postback. Is there
a way?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top