Asp.NET C#.
It is possible to create HtmlGenericControl without tag ? If i write :
HtmlGenericControl o_My_Control = New HtmlGenericControl();
It automatically returns a开发者_运维百科 span element. I need an UserControl because i must add this control into an another usercontrol Control.Add(o_My_Control) and i need to directly append html. I use o_My_Control.innerHTML.
Can you help me to find solution ?
A HtmlGenericControl is a control used to represent an HTML element and thus it has to have a name. You can either provide one or if you don't it uses the default value of "span".
If you have some text you want to put into the page directly then you might want to look at the literalControl ( http://msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol.aspx ). This control is designed to be used for "HTML elements, text, and any other strings in an ASP.NET page that do not require processing on the server".
So you could just do
myUserControl.Controls.Add(new LiteralControl(myHTMLstring));
And avoid needing to use the innerHTML at all.
A span element is automatically returned because all server controls are surrounded with span tags. There are several ways to go about removing these tags, but if you are able to write a custom control and then override the "RenderBeginTag" and "RenderEndTag" methods, you can solve the issue that way.
See http://weblogs.asp.net/gunnarpeipman/archive/2009/04/09/removing-span-tags-around-server-control.aspx for info on using this method to solve the problem.
Hope that helps.
精彩评论