HtmlControl or WebControl from HTML string

  • Thread starter Thread starter michael.schwarz
  • Start date Start date
M

michael.schwarz

Hello,

is it possible to get a HtmlControl from a string including the HTML
code in .NET 2.0? I was using the TemplateControl.ParseControl method
in .NET 1.1, but this is not working in the new version.

CIAO
Michael
 
Your question is confusing. First, what do you mean by "get?" Second, a
Control is a class. A string is text. So, what exactly are youre
requirements?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
Kevin Spencer said:
Your question is confusing. First, what do you mean by "get?" Second, a
Control is a class. A string is text. So, what exactly are youre
requirements?


I get a string like "<select><option value=1>One</option></select>" and
want to get a HtmlSelect control. In .NET 1.1 I used this code:


TemplateControl p = new System.Web.UI.UserControl();
Control htmlControl = p.ParseControl("<select
runat=\"server\"><option>hans</option></select>");

HtmlControl result = null;

if (htmlControl.GetType() == htmlControlType)
{
result = htmlControl as HtmlControl;
}
else
{
foreach (Control con in htmlControl.Controls)
{
if (con.GetType() == htmlControlType)
{
result = con as HtmlControl;
break;
}
}
}


In .NET 2.0 I get an exception that the property virtualPath is missing.
If I use the ParseControl method in a webform (UI.Page) it is working
correct, but I need this code in a library.

Regards,
Michael
 
The problem is that I need this feature in a library, not on a page. I
get the error ArgumentException for argument virtualPath.

CIAO
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top