473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

asp:Literal & <!--includes-->

Hi,

VS.NET 2003 on WinXPPro + all latest service packs etc.

I have a totally standard WebForm wherein I need to include one of several
HTML files according to various parameters etc.

I'm trying to use an <asp:Literal /> control for this, and intend to modify
its Text property in the Page_Load event, but it's not working. The code I'm
using is as follows:

<table>
<tr>
<td>
<asp:Literal ID=litText Runat=server Text='<!--#include
file="history.htm"-->' />
</td>
</tr>
</table>

However, although the include appears to be correctly written out when I do
a View Source on the page, its contents are not displayed. If I hardcode the
include, it works perfectly, as follows:

<table>
<tr>
<td>
<!--#include file="history.htm"-->'
</td>
</tr>
</table>

Any assistance gratefully appreciated.

Best,

Mark Rae
Nov 18 '05 #1
4 1938
Including cannot assign value to control property that way. Try it this way:

<asp:Literal ID=litText Runat=server >
<!--#include file="history.htm"-->
</asp:Literal>

E.g put the include part inside the Literal's tag

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Hi,

VS.NET 2003 on WinXPPro + all latest service packs etc.

I have a totally standard WebForm wherein I need to include one of several
HTML files according to various parameters etc.

I'm trying to use an <asp:Literal /> control for this, and intend to modify its Text property in the Page_Load event, but it's not working. The code I'm using is as follows:

<table>
<tr>
<td>
<asp:Literal ID=litText Runat=server Text='<!--#include
file="history.htm"-->' />
</td>
</tr>
</table>

However, although the include appears to be correctly written out when I do a View Source on the page, its contents are not displayed. If I hardcode the include, it works perfectly, as follows:

<table>
<tr>
<td>
<!--#include file="history.htm"-->'
</td>
</tr>
</table>

Any assistance gratefully appreciated.

Best,

Mark Rae

Nov 18 '05 #2
The contents of the string Literal is not processed by ASP.NET and so the
control is simply rendered to the page in its literal text form.

As the #include is a server side directive the string on its own is useless
once it reaches the client. Try reading the contents of history.htm and
then using the literal control to output that to the client.

MattC

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:#z**************@TK2MSFTNGP10.phx.gbl...
Hi,

VS.NET 2003 on WinXPPro + all latest service packs etc.

I have a totally standard WebForm wherein I need to include one of several
HTML files according to various parameters etc.

I'm trying to use an <asp:Literal /> control for this, and intend to modify its Text property in the Page_Load event, but it's not working. The code I'm using is as follows:

<table>
<tr>
<td>
<asp:Literal ID=litText Runat=server Text='<!--#include
file="history.htm"-->' />
</td>
</tr>
</table>

However, although the include appears to be correctly written out when I do a View Source on the page, its contents are not displayed. If I hardcode the include, it works perfectly, as follows:

<table>
<tr>
<td>
<!--#include file="history.htm"-->'
</td>
</tr>
</table>

Any assistance gratefully appreciated.

Best,

Mark Rae

Nov 18 '05 #3
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
Including cannot assign value to control property that way. Try it this way:
<asp:Literal ID=litText Runat=server >
<!--#include file="history.htm"-->
</asp:Literal>

E.g put the include part inside the Literal's tag


Thanks very much! That solves the problem if I hardcode the reference to the
include file. However, I still need to change it in the Page_Load event.
I've tried the following with no success:

protected Literal litText;

private void Page_Load(object sender, System.EventArgs e)
{
litText.Text = "<!--#include file=\"history.htm\"-->";
}

As before, that causes the include to appear in View Source, but doesn't
write it out to the browser. It's almost like I need an InnerHTML
property...

Regards,

Mark
Nov 18 '05 #4
"MattC" <m@m.com> wrote in message
news:OS*************@tk2msftngp13.phx.gbl...

Matt,
The contents of the string Literal is not processed by ASP.NET and so the
control is simply rendered to the page in its literal text form.

As the #include is a server side directive the string on its own is useless once it reaches the client. Try reading the contents of history.htm and
then using the literal control to output that to the client.


Excellent advice! I did:

StreamReader objStreamReader = File.OpenText(strIncludeFile);
litText.Text = objStreamReader.ReadToEnd();
objStreamReader.Close();

where strIncludeFile is a fully-qualified filespec which I set in code, and
that worked perfectly.

Thanks a lot.

Mark
Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Collin VanDyck | last post by:
I have a basic understanding of this, so forgive me if I am overly simplistic in my explanation of my problem.. I am trying to get a Java/Xalan transform to pass through a numeric character...
1
by: DrTebi | last post by:
Hello, I have the following problem: I used to "encode" my email address within links, in order to avoid (most) email spiders. So I had a link like this: <a...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.