set div data attribute using a code behind value in an aspx page

陌路散爱 提交于 2019-12-13 02:19:32

问题


On an .aspx page I need to set the data-attribute on a addthis div. The value is an URL that is calculated in the code behind.

<div class="addthis_sharing_toolbox" data-url="CodeBehindValue"></div>

Is there a way to do this?


回答1:


You have a couple options.

Using a property

<div class="addthis_sharing_toolbox" data-url="<%= PropertyFromCodeBehind %>"></div>

Using a method

<div class="addthis_sharing_toolbox" data-url="<%= MethodFromCodeBehind() %>"></div>



回答2:


If you choose your div to run at the server (runat="server") such as:

<div id="divMyID" class="addthis_sharing_toolbox" data-url="CodeBehindValue" runat="server"></div>

divMyID.Attributes("data-url") = "http://www.test.com"


来源:https://stackoverflow.com/questions/31861220/set-div-data-attribute-using-a-code-behind-value-in-an-aspx-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!