Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set data-attributes with ASP.NET?

How can data-attributes be set using code behind?

ASP.NET

<asp:Label ID="lbl" runat="server" Text="Value" />
<asp:Panel ID="pnl" runat="server" />    

VB

lbl.Text = "Text"
pnl.Attributes("data-attribute") = "200"
//Is this correct?

DESIRED MARKUP

<span id="lbl">Text</span>
<div id="pnl" data-attribute="200">Value</div>
like image 485
DreamTeK Avatar asked Oct 24 '25 14:10

DreamTeK


2 Answers

pnl.Attributes("data-attribute") = "200"
like image 66
Yuriy Galanter Avatar answered Oct 26 '25 05:10

Yuriy Galanter


C#:

pnl.Attributes["data-attribute"] = "200";

VB:

pnl.Attributes("data-attribute") = "200"
like image 40
igal Avatar answered Oct 26 '25 05:10

igal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!