Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

include static text in <script>

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard - 30 Oct 2005 11:01 GMT
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
Siva M - 30 Oct 2005 11:12 GMT
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
Gaurav Vaish - 30 Oct 2005 11:17 GMT
: 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

--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
Howard - 30 Oct 2005 19:01 GMT
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

: 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

--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
Gaurav Vaish - 30 Oct 2005 19:20 GMT
: 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
-----------------------
Howard - 30 Oct 2005 19:38 GMT
I use Response.Write(a); later on in the script so it has to be stored in a
string.

>: 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
[quoted text clipped - 11 lines]
> http://mastergaurav.org
> -----------------------
Gaurav Vaish - 30 Oct 2005 20:34 GMT
: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
-----------------------------
Howard - 30 Oct 2005 21:44 GMT
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.

> :I use Response.Write(a); later on in the script so it has to be stored in
> a
[quoted text clipped - 14 lines]
> http://mastergaurav.org
> -----------------------------
Sreejith Ram - 31 Oct 2005 17:10 GMT
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)

> 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
[quoted text clipped - 26 lines]
> > http://mastergaurav.org
> > -----------------------------
Jason Kester - 31 Oct 2005 19:40 GMT
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/

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.