简体   繁体   中英

Problems with using .InnerHtml in ASP.NET c #

I have a div in the aspx page which i gave the attribute runat = "server" and id = "content". When starting the page I need to create some cards with data taken from a database. But it gives me error when I try from code behind in c # using content.InnerHtml to add html code.

aspx page

<div class="page-wrapper">
            <div class="page-content" runat="server" id="contenuto">

            </div>
</div>

code behind

contenuto.InnerHtml += "<div class='row'>";

it gives me this error: "Could not get the internal content of content because it is not in literal format."

image of the Error

"contenuto" not containing any server control inside it, you required to change your code like below -

var sb = new StringBuilder();
String innertext =sb.Append("Text what you required or tag");
contenuto.InnerHtml = innertext ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM