include static text in <script>

  • Thread starter Thread starter Howard
  • Start date Start date
H

Howard

Hello

I need some help with this. I want to assign the content of a static
txt/html file to my string a.

<script runat="server" language="C#">
private void Page_Load(object sender, System.EventArgs e)
{
string a =
//include static html page welcome.htm
}
</script>


should i make welcome.htm a user control?
or use StreamReader?

Howard
 
If you want to assign the file content to a variable (for any manipulation
perhaps) then use StreamReader. However, if the file is a reusable content
(to show across pages) then go for user control.

Hope I got your question right.

Hello

I need some help with this. I want to assign the content of a static
txt/html file to my string a.

<script runat="server" language="C#">
private void Page_Load(object sender, System.EventArgs e)
{
string a =
//include static html page welcome.htm
}
</script>


should i make welcome.htm a user control?
or use StreamReader?

Howard
 
: I need some help with this. I want to assign the content of a static
: txt/html file to my string a.

What's the objective? Do you want to work with the content later on or just want to use for display?

If you just want to display the content, you may like to use the "include" ... <!--#include file="welcome.htm"-->

http://samples.gotdotnet.com/quickstart/aspplus/doc/webformssyntaxref.aspx

Loading as a control (ascx, UserControl) will be beneficial if you want to have some functionality in the page (server side controls).

HTH
 
It's just static text no functionality. i cannot use #inlucde here because
it's in <script>
the reason i need to include a static text/html page it's because i don't
want to escape all the characters in the html, it has some javascript it's
very hard and cumbersome

instead of

string a = "<input type=\"text\">";

i want
string a = plain html here;

actually it doesn't have to be a seperate file, any method that would allow
me to use unmodified plain html in <script runat="server"> is fine

Thanks


message : I need some help with this. I want to assign the content of a static
: txt/html file to my string a.

What's the objective? Do you want to work with the content later on or
just want to use for display?

If you just want to display the content, you may like to use the
"include" ... <!--#include file="welcome.htm"-->

http://samples.gotdotnet.com/quickstart/aspplus/doc/webformssyntaxref.aspx

Loading as a control (ascx, UserControl) will be beneficial if you want
to have some functionality in the page (server side controls).

HTH
 
: the reason i need to include a static text/html page it's because i don't
: want to escape all the characters in the html, it has some javascript it's
: very hard and cumbersome

Let me rephrase the question.

Do you want to process the text of the html file? Why do you want to store
it in a string?
 
:I use Response.Write(a); later on in the script so it has to be stored in a
: string.

And exactly at that point, instead of doing "Response.Write(str)", just
do:

<!--#include file="main.htm"-->

You don't need to do all the headache of loading it in a string and then
emitting it out...
 
I see what youre saying. but I forgot to mention that string a is not the
final output in response.write. I cannot use this method

string a = \\static text
string b = "something";
string c = "something";

string output = b + a + c;
Response.Write(output);

So theres no way around this? I hate to escape all those lines.
 
not sure , if i have understood the requirement well..
string output = b + a + c;
Response.Write(output);

above 2 lines are eaqual to

Response.Write(b)
<!--#include file="main.htm"-->
Response.Write(c)




Howard said:
I see what youre saying. but I forgot to mention that string a is not the
final output in response.write. I cannot use this method

string a = \\static text
string b = "something";
string c = "something";

string output = b + a + c;
Response.Write(output);

So theres no way around this? I hate to escape all those lines.
 
This will work if all you want to do is append text without any HTML
garbage surrounding it:

var a = "<asp:literal id=litWhatEver runat=server/>";


Then in your codebehind:
litWhatEver.Text = @"<input type='text'>";


This will render as:
var a = "<input type='text'>";


Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 
Back
Top