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

run js on server?

Can I (and how) run a javascript in the code behind on the server and then
send the results of the script to the aspx page. Thereby rendering the
content regardless of the clients javascript support.

--
David Bartosik - Microsoft MVP
Visit www.davidbartosik.com
for Publisher and Web Design
Tips and How-to's.
Nov 17 '05 #1
4 1730
David,

What is the script supposed to do?

Some of the details of what you are attempting to do server side would help
to solve your problem.

The short answer is no, you can't run a javascript on the server. However,
there is probably a way to do whatever you need.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"David Bartosik - MS MVP" <db*******@mvps.org> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
Can I (and how) run a javascript in the code behind on the server and then
send the results of the script to the aspx page. Thereby rendering the
content regardless of the clients javascript support.

--
David Bartosik - Microsoft MVP
Visit www.davidbartosik.com
for Publisher and Web Design
Tips and How-to's.

Nov 17 '05 #2

On my site I have some content that is delivered via a js file, for example
the page http://www.davidbartosik.com/webdesign.htm runs the following
script :
<script language="JavaScript"
src="http://www.web-source.net/content/website.js"></script>
- the js file contains the html for the browser to render.
This scenario of course is dependant on client support.
I'm wondering if I can run this server side to get the html and then send
the actual html to the client (like to a label control).

--
David Bartosik - Microsoft MVP
Visit www.davidbartosik.com
for Publisher and Web Design
Tips and How-to's.

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
David,

What is the script supposed to do?

Some of the details of what you are attempting to do server side would help to solve your problem.

The short answer is no, you can't run a javascript on the server. However,
there is probably a way to do whatever you need.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"David Bartosik - MS MVP" <db*******@mvps.org> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
Can I (and how) run a javascript in the code behind on the server and then send the results of the script to the aspx page. Thereby rendering the
content regardless of the clients javascript support.

--
David Bartosik - Microsoft MVP
Visit www.davidbartosik.com
for Publisher and Web Design
Tips and How-to's.


Nov 17 '05 #3
David,

You could make a request for the page from server side and get the html
response in a string.

It would be something like this:

(Copy and paste the code below to the code behind file of a page named
defaults.aspx)

Imports System.IO

Imports System.Net

Imports System.Text

Public Class _default

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim WebRequest As System.Net.WebRequest =
CType(System.Net.WebRequest.Create(New Uri("http://www.gotdotnet.com")),
System.Net.HttpWebRequest)

' Send the 'WebRequest' and wait for response.

Dim WebResponse As WebResponse = WebRequest.GetResponse()

' Call method 'GetResponseStream' to obtain stream associated with the
response object

Dim ReceiveStream As Stream = WebResponse.GetResponseStream()

Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")

' Pipe the stream to a higher level stream reader with the required encoding
format.

Dim readStream As New StreamReader(ReceiveStream, encode)

Response.Write("Response stream received")

Dim read(256) As [Char]

' Read 256 charcters at a time .

Dim count As Integer = readStream.Read(read, 0, 256)

Response.Write("HTML..." + ControlChars.Lf + ControlChars.Cr)

While count > 0

' Dump the 256 characters on a string and display the string onto the
console.

Dim str As New [String](read, 0, count)

Response.Write(str)

count = readStream.Read(read, 0, 256)

End While

' Release the resources of stream object.

readStream.Close()

' Release the resources of response object.

WebResponse.Close()

End Sub

End Class

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"David Bartosik - MS MVP" <db*******@mvps.org> wrote in message
news:OS*************@TK2MSFTNGP12.phx.gbl...

On my site I have some content that is delivered via a js file, for example the page http://www.davidbartosik.com/webdesign.htm runs the following
script :
<script language="JavaScript"
src="http://www.web-source.net/content/website.js"></script>
- the js file contains the html for the browser to render.
This scenario of course is dependant on client support.
I'm wondering if I can run this server side to get the html and then send
the actual html to the client (like to a label control).

--
David Bartosik - Microsoft MVP
Visit www.davidbartosik.com
for Publisher and Web Design
Tips and How-to's.

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
David,

What is the script supposed to do?

Some of the details of what you are attempting to do server side would

help
to solve your problem.

The short answer is no, you can't run a javascript on the server. However,
there is probably a way to do whatever you need.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"David Bartosik - MS MVP" <db*******@mvps.org> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
Can I (and how) run a javascript in the code behind on the server and

then send the results of the script to the aspx page. Thereby rendering the
content regardless of the clients javascript support.

--
David Bartosik - Microsoft MVP
Visit www.davidbartosik.com
for Publisher and Web Design
Tips and How-to's.



Nov 17 '05 #4
David,

This is how you'd do it if the files aren't accessible through the file
system.

You could also use the File system object to access the files directly
without the overhead of making http calls.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
David,

You could make a request for the page from server side and get the html
response in a string.

It would be something like this:

(Copy and paste the code below to the code behind file of a page named
defaults.aspx)

Imports System.IO

Imports System.Net

Imports System.Text

Public Class _default

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim WebRequest As System.Net.WebRequest =
CType(System.Net.WebRequest.Create(New Uri("http://www.gotdotnet.com")),
System.Net.HttpWebRequest)

' Send the 'WebRequest' and wait for response.

Dim WebResponse As WebResponse = WebRequest.GetResponse()

' Call method 'GetResponseStream' to obtain stream associated with the
response object

Dim ReceiveStream As Stream = WebResponse.GetResponseStream()

Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")

' Pipe the stream to a higher level stream reader with the required encoding format.

Dim readStream As New StreamReader(ReceiveStream, encode)

Response.Write("Response stream received")

Dim read(256) As [Char]

' Read 256 charcters at a time .

Dim count As Integer = readStream.Read(read, 0, 256)

Response.Write("HTML..." + ControlChars.Lf + ControlChars.Cr)

While count > 0

' Dump the 256 characters on a string and display the string onto the
console.

Dim str As New [String](read, 0, count)

Response.Write(str)

count = readStream.Read(read, 0, 256)

End While

' Release the resources of stream object.

readStream.Close()

' Release the resources of response object.

WebResponse.Close()

End Sub

End Class

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"David Bartosik - MS MVP" <db*******@mvps.org> wrote in message
news:OS*************@TK2MSFTNGP12.phx.gbl...

On my site I have some content that is delivered via a js file, for

example
the page http://www.davidbartosik.com/webdesign.htm runs the following
script :
<script language="JavaScript"
src="http://www.web-source.net/content/website.js"></script>
- the js file contains the html for the browser to render.
This scenario of course is dependant on client support.
I'm wondering if I can run this server side to get the html and then send
the actual html to the client (like to a label control).

--
David Bartosik - Microsoft MVP
Visit www.davidbartosik.com
for Publisher and Web Design
Tips and How-to's.

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
David,

What is the script supposed to do?

Some of the details of what you are attempting to do server side would

help
to solve your problem.

The short answer is no, you can't run a javascript on the server. However, there is probably a way to do whatever you need.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"David Bartosik - MS MVP" <db*******@mvps.org> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
> Can I (and how) run a javascript in the code behind on the server and then
> send the results of the script to the aspx page. Thereby rendering

the > content regardless of the clients javascript support.
>
> --
> David Bartosik - Microsoft MVP
> Visit www.davidbartosik.com
> for Publisher and Web Design
> Tips and How-to's.
>
>



Nov 17 '05 #5

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

Similar topics

2
by: Phil | last post by:
I am using a Pascal like language (Wealth-Lab) on W2K and call this server: class HelloWorld: _reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}" _reg_desc_ = "Python Test COM Server"...
6
by: Nathan Sokalski | last post by:
I want to set up SQL Server on Windows XP Pro so that I can use the database capabilities of ASP and IIS. I am probably using some incorrect settings, but I am not sure what they are. Here is what...
9
by: Grim Reaper | last post by:
My work let me put SQL Server 7.0 Enterprise Edition on my laptop. I have never setup a server from the beginning, so I am a little new at creating server groups. Alright, I am trying to create...
0
by: Chris Halcrow | last post by:
Hi I've spent ALL DAY trying to re-install SQL Server 2000 on Windows XP. I continually get the error 'cannot configure server' just at the end of the installation. I've tried the following: ...
0
by: Zorba.GR | last post by:
IBM DB2 Connect Enterprise Edition v8.2, other IBM DB2 (32 bit, 64 bit) (MULTiOS, Windows, Linux, Solaris), IBM iSoft Commerce Suite Server Enterprise v3.2.01, IBM Tivoli Storage Resource Manager...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
14
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.