JCS
JCS

Reputation: 907

Getting the name attribute of a HTML check box(and other elements) in ASP.NET using C#

I am trying to get the name of check boxes so that i can group all check boxes with the same name, i have tried cb.Name (cb is a object of type HtmlInputCheckBox) this only returns the id, i also have tried cb.Attributes["name"] which also gives nothing. Not sure any other ways to get the name attribute of a check box any body else have an idea?

Upvotes: 1

Views: 324

Answers (2)

Francis Gagnon
Francis Gagnon

Reputation: 3675

If you want to work around the way ASP.NET renders the name attribute, you might want to remove the runat="server" from the input tags in your markup. That way the tags will be rendered as they are in the markup an won't be processed by the HtmlInputCheckBox class. You can get the values of the checkbox by using Request.Form["nameOfCheckbox"] in a postback event.

Upvotes: 1

Adil
Adil

Reputation: 148110

You can assign same GroupName to all the checkboxes property to group them.

cb1.GroupName = "SomeName";
cb2.GroupName = "SomeName";    

Upvotes: 0

Related Questions