snit80
snit80

Reputation: 731

Access custom attribute and value in c# code behind

I want to access custom attribute in the code behind, how can I?

e.g. my server control

<asp:HyperLink ID="id_1" runat="server" Target="_blank" NavigateUrl="xyz" Style="color:red"></HyperLink>

'Style' is not an Attribute of HyperLink as a result it is not rendered in the HTML, so I want to access the Style value in c# code behind and once I access it i can dom something like below which works.

id_1.Attributes.Add("Style","color:red");

Any help is appreciated. If you guys have any other suggestion, that is appreciated as well.

Upvotes: 0

Views: 3187

Answers (1)

Stinky Towel
Stinky Towel

Reputation: 778

string value = id_1.Attributes["Style"].ToString();

Upvotes: 2

Related Questions