Reputation: 385
I have div
control which runs on server
<div id="report" runat="server" ></div>
I'm appending some content to the above div
using jquery
at run time. Now i want to access the innerHtml of the above div.
example:
<div id="report" runat="server" >
<div class="someclass">some Text1</div>
<div class="someclass">some Text2</div>
<div class="someclass">some Text3</div>
</div>
expected output is(following HTML in a string format):
<div class="someclass">some Text1</div>
<div class="someclass">some Text2</div>
<div class="someclass">some Text3</div>
so far i tried the following two methods but no luck
ContentPlaceHolder myContent = (ContentPlaceHolder)this.Master.FindControl("contentPlaceHolder");
Control cc= myContent.FindControl("report");
and
string HTMLString=report.InnerHtml;
Upvotes: 0
Views: 1725
Reputation: 17614
Form input elements inside a form element posted to server.
All other content is static and not posted to server.
It's fundamental rule of HTTP, you can see details from here.
So you cannot get the report.InnerHtml
.
You have two option, while preparing your div's content, write the same content inside a hidden field. And at server side get the hidden field's value.
<input type="hidden" id="hdnDivContents" runat="server">
and set the value using jquery or javascript.
$('#<% hdnDivContents.ClientID %>').val($("#<% report.ClientID %>").val());
and get the value in code behind
string HTMLString=hdnDivContents.Value;
Or make an AJAX call while preparing your content to get it at server side.
Upvotes: 1