Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Name and ID attributes of the server HTMLControls

Thread Tools

Name and ID attributes of the server HTMLControls

Parag Mahajan
Posts: n/a

I am having trouble in assigning "id" as well as the "name" attribute for
the 2.0 webcontrol I am developing.

Consider my control below:
public class MyWebControl : WebControl
divCtrl = new HtmlGenericControl("div");
HtmlInputText t = new HtmlInputText();
t.Attributes["name"] = "textboxnameAttrName";
t.Attributes["id"] = "textboxnameAttrID";

For this, I get the following output HTML.

<span id="MyWebControl1"><div><input name="ctl03" type="text"
id="textboxnameAttrID" /></div></span>

My question over here is, why does the name attribute of the input html
element is "ctl03" and not "textboxnameAttrName" (the one which I set it
programmatically). I even tried with the below statement

t.Name = "textboxname";

I still get the same output as above..


I have one more question here, is that when I set the property "ID" of the
HtmlInputText control, it also sets the "name" attribute of the rendered
HTML text box to be the same as "id" attribute. (This is what MSDN also
says.) But I did not understand why is this such a behaviour.

When I have the following lines in the control,
t.ID = "textboxnameAttrID";
t.Attributes["name"] = "textboxnameAttrName";

the output HTML is :
<span id="MyWebControl1"><div><input name="IDText" type="text" id="IDText"
type="text" /></div></span>

Can anyone please let me know, why is this such a behaviour?
For the ASP.Net control, can I not set "id" as well as the "name" attribute
as per my requirement.?

By this, I mean I want the HTML output to be like this,
<span id="MyWebControl1"><div><input name="textboxnameAttrName" type="text"
id="textboxnameAttrID" /></div></span>

Thanks and Regards,

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
obtain element name, or attribute and value of the document name itself, and some elemnts and attributes from an ancestor or the node itself using xquery Jeff Kish XML 4 10-30-2008 05:47 PM
htmlcontrols not reflecting changes upon return to the server =?Utf-8?B?U3RldmVuLkRhaGxpbg==?= ASP .Net 3 08-06-2004 12:02 PM
difference between HtmlControls and WebControls? Henri ASP .Net 4 05-18-2004 05:04 PM
WebControls and HtmlControls Abhishek Srivastava ASP .Net 0 05-12-2004 06:13 AM
Difference between HtmlControls and server controls Gopal Prabhakaran ASP .Net 1 01-26-2004 02:03 PM