I want to add HTML structure and control like this from code behind into a panel
First Name
-
For appending HTML to your panel, add a LiteralControl
control to your panel:
string yourHTMLstring = "<div class='Main'>....";
pnlUserdata.Controls.Add(new LiteralControl(yourHTMLstring));
讨论(0)
-
Make the div runat="server"
<div id="d" runat="server"></div>
and add the controls inside div like below
d.Controls.Add();
讨论(0)
-
- Take one local string variable TEMP.
- Create same html as you want to display on screen and store it in variable TEMP.
- You can take html creation of control in separate function based on requirement.
- Place that created html as innerHTML to your panel/div.
That's it...
讨论(0)
-
Don't add that child control to the panel, add it to the control that should be the parent:
HtmlGenericControl divcontrol = new HtmlGenericControl();
divcontrol.Attributes["class"] = "sxro sx1co";
divcontrol.TagName = "div";
pnlUserSearch.Controls.Add(divcontrol);
Label question = new Label();
questionDescription.Text = "text";
divcontrol.Controls.Add(question); // add to the new div, not to the panel
讨论(0)
-
<div id="Div1" runat="server">
Div1.InnerText = "Text";
讨论(0)