display actual HTML in text box

  • Thread starter Thread starter Adie
  • Start date Start date
A

Adie

I'm actually trying render usercontrols dynamicaly fraom a name stored
in a db, but am have problems. My debugging attempts involve trying to
write the contents of the .aspx to a label, but this is just giving me
the text and actually rendering the html, I just want the raw code.


void someMethod()
{
string ucstring = "";
blah.GenericData gd = new GenericData(); // my own data class
SqlDataReader dr;
dr = gd.getByString
(@"select Category_Spec
from Categories
where Category_Name = 'End Caps'");

while(dr.Read())
{
ucstring = dr.GetSqlValue(0).ToString();
}

StreamReader sr = new StreamReader
(@"C:\Inetpub\wwwroot\blah\pecs\" + ucstring);

s = sr.ReadToEnd();
Literal1.Text = s; // should render HTML tags as well??
}

Anyone have the answer to this one?
 
I'm actually trying render usercontrols dynamicaly fraom a name stored
in a db, but am have problems. My debugging attempts involve trying to
write the contents of the .aspx to a label, but this is just giving me
the text and actually rendering the html, I just want the raw code.

void someMethod()
{
string ucstring = "";
blah.GenericData gd = new GenericData(); // my own data class
SqlDataReader dr;
dr = gd.getByString
(@"select Category_Spec
from Categories
where Category_Name = 'End Caps'");

while(dr.Read())
{
ucstring = dr.GetSqlValue(0).ToString();
}

StreamReader sr = new StreamReader
(@"C:\Inetpub\wwwroot\blah\pecs\" + ucstring);

s = sr.ReadToEnd();
Literal1.Text = s; // should render HTML tags as well??
}

Anyone have the answer to this one?

One solution would be to have the content displayed in a <textarea>
block (TextBox with multiline set to true in .Net) instead of the
literal. It also looks like you do not close your DataReader (at least
not in the code you posted) which may cause some problems for you as
well.

HTH,
Tim
 
Adie wrote:

[snip]

Found the solution to displaying dynamic user controls made from any
file:

void someMethod
{
string s = "",ucstring="";
SomeOtherApp.GenericData gd = new GenericData(); //
SqlDataReader sqlDR;

// get the name of the aspx file to load from database
sqlDR = gd.getByString
(@"SELECT Category_Spec
FROM Categories
WHERE Category_Name = 'End Caps'");

while(sqlDR.Read())
{ // aspx filename to string value
ucstring =
sqlDR.GetSqlValue(0).
ToString();
}

// read the HTML contents of the file
StreamReader sr = new StreamReader
(@"C:\Inetpub\wwwroot\MainApp\pecs\" + ucstring);
s = sr.ReadToEnd()

// create control from HTML string;
Control c = ParseControl(s);
PlHdrSpecs.Controls.Add(c);
PnlSpecs.Controls.Add(PlHdrSpecs);
}

To display raw html code with tags use

Label1.Text = Server.HtmlEncode(HTMLstringToDispay);
 
Back
Top