473,396 Members | 2,039 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.

how to call aspx variable from Javascript

I saw some web page saying I could do it this way in
javascript:
var iNumber = <%#publicvarname [or] publicpropertyname %>

but it doesn't seem to work. I have this piece of code
here in javascript:
<script language="javascript">
var sessionServer = "<%#jsTestServer%>";
alert(sessionServer);
</script>

and the variable is defined in the C# code behind:
public string jsTestServer
= "\\\\TestServer\\TestSession\\";

when I run it, alert has no message in it.
Nov 17 '05 #1
5 4328
Jade,

Assuming that variable is in scope, you would use the following:

<% = jsTestServer %>

Actually, what you should do is use RegisterClientScriptBlock to generate
your client-side script on the server and then register it on the client.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jade" <an*******@discussions.microsoft.com>
Sender: "Jade" <an*******@discussions.microsoft.com>
Subject: how to call aspx variable from Javascript
Date: Tue, 11 Nov 2003 09:30:27 -0800
Lines: 16
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOoeX8iZVlOZ5x5TzC4ue9n01Hi8w==
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:190114
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I saw some web page saying I could do it this way in
javascript:
var iNumber = <%#publicvarname [or] publicpropertyname %>

but it doesn't seem to work. I have this piece of code
here in javascript:
<script language="javascript">
var sessionServer = "<%#jsTestServer%>";
alert(sessionServer);
</script>

and the variable is defined in the C# code behind:
public string jsTestServer
= "\\\\TestServer\\TestSession\\";

when I run it, alert has no message in it.


Nov 17 '05 #2
the thing is I need to do it on the client side. I've
tried <% = jsTestServer %> before. It didn't work. It
didn't even pop up the alert this time. Or maybe I did
something wrong. Could you please give me a more
complete piece of code?

Thanks!
-----Original Message-----
Jade,

Assuming that variable is in scope, you would use the following:
<% = jsTestServer %>

Actually, what you should do is use RegisterClientScriptBlock to generateyour client-side script on the server and then register it on the client.
Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Jade" <an*******@discussions.microsoft.com>
Sender: "Jade" <an*******@discussions.microsoft.com>
Subject: how to call aspx variable from Javascript
Date: Tue, 11 Nov 2003 09:30:27 -0800
Lines: 16
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOoeX8iZVlOZ5x5TzC4ue9n01Hi8w==
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:190114NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I saw some web page saying I could do it this way in
javascript:
var iNumber = <%#publicvarname [or] publicpropertyname %


but it doesn't seem to work. I have this piece of code
here in javascript:
<script language="javascript">
var sessionServer = "<%#jsTestServer%>";
alert(sessionServer);
</script>

and the variable is defined in the C# code behind:
public string jsTestServer
= "\\\\TestServer\\TestSession\\";

when I run it, alert has no message in it.


.

Nov 17 '05 #3
Jade,

A complete source sample is not going to help you because the problem is
almost certainly that jsTestServer is out of scope. That's why using this
type of legacy architecture is not recommended in ASP.NET. Instead, you
need to use RegisterClientScriptBlock to create the client-side code on the
server and then write it to the page.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jade" <an*******@discussions.microsoft.com>
Sender: "Jade" <an*******@discussions.microsoft.com>
References: <0d****************************@phx.gbl> <hH**************@cpmsftngxa06.phx.gbl>Subject: RE: how to call aspx variable from Javascript
Date: Tue, 11 Nov 2003 10:12:37 -0800
Lines: 72
Message-ID: <02****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcOof2MGsd833c3lTq29mA5i2VBUfg==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:190128
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

the thing is I need to do it on the client side. I've
tried <% = jsTestServer %> before. It didn't work. It
didn't even pop up the alert this time. Or maybe I did
something wrong. Could you please give me a more
complete piece of code?

Thanks!
-----Original Message-----
Jade,

Assuming that variable is in scope, you would use the

following:

<% = jsTestServer %>

Actually, what you should do is use

RegisterClientScriptBlock to generate
your client-side script on the server and then register

it on the client.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and

confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jade" <an*******@discussions.microsoft.com>
Sender: "Jade" <an*******@discussions.microsoft.com>
Subject: how to call aspx variable from Javascript
Date: Tue, 11 Nov 2003 09:30:27 -0800
Lines: 16
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOoeX8iZVlOZ5x5TzC4ue9n01Hi8w==
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gblmicrosoft.public.dotnet.framework.aspnet:190114NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I saw some web page saying I could do it this way in
javascript:
var iNumber = <%#publicvarname [or] publicpropertyname %


but it doesn't seem to work. I have this piece of code
here in javascript:
<script language="javascript">
var sessionServer = "<%#jsTestServer%>";
alert(sessionServer);
</script>

and the variable is defined in the C# code behind:
public string jsTestServer
= "\\\\TestServer\\TestSession\\";

when I run it, alert has no message in it.


.


Nov 17 '05 #4
make sure you do like this
"<%=jsTestServer%>"

"Jade" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
I saw some web page saying I could do it this way in
javascript:
var iNumber = <%#publicvarname [or] publicpropertyname %>

but it doesn't seem to work. I have this piece of code
here in javascript:
<script language="javascript">
var sessionServer = "<%#jsTestServer%>";
alert(sessionServer);
</script>

and the variable is defined in the C# code behind:
public string jsTestServer
= "\\\\TestServer\\TestSession\\";

when I run it, alert has no message in it.

Nov 17 '05 #5
javascript is client side and your variable is server side......
"Jade" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
the thing is I need to do it on the client side. I've
tried <% = jsTestServer %> before. It didn't work. It
didn't even pop up the alert this time. Or maybe I did
something wrong. Could you please give me a more
complete piece of code?

Thanks!
-----Original Message-----
Jade,

Assuming that variable is in scope, you would use the

following:

<% = jsTestServer %>

Actually, what you should do is use

RegisterClientScriptBlock to generate
your client-side script on the server and then register

it on the client.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and

confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jade" <an*******@discussions.microsoft.com>
Sender: "Jade" <an*******@discussions.microsoft.com>
Subject: how to call aspx variable from Javascript
Date: Tue, 11 Nov 2003 09:30:27 -0800
Lines: 16
Message-ID: <0d****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOoeX8iZVlOZ5x5TzC4ue9n01Hi8w==
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:190114NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I saw some web page saying I could do it this way in
javascript:
var iNumber = <%#publicvarname [or] publicpropertyname %


but it doesn't seem to work. I have this piece of code
here in javascript:
<script language="javascript">
var sessionServer = "<%#jsTestServer%>";
alert(sessionServer);
</script>

and the variable is defined in the C# code behind:
public string jsTestServer
= "\\\\TestServer\\TestSession\\";

when I run it, alert has no message in it.


.

Nov 17 '05 #6

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

Similar topics

5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
8
by: Jade | last post by:
I saw some web page saying I could do it this way in javascript: var iNumber = <%#publicvarname publicpropertyname %> but it doesn't seem to work. I have this piece of code here in...
4
by: abcd | last post by:
I am novice asp.net programmer. I have xyz.js file which has resuable functions. I have asp.net form abcd.aspx and the code behind file abcd.aspx.cs, I want to put a 'Help' button when clicked...
3
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with...
2
by: hibaru | last post by:
Hi Is it possible to call a javascript function from a treeview controls OnSelectedNodeChanged event? Something similar to a OnClientClick event for buttons? I cant seem to find anyway to do...
5
by: moni | last post by:
Hi.. I am trying to use javascript for google maps display. If I call the javascript function from my aspx file I use: <input type="text" id="addresstext" value="Huntington Avenue,...
1
by: supin | last post by:
hi, i work in asp.net2.0/c#.not much expert in javascript.i have a variable declared in the c# code behind page.assume the variable contains some value. i have a javascript function in the...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.