473,324 Members | 2,313 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,324 software developers and data experts.

Setting Text In Javascript

I have a web page which uses some javascript. It has a variable which
contains text which I want to retrieve from a file. I have no real knowldege
of javascript so I was looking for a way to get this javascript to read and
text file for the information.

Can I use ASP.Net to set the variable value for the javascript? Or is there
an easier way?
Apr 25 '07 #1
4 1603
Hi Jim,

You didn't mention whether the file is server-side or client-side, but I'll
assume server-side. JavaScript cannot read server-side files, although Ajax
can, which uses JavaScript. However, I don't think that's necessary, unless
the file needs to be read AFTER the page is sent to the client. So, I would
use ASP.Net server-side to read the file and inject the text into the page
(possibly inside the JavaScript).

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"JimHeavey" <Ji*******@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
>I have a web page which uses some javascript. It has a variable which
contains text which I want to retrieve from a file. I have no real
knowldege
of javascript so I was looking for a way to get this javascript to read
and
text file for the information.

Can I use ASP.Net to set the variable value for the javascript? Or is
there
an easier way?

Apr 25 '07 #2
Thanks Kevin.

Yes, it is a server side file.

I was not quite sure how to "inject" the text into the page.

So I open up a reader and read all the text into variable XX. Now how do I
set the javascript variable FF to the value which I have in XX? That was the
real point of my confusion, although you did confirm that javascript will not
read server side files.
Apr 25 '07 #3
the easiest is to put the text into a hidden field.

<script runat=server>
Page.ClientScript.RegisterHiddenField("fileText",g etFileText());
</script>
<script>
alert(document.getElementById('fileText').value);
</script>
-- bruce (sqlwork.com)

JimHeavey wrote:
Thanks Kevin.

Yes, it is a server side file.

I was not quite sure how to "inject" the text into the page.

So I open up a reader and read all the text into variable XX. Now how do I
set the javascript variable FF to the value which I have in XX? That was the
real point of my confusion, although you did confirm that javascript will not
read server side files.

Apr 25 '07 #4
You can also insert it into a block of JavaScript which is added to the page
using RegisterClientScriptBlock, etc. Or, you can put a LiteralControl into
the hard-coded JavaScript in a Page (if you have hard-coded JavaScript in
the Page_, and set the Text property of the LiteralControl.

The most dynamic but difficult method is to create an HttpHandler to handle
requests for .js files, have the HttpHandler dynamically generate the .js
file, and reference it as an external script in the Page. This is almost
never necessary, and because it is complicated, should be avoided if not
necessary.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"bruce barker" <no****@nospam.comwrote in message
news:eC**************@TK2MSFTNGP03.phx.gbl...
the easiest is to put the text into a hidden field.

<script runat=server>
Page.ClientScript.RegisterHiddenField("fileText",g etFileText());
</script>
<script>
alert(document.getElementById('fileText').value);
</script>
-- bruce (sqlwork.com)

JimHeavey wrote:
>Thanks Kevin.

Yes, it is a server side file.

I was not quite sure how to "inject" the text into the page.

So I open up a reader and read all the text into variable XX. Now how do
I set the javascript variable FF to the value which I have in XX? That
was the real point of my confusion, although you did confirm that
javascript will not read server side files.
Apr 25 '07 #5

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

Similar topics

1
by: relaxedrob | last post by:
Howdy All! I am really stuck with this one - I want to completely create a table within JavaScript and insert it into the document, with onMouseOut and onMouseOver handlers in the table rows. ...
2
by: - | last post by:
Hi there All, Don't know if this is possible at all, but here goes. I've got a page (an active server page if that makes any difference), that is pulling some sticky content from...
12
by: daniel kaplan | last post by:
Hi All, Been learning Javascript (via google) to create forms with pre-set values. As seen below. My problem I have found is this: I can't seem to figure out (or find so far via google) how to...
3
by: Bob | last post by:
I'm a total newbie at Javascript, but a programmer for over 20 years... so, my plans may be bigger than they are possible. I'm trying to set with Javascript the value of a form field... easy...
2
by: foldface | last post by:
Hi Pardon the vague-ness, I mean the ?name=value stuff in the URL. Can you set this within javascript on a page such that when an asp.net button is clicked then these values are passed as params?...
5
by: jose1lm | last post by:
What is supposed to happen: A user enters data into one of the FORM input selections. When the user submits the form, the onclick event is supposed to go to a function that will set another FORM...
1
by: ton | last post by:
Hi, I'm using Ajax to seach direct in a gridview. It works fine. I even keep the focus on the input text box. Here is my code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As...
7
by: ThePope78705 | last post by:
Hi all, I have a web form that is generated on the fly. I need to insert some javascript into the form to do validation on the contents of each text box when the text box loses focus. here is what I...
3
by: Annette Block | last post by:
I'm rather new in JavaScript, but I have some experience in php. I learned it's rather easy to open a window of a specified size with JavaScript, that you need to specify the opened file, but I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: 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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.