VB.NET - Text Box - Asked By pradnya sahu on 10-Nov-11 04:24 AM

I have 3 Text boxes with following id and i have given same name to all 3 text boxes is it ok or it will effect wrong for same name

<input id="txtFile1" name="Attachment" />

<input id="txtFile2" name="Attachment" />

<input id="txtFile3" name="Attachment" />


Chintan Vaghela replied to pradnya sahu on 10-Nov-11 04:30 AM

There is no any problem

Id must be unique

Name can be same

Hope this helpfule
Chintan Vaghela replied to pradnya sahu on 10-Nov-11 04:33 AM

When controls that share the same NAME attribute they can still be accessed as integer indexed members of the FORM element's elements collection.

But when the member of the elements collection is accessed using the NAME attribute value as a property name browsers return a collection all of the elements with the corresponding NAME attributes

Hope this helpful
Suchit shah replied to pradnya sahu on 10-Nov-11 04:33 AM
As you have defined the different ID there is no issue but here in code you have not defined the Type propery of the Input control ?
Kirtan Patel replied to pradnya sahu on 10-Nov-11 05:14 AM
there will be problem when u access them using java script if you want something that tell the system that they are belong to same group them put class instead of name as same because when you post data by form it will cause ambiguity in data

<input class="TextBox" id="txtFile1" name="Attachment1" />

<input class="TextBox" id="txtFile2" name="Attachment2" />

<input  class="TextBox" id="txtFile3" name="Attachment3" />


dipa ahuja replied to pradnya sahu on 10-Nov-11 05:17 AM
The name is used when sending data in a form submission. Different controls respond differently. For example, you may have several radio buttons with different ids, but the same name.

When submitted, there is just the one value in the response - the radio button you selected.
So if you are going to use GET an POST then you can recognize the controls using its name property
where as ID is used if we include runat="server" attribute and access it in codebehind