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

generate clientside javascript from asp.net page

fxs
Hello, I've got the following elements on my page:

A Body tag that looks like this:
<body onload="setTabs()">

A Javascript script in the <head> that has:
var foo;
function setTabs()
{
doSomething(foo);
}

I want my ASP.NET page to set the value of foo so that it gets used in the
setTabs() function onload of the page.

So, I tried the following in Page_Load()

string strScript = "<script language='javascript'>foo=" +
Request.QueryString["var"].ToString() + "; </script>";
if(!this.IsClientScriptBlockRegistered("clientScri pt"))
this.RegisterClientScriptBlock("clientScript", scriptString);

This obviously does not seem to work.I'm trying to therefore figure out, how
do I set the value of a client side javascript variable (foo) based on the
value of my serverside variable request.querystring["var"]?

Any help would be appreciated.

thanks,
fxs


Nov 19 '05 #1
4 1639
Hi

You could write the function like this...

function setTabs()
{
doSomething(<%= qsvar %>);
}

and your Page class should have...

public string qsvar="";

Page_Load()
{
qsvar = Page.Request.QueryString["var"];
}

You might be able to do it with without the variable, by just using <%=
Page.Request.QueryString["var"] %> in your Javascript - haven't tested this
tho!

HTH
Dan

"fxs" wrote:
Hello, I've got the following elements on my page:

A Body tag that looks like this:
<body onload="setTabs()">

A Javascript script in the <head> that has:
var foo;
function setTabs()
{
doSomething(foo);
}

I want my ASP.NET page to set the value of foo so that it gets used in the
setTabs() function onload of the page.

So, I tried the following in Page_Load()

string strScript = "<script language='javascript'>foo=" +
Request.QueryString["var"].ToString() + "; </script>";
if(!this.IsClientScriptBlockRegistered("clientScri pt"))
this.RegisterClientScriptBlock("clientScript", scriptString);

This obviously does not seem to work.I'm trying to therefore figure out, how
do I set the value of a client side javascript variable (foo) based on the
value of my serverside variable request.querystring["var"]?

Any help would be appreciated.

thanks,
fxs


Nov 19 '05 #2
You can call Response.Write (strScript);

But the cleanest way is to pass data in a hidden input instead of setting a
client variable from the server.

Eliyahu

"fxs" <su****@xyant.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Hello, I've got the following elements on my page:

A Body tag that looks like this:
<body onload="setTabs()">

A Javascript script in the <head> that has:
var foo;
function setTabs()
{
doSomething(foo);
}

I want my ASP.NET page to set the value of foo so that it gets used in the
setTabs() function onload of the page.

So, I tried the following in Page_Load()

string strScript = "<script language='javascript'>foo=" +
Request.QueryString["var"].ToString() + "; </script>";
if(!this.IsClientScriptBlockRegistered("clientScri pt"))
this.RegisterClientScriptBlock("clientScript", scriptString);
This obviously does not seem to work.I'm trying to therefore figure out, how do I set the value of a client side javascript variable (foo) based on the
value of my serverside variable request.querystring["var"]?

Any help would be appreciated.

thanks,
fxs

Nov 19 '05 #3
fxs
great. thanks! i'll try that!

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
You can call Response.Write (strScript);

But the cleanest way is to pass data in a hidden input instead of setting
a
client variable from the server.

Eliyahu

"fxs" <su****@xyant.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Hello, I've got the following elements on my page:

A Body tag that looks like this:
<body onload="setTabs()">

A Javascript script in the <head> that has:
var foo;
function setTabs()
{
doSomething(foo);
}

I want my ASP.NET page to set the value of foo so that it gets used in
the
setTabs() function onload of the page.

So, I tried the following in Page_Load()

string strScript = "<script language='javascript'>foo=" +
Request.QueryString["var"].ToString() + "; </script>";
if(!this.IsClientScriptBlockRegistered("clientScri pt"))
this.RegisterClientScriptBlock("clientScript",

scriptString);

This obviously does not seem to work.I'm trying to therefore figure out,

how
do I set the value of a client side javascript variable (foo) based on
the
value of my serverside variable request.querystring["var"]?

Any help would be appreciated.

thanks,
fxs


Nov 19 '05 #4
fxs
I tested <%=request.querystring("var")%> and that works -- however, I;d like
to be able to stay away from the asp style code-insertion tactics if i can.

How about creating a serverside input control type = hidden runat=server and
then trying to assign it a value on the page_load?

"dhnriverside" <da*@musoswire.com> wrote in message
news:CC**********************************@microsof t.com...
Hi

You could write the function like this...

function setTabs()
{
doSomething(<%= qsvar %>);
}

and your Page class should have...

public string qsvar="";

Page_Load()
{
qsvar = Page.Request.QueryString["var"];
}

You might be able to do it with without the variable, by just using <%=
Page.Request.QueryString["var"] %> in your Javascript - haven't tested
this
tho!

HTH
Dan

"fxs" wrote:
Hello, I've got the following elements on my page:

A Body tag that looks like this:
<body onload="setTabs()">

A Javascript script in the <head> that has:
var foo;
function setTabs()
{
doSomething(foo);
}

I want my ASP.NET page to set the value of foo so that it gets used in
the
setTabs() function onload of the page.

So, I tried the following in Page_Load()

string strScript = "<script language='javascript'>foo=" +
Request.QueryString["var"].ToString() + "; </script>";
if(!this.IsClientScriptBlockRegistered("clientScri pt"))
this.RegisterClientScriptBlock("clientScript",
scriptString);

This obviously does not seem to work.I'm trying to therefore figure out,
how
do I set the value of a client side javascript variable (foo) based on
the
value of my serverside variable request.querystring["var"]?

Any help would be appreciated.

thanks,
fxs


Nov 19 '05 #5

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

Similar topics

4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
5
by: Alvin Bruney | last post by:
I have a server side datagrid control. I'd like to clear the grid before the post occurs using javascript. Anybody know how to do this? It would be a similar effect to binding to a null dataset in...
4
by: TJS | last post by:
how do I get "onSubmit" to work in .net ? <Form id="Form1" name="Form1" method="post" onSubmit="return validateStandard(this, 'error');" runat="server">
4
by: Rob Shorney | last post by:
Hi, I am using .Net 2003 , c# asp.net. The situation i have is this. I have a asp.net page which in the codebehind maintains an xml document in memory. The user can click on a button to popup a...
1
by: IkBenHet | last post by:
Hello, Currently I am using a large input form on a website that is based on ASP and JavaScript. Depending on the values that are filled in by the user the forms does a refresh and makes...
1
by: bill | last post by:
I need to be able to dynamically add items to a <asp:listbox> (or HTML <select runat=server>) using clientside javascript, and retrieve the items when the page is posted back. I use this code to...
16
by: susiedba | last post by:
hey I used to be able to take VB6 code and paste it into a HTML page and it would run on the clientside does anyone know if this is possible in VB 2005? Thanks -Susie
2
by: John Kotuby | last post by:
Hi all, In ASP.NET 2.0 and VB.NET, I am trying to get the OnSelectedIndexChanged event to fire a Javascript function. There is no OnClientClick event for that control. When I try something...
6
by: Anz | last post by:
Is there any JavaScript function to generate a Beep sound from system ?, is it possible to make system Beep using JavaScript function ?
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
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
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.