Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find span from code behind and add user control to it?

I've a div

<div id="PageContent" runat="server"></div>

Now I'm adding HTML to it from code behind(c#) like this

PageContent.InnerHtml =mytext;

where mytext is the content I want to add in PageContent div, mytext contains a span in between some text(it can be any string), something like this

This is some <span id="span1"> </span> text

How can I find span from code behind and add user control to it?

like image 499
Sid M Avatar asked Oct 03 '22 17:10

Sid M


1 Answers

//This is some <span id="span1" runat="server"> </span>

//In the code behind...

var span1 = this.FindControl("span1") as HtmlGenericControl;
var controlPath = "path of your user control";
var someControl = LoadControl(controlPath);
span1.Controls.Add(someControl);
like image 103
Tausif Alam Avatar answered Oct 20 '22 11:10

Tausif Alam