ASP.Net Page that has a control to display HTML

D

David Elliott

I need a control on a Web Page that can accept an HTML Document and will display it.

Any help would be appreciated.

Thanks,
Dave


Here is what I was trying...


protected System.Web.UI.WebControls.Panel htmlPanel;
protected System.Web.UI.WebControls.Image htmlImage;


htmlString = @"ImageFeed.aspx?docId=" + docID;

htmlPanel.BackImageUrl = htmlString;

htmlImage.ImageUrl = htmlString;
htmlImage.Visible = true;



public class ImageFeed : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string htmlData = @"<html><body><h3>Hello World</h3></body></html>";
Response.Write(htmlData);
}
}
 
M

Martin Dechev

Hi, David Elliott,

How about an iframe? In the class you can declare it as
System.Web.UI.HtmlControls.HtmlGenericControl, just don't forget the
runat="server" attribute in the .aspx. You can set the attributes (src,
width, height, border, etc) from the property Attributes, i.e.
iframe1.Attributes["src"] = "somepage.aspx";

Greetings
Martin
 
G

Guest

Use the WebControls.Literal control

Set the Literal.Text property to store the HTML content

HTH
Tim Stal

----- David Elliott wrote: ----

I need a control on a Web Page that can accept an HTML Document and will display it

Any help would be appreciated

Thanks
Dav


Here is what I was trying..


protected System.Web.UI.WebControls.Panel htmlPanel
protected System.Web.UI.WebControls.Image htmlImage


htmlString = @"ImageFeed.aspx?docId=" + docID

htmlPanel.BackImageUrl = htmlString

htmlImage.ImageUrl = htmlString
htmlImage.Visible = true



public class ImageFeed : System.Web.UI.Pag

private void Page_Load(object sender, System.EventArgs e

string htmlData = @"<html><body><h3>Hello World</h3></body></html>"
Response.Write(htmlData)
 
D

David Elliott

I added <iframe id=extText runat=server></iframe> to my ASPX page and defined
protected System.Web.UI.HtmlControls.HtmlGenericControl extText;

htmlString = @"ImageFeed.aspx?docId=" + docID;
extText.Attributes["src"] = htmlString;

If I have ImageFeed defined to return:
dataString = @"<html><body><h1>hello world 12</h1></body></html>";
Response.Write(dataString);
Response.Flush();
Response.Close();

Everything works fine.

=======================

If I cache a file
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] data = new byte [fs.Length];
fs.Read(data, 0, (int)fs.Length);
fs.Close();

and have ImageFeed defined to return
data = (byte[])document;
string dataString = Encoding.UTF8.GetString(data);

Response.Write(dataString);
Response.Flush();
Response.Close();

This doesn't work. Using the debugger, I verified that dataString has the correct information (i.e. the HTML)

If I view the source it returns some generated text from who knows where. Isn't anything like what I am trying
to load. It looks like this.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ImageFeed</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="ImageFeed.aspx?r0=1077912660" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDwtMTI3OTMzNDM4NDs7Ppf+ZVIuJLGxTqy+PZFowk7vf36y" />

</form>
</body>
</HTML>


Any help would be appreciated.

Thanks,
Dave





Hi, David Elliott,

How about an iframe? In the class you can declare it as
System.Web.UI.HtmlControls.HtmlGenericControl, just don't forget the
runat="server" attribute in the .aspx. You can set the attributes (src,
width, height, border, etc) from the property Attributes, i.e.
iframe1.Attributes["src"] = "somepage.aspx";

Greetings
Martin
David Elliott said:
I need a control on a Web Page that can accept an HTML Document and will display it.

Any help would be appreciated.

Thanks,
Dave


Here is what I was trying...


protected System.Web.UI.WebControls.Panel htmlPanel;
protected System.Web.UI.WebControls.Image htmlImage;


htmlString = @"ImageFeed.aspx?docId=" + docID;

htmlPanel.BackImageUrl = htmlString;

htmlImage.ImageUrl = htmlString;
htmlImage.Visible = true;



public class ImageFeed : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string htmlData = @"<html><body><h3>Hello World</h3></body></html>";
Response.Write(htmlData);
}
}
 
M

Martin Dechev

Hi, David Elliott,

Are you sure that you are not viewing a cached version of the page? Delete
your temp. files in the IE. If you are running Windows Server (IIS 6.0) you
might need to restart the w3svc service because there is some bizzare
caching which is not documented but many people are experiencing it.

Also, call Response.End() instead of Response.Close()

Greetings
Martin
David Elliott said:
I added <iframe id=extText runat=server></iframe> to my ASPX page and defined
protected System.Web.UI.HtmlControls.HtmlGenericControl extText;

htmlString = @"ImageFeed.aspx?docId=" + docID;
extText.Attributes["src"] = htmlString;

If I have ImageFeed defined to return:
dataString = @"<html><body><h1>hello world 12</h1></body></html>";
Response.Write(dataString);
Response.Flush();
Response.Close();

Everything works fine.

=======================

If I cache a file
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] data = new byte [fs.Length];
fs.Read(data, 0, (int)fs.Length);
fs.Close();

and have ImageFeed defined to return
data = (byte[])document;
string dataString = Encoding.UTF8.GetString(data);

Response.Write(dataString);
Response.Flush();
Response.Close();

This doesn't work. Using the debugger, I verified that dataString has the
correct information (i.e. the HTML)
If I view the source it returns some generated text from who knows where.
Isn't anything like what I am trying
to load. It looks like this.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ImageFeed</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="ImageFeed.aspx?r0=1077912660" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Ppf+ZVIuJLGxTqy+PZFowk7vf36y" />
</form>
</body>
</HTML>


Any help would be appreciated.

Thanks,
Dave





Hi, David Elliott,

How about an iframe? In the class you can declare it as
System.Web.UI.HtmlControls.HtmlGenericControl, just don't forget the
runat="server" attribute in the .aspx. You can set the attributes (src,
width, height, border, etc) from the property Attributes, i.e.
iframe1.Attributes["src"] = "somepage.aspx";

Greetings
Martin
David Elliott said:
I need a control on a Web Page that can accept an HTML Document and
will
display it.
Any help would be appreciated.

Thanks,
Dave


Here is what I was trying...


protected System.Web.UI.WebControls.Panel htmlPanel;
protected System.Web.UI.WebControls.Image htmlImage;


htmlString = @"ImageFeed.aspx?docId=" + docID;

htmlPanel.BackImageUrl = htmlString;

htmlImage.ImageUrl = htmlString;
htmlImage.Visible = true;



public class ImageFeed : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string htmlData = @"<html><body><h3>Hello World</h3></body></html>";
Response.Write(htmlData);
}
}
 
D

David Elliott

I changed from Close() to End() as suggested and it throws an exception:
ex.Message "Thread was being aborted.". I was using a simple hard coded
string " <html><body><h1>This is some text</h1></body></html>"

The failure to display the HTML, I believe it has something to do with the data
contained inside of the HTML file. If I create a file using the string above, the
output is displayed correctly. Upon viewing the source, it is identical to the
file on disk. No additional headers or information.

The data file I had been using for testing purposes was the Yahoo.com main page.
I just saved it to disk and then read it into a byte[] (see previous message below)
and then do the write. Using this yahoo.htm file instead of the simple html file, I get
nothing displayed. When I view the source code, the following is displayed which
doesn't look like the Yahoo.com file on disk..


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ImageFeed</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="ImageFeed.aspx?r0=1077912660"
id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Ppf+ZVIuJLGxTqy+PZFowk7vf36y" />

</form>
</body>
</HTML>



Cheers,
Dave



Hi, David Elliott,

Are you sure that you are not viewing a cached version of the page? Delete
your temp. files in the IE. If you are running Windows Server (IIS 6.0) you
might need to restart the w3svc service because there is some bizzare
caching which is not documented but many people are experiencing it.

Also, call Response.End() instead of Response.Close()

Greetings
Martin
David Elliott said:
I added <iframe id=extText runat=server></iframe> to my ASPX page and defined
protected System.Web.UI.HtmlControls.HtmlGenericControl extText;

htmlString = @"ImageFeed.aspx?docId=" + docID;
extText.Attributes["src"] = htmlString;

If I have ImageFeed defined to return:
dataString = @"<html><body><h1>hello world 12</h1></body></html>";
Response.Write(dataString);
Response.Flush();
Response.Close();

Everything works fine.

=======================

If I cache a file
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] data = new byte [fs.Length];
fs.Read(data, 0, (int)fs.Length);
fs.Close();

and have ImageFeed defined to return
data = (byte[])document;
string dataString = Encoding.UTF8.GetString(data);

Response.Write(dataString);
Response.Flush();
Response.Close();

This doesn't work. Using the debugger, I verified that dataString has the
correct information (i.e. the HTML)
If I view the source it returns some generated text from who knows where.
Isn't anything like what I am trying
to load. It looks like this.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ImageFeed</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="ImageFeed.aspx?r0=1077912660" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Ppf+ZVIuJLGxTqy+PZFowk7vf36y" />
</form>
</body>
</HTML>


Any help would be appreciated.

Thanks,
Dave





Hi, David Elliott,

How about an iframe? In the class you can declare it as
System.Web.UI.HtmlControls.HtmlGenericControl, just don't forget the
runat="server" attribute in the .aspx. You can set the attributes (src,
width, height, border, etc) from the property Attributes, i.e.
iframe1.Attributes["src"] = "somepage.aspx";

Greetings
Martin
I need a control on a Web Page that can accept an HTML Document and will
display it.

Any help would be appreciated.

Thanks,
Dave


Here is what I was trying...


protected System.Web.UI.WebControls.Panel htmlPanel;
protected System.Web.UI.WebControls.Image htmlImage;


htmlString = @"ImageFeed.aspx?docId=" + docID;

htmlPanel.BackImageUrl = htmlString;

htmlImage.ImageUrl = htmlString;
htmlImage.Visible = true;



public class ImageFeed : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string htmlData = @"<html><body><h3>Hello World</h3></body></html>";
Response.Write(htmlData);
}
}
 
D

David Elliott

I got it.

It turns out that loading the page into my application was fine. The problem was that
the page was loading a cookie to automatically log me into my Yahoo account. It was
then posting back to my ASPX page to display which is what the r0=.... number is below.
Once I logged out of Yahoo the page displayed successfully.

I still don't know about using End().

Thanks all for the help.

Cheers,
Dave


I changed from Close() to End() as suggested and it throws an exception:
ex.Message "Thread was being aborted.". I was using a simple hard coded
string " <html><body><h1>This is some text</h1></body></html>"

The failure to display the HTML, I believe it has something to do with the data
contained inside of the HTML file. If I create a file using the string above, the
output is displayed correctly. Upon viewing the source, it is identical to the
file on disk. No additional headers or information.

The data file I had been using for testing purposes was the Yahoo.com main page.
I just saved it to disk and then read it into a byte[] (see previous message below)
and then do the write. Using this yahoo.htm file instead of the simple html file, I get
nothing displayed. When I view the source code, the following is displayed which
doesn't look like the Yahoo.com file on disk..


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ImageFeed</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="ImageFeed.aspx?r0=1077912660"
id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Ppf+ZVIuJLGxTqy+PZFowk7vf36y" />

</form>
</body>
</HTML>



Cheers,
Dave



Hi, David Elliott,

Are you sure that you are not viewing a cached version of the page? Delete
your temp. files in the IE. If you are running Windows Server (IIS 6.0) you
might need to restart the w3svc service because there is some bizzare
caching which is not documented but many people are experiencing it.

Also, call Response.End() instead of Response.Close()

Greetings
Martin
David Elliott said:
I added <iframe id=extText runat=server></iframe> to my ASPX page and defined
protected System.Web.UI.HtmlControls.HtmlGenericControl extText;

htmlString = @"ImageFeed.aspx?docId=" + docID;
extText.Attributes["src"] = htmlString;

If I have ImageFeed defined to return:
dataString = @"<html><body><h1>hello world 12</h1></body></html>";
Response.Write(dataString);
Response.Flush();
Response.Close();

Everything works fine.

=======================

If I cache a file
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] data = new byte [fs.Length];
fs.Read(data, 0, (int)fs.Length);
fs.Close();

and have ImageFeed defined to return
data = (byte[])document;
string dataString = Encoding.UTF8.GetString(data);

Response.Write(dataString);
Response.Flush();
Response.Close();

This doesn't work. Using the debugger, I verified that dataString has the
correct information (i.e. the HTML)
If I view the source it returns some generated text from who knows where.
Isn't anything like what I am trying
to load. It looks like this.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ImageFeed</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="ImageFeed.aspx?r0=1077912660" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Ppf+ZVIuJLGxTqy+PZFowk7vf36y" />
</form>
</body>
</HTML>


Any help would be appreciated.

Thanks,
Dave





Hi, David Elliott,

How about an iframe? In the class you can declare it as
System.Web.UI.HtmlControls.HtmlGenericControl, just don't forget the
runat="server" attribute in the .aspx. You can set the attributes (src,
width, height, border, etc) from the property Attributes, i.e.
iframe1.Attributes["src"] = "somepage.aspx";

Greetings
Martin
I need a control on a Web Page that can accept an HTML Document and will
display it.

Any help would be appreciated.

Thanks,
Dave


Here is what I was trying...


protected System.Web.UI.WebControls.Panel htmlPanel;
protected System.Web.UI.WebControls.Image htmlImage;


htmlString = @"ImageFeed.aspx?docId=" + docID;

htmlPanel.BackImageUrl = htmlString;

htmlImage.ImageUrl = htmlString;
htmlImage.Visible = true;



public class ImageFeed : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string htmlData = @"<html><body><h3>Hello World</h3></body></html>";
Response.Write(htmlData);
}
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top