By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,130 Members | 2,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,130 IT Pros & Developers. It's quick & easy.

include static text in <script>

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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.

"Howard" <ho*******@yahoo.com> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
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

Nov 22 '05 #2

P: n/a
: 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/quickst...syntaxref.aspx

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

HTH
--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org

Nov 22 '05 #3

P: n/a
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
"Gaurav Vaish" <g_***********************************@gmail.com > wrote in
message news:Om**************@tk2msftngp13.phx.gbl...
: 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/quickst...syntaxref.aspx

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

HTH
--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
Nov 22 '05 #4

P: n/a
: 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?
--
Cheers,
Gaurav Vaish
http://mastergaurav.org
-----------------------

Nov 22 '05 #5

P: n/a
I use Response.Write(a); later on in the script so it has to be stored in a
string.

"Gaurav Vaish" <g_***********************************@gmail.com > wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
: 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?
--
Cheers,
Gaurav Vaish
http://mastergaurav.org
-----------------------

Nov 22 '05 #6

P: n/a
: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...
--
Cheers,
Gaurav Vaish
http://mastergaurav.org
-----------------------------
Nov 22 '05 #7

P: n/a
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.

"Gaurav Vaish" <g_***********************************@gmail.com > wrote in
message news:e6**************@tk2msftngp13.phx.gbl...
: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...
--
Cheers,
Gaurav Vaish
http://mastergaurav.org
-----------------------------

Nov 22 '05 #8

P: n/a
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" wrote:
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.

"Gaurav Vaish" <g_***********************************@gmail.com > wrote in
message news:e6**************@tk2msftngp13.phx.gbl...
: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...
--
Cheers,
Gaurav Vaish
http://mastergaurav.org
-----------------------------


Nov 22 '05 #9

P: n/a
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/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/

Nov 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.