Mujahid Mujahid - 1 month ago 16
ASP.NET (C#) Question

changing attribute of a html div tag from asp.net

i have following in my html page and i want to change its Data-To attribute value from code behind in asp.net

<div id="camp" class="number count-to" data-from="0" data-to="125" data-speed="1000" data-fresh-interval="20"></div>


I have a javascript function that sets the value but i'm not able to set its value from code behind in asp.net my java script function is following...

<script type="text/javascript">

function myfunc() {
$('#camp').countTo({ from: 0, to: 100 });
}
my func();
</script>


i want to call my func from asp.net..

Answer
<div id="camp" class="number count-to" data-from="<%= SomeFromValue %>" data-to="<%= SomeToValue%>" data-speed="1000" data-fresh-interval="20"></div>

Alternatively give it a runat="server" and set it from code behind:

<div runat=server id="camp" class="number count-to" data-speed="1000" data-fresh-interval="20"></div>

Somewhere in code behind:

 camp.Attributes.Add("data-to", "10");
 camp.Attributes.Add("data-from", "1");
Comments