By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

vs2005 HTML issue : "Another object on this page already uses ID"

P: n/a
here is the html :

<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="<%=LABEL_WIDTH%>" class="formtext"><%= HTEXT("Connection
type:")%></td>
<td class="formtext">
<input type="radio" class="inputRadio" id="dbStatus" name="dbStatus"
value="1" onclick="changeDbStatus(1)" <%if dbStatus=1 then%checked
<%end if%>><%= HTEXT("Control Server") %>
<input type="radio" class="inputRadio" id="dbStatus" name="dbStatus"
value="0" onclick="changeDbStatus(1)" <%if dbStatus=0 then%checked
<%end if%>><%= HTEXT("Historical Database") %>
</td>
</tr>
</table>
here is the error :

Another object on this page already uses ID 'dbstatus'

with squiggles under both occurrences of dbstatus .
Here is my colleague's take :

In classic HTML, this is very legal and common. The radio button that is
selected is the only one that posts back to the server. Its named value,
either 0 or 1, is sent back.

Even the duplicate id attributes are valid, as Jscript will just see an
array of two <inputobjects, not just a non-array of one object.

So, what is the way to do this same thing in ASPX?




Jul 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"chaz" wrote ...
here is the html :

<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="<%=LABEL_WIDTH%>" class="formtext"><%= HTEXT("Connection
type:")%></td>
<td class="formtext">
<input type="radio" class="inputRadio" id="dbStatus" name="dbStatus"
value="1" onclick="changeDbStatus(1)" <%if dbStatus=1 then%checked
<%end if%>><%= HTEXT("Control Server") %>
<input type="radio" class="inputRadio" id="dbStatus" name="dbStatus"
value="0" onclick="changeDbStatus(1)" <%if dbStatus=0 then%checked
<%end if%>><%= HTEXT("Historical Database") %>
</td>
</tr>
</table>
give them unique ID's, but keep the name attributes the same...

Rob
Jul 20 '06 #2

P: n/a
Hello Chaz,

According to the lastest html specifications such as the html4.0 or xhtml,
each element on the html page should has a unique id. And the VS 2005 html
editor use "XHTML 1.0 Transitional" to validate the aspx page template,
therefore, you'll get the "Another object on this page already uses ID xxx"
error message at design-time. To resolve this, you can assign each radio
button element an unique id value(use the "name" attribute to group them
instead).

Also, I've got from your first message that your concern here is how to
manipulate the radio button elements(in the same group) through a element
array rather than individual elements in client-side script, correct? As
for this point, I think we can use the "document.getElementByNames" to get
the list of radio button elements( in a certain group, with the same name
attribute) and process them through an array. For example, the following
script function get a list of radio elements through their name (group
name) and access each of them:

=======javascript=========
function display()
{
var list = document.getElementsByName("RadioButtonList1");
var i = 0;

for(i=0;i<list.length;i++)
{
var radio = list[i];
alert(radio.id);
}
}
==============

In addition, in ASP.NET, there is a RadioButtonList control that can help
simplify our work on creating list of Radiobuttons(belong to same group) on
the page. The RadioButtonList support populate radiobutton items by the
following means:

1. statically define radio button items in RadioButtonList's aspx template

2. programmatically create radio button items in code(add them into
RadioButtonList.Items collection)

3. use databinding to populate items (from some certain datasource).

You can find detailed information about the RadioButton and RadioButtonList
server control and how to use them in ASP.NET 2.0:

#RadioButton and RadioButtonList Web Server Controls
http://msdn2.microsoft.com/en-us/library/5xf4ea25.aspx

If there is anything unclear or any other questions, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 21 '06 #3

P: n/a
This is quite helpful Steven ,
Thank you and Rob for the replies .
-chaz

"Steven Cheng[MSFT]" wrote:
Hello Chaz,

According to the lastest html specifications such as the html4.0 or xhtml,
each element on the html page should has a unique id. And the VS 2005 html
editor use "XHTML 1.0 Transitional" to validate the aspx page template,
therefore, you'll get the "Another object on this page already uses ID xxx"
error message at design-time. To resolve this, you can assign each radio
button element an unique id value(use the "name" attribute to group them
instead).

Also, I've got from your first message that your concern here is how to
manipulate the radio button elements(in the same group) through a element
array rather than individual elements in client-side script, correct? As
for this point, I think we can use the "document.getElementByNames" to get
the list of radio button elements( in a certain group, with the same name
attribute) and process them through an array. For example, the following
script function get a list of radio elements through their name (group
name) and access each of them:

=======javascript=========
function display()
{
var list = document.getElementsByName("RadioButtonList1");
var i = 0;

for(i=0;i<list.length;i++)
{
var radio = list[i];
alert(radio.id);
}
}
==============

In addition, in ASP.NET, there is a RadioButtonList control that can help
simplify our work on creating list of Radiobuttons(belong to same group) on
the page. The RadioButtonList support populate radiobutton items by the
following means:

1. statically define radio button items in RadioButtonList's aspx template

2. programmatically create radio button items in code(add them into
RadioButtonList.Items collection)

3. use databinding to populate items (from some certain datasource).

You can find detailed information about the RadioButton and RadioButtonList
server control and how to use them in ASP.NET 2.0:

#RadioButton and RadioButtonList Web Server Controls
http://msdn2.microsoft.com/en-us/library/5xf4ea25.aspx

If there is anything unclear or any other questions, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 21 '06 #4

P: n/a
Thanks for your response Chaz,

Glad that the information is of assistance.

If you need any further assistance later, please feel free to post here.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.