Want to access literal value into javascript

吃可爱长大的小学妹 提交于 2019-12-06 15:28:00

An ASP.NET Literal control does not by itself insert any HTML into a webpage. Your Literal control is a placeholder for text or HTML you will set in your code behind.

You should wrap your literal in a DIV or SPAN and give that an ID and reference that DIV or SPAN in the JavaScript

WebForm:

<span id="yourId"><asp:Literal  ID="lblPerInstanceListing" runat="server"></asp:Literal></span>

JavaScript: Solved by this code.

var value= document.getElementById('yourId').innerText;
<span id="yourId" runat="server"></span>

js :

var value= document.getElementById('yourId');

It is not better then use this code?? You can put in span enableviewstate to false if You need.

It's a Literal. It renders literal HTML to the page. It doesn't render any container matching the ClientID that you can access on the client side.

Either put a div or span in the literal with an ID you can use, or use e.g. a Label or Panel control that does render a wrapping span or div you can use.

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