473,804 Members | 3,549 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='javas cript'>foo=" +
Request.QuerySt ring["var"].ToString() + "; </script>";
if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.RegisterCl ientScriptBlock ("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.queryst ring["var"]?

Any help would be appreciated.

thanks,
fxs


Nov 19 '05 #1
4 1661
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.Qu eryString["var"];
}

You might be able to do it with without the variable, by just using <%=
Page.Request.Qu eryString["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='javas cript'>foo=" +
Request.QuerySt ring["var"].ToString() + "; </script>";
if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.RegisterCl ientScriptBlock ("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.queryst ring["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.c om> wrote in message
news:eB******** ******@TK2MSFTN GP09.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='javas cript'>foo=" +
Request.QuerySt ring["var"].ToString() + "; </script>";
if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.RegisterCl ientScriptBlock ("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.queryst ring["var"]?

Any help would be appreciated.

thanks,
fxs

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

"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:%2******** ********@tk2msf tngp13.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.c om> wrote in message
news:eB******** ******@TK2MSFTN GP09.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='javas cript'>foo=" +
Request.QuerySt ring["var"].ToString() + "; </script>";
if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.RegisterCl ientScriptBlock ("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.queryst ring["var"]?

Any help would be appreciated.

thanks,
fxs


Nov 19 '05 #4
fxs
I tested <%=request.quer ystring("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?

"dhnriversi de" <da*@musoswire. com> wrote in message
news:CC******** *************** ***********@mic rosoft.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.Qu eryString["var"];
}

You might be able to do it with without the variable, by just using <%=
Page.Request.Qu eryString["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='javas cript'>foo=" +
Request.QuerySt ring["var"].ToString() + "; </script>";
if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.RegisterCl ientScriptBlock ("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.queryst ring["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
4091
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 dependant on data collected in the code behind on the server. I have set AutoPostback to false for the controls and added lines such as cboMyCombo1.Attributes.Add("onchange", "MyCombos_OnChange('1')"); in the Page_Load event, which is rendered OK...
5
1647
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 the codebehind, sorta. -- Regards, Alvin Bruney Got tidbits? Get it here... http://tinyurl.com/3he3b
4
2552
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
4126
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 windows to select some items, this is done via window.open, I then return the selected items via the returnValue, when I receive the data back I need to be able to call into a function in my main page codebehind to update the xml.
1
3265
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 other input fields available to fill in. I use the JavaScript OnChange function (=clientside) that creates a querystring and does a refresh of the page. It works fine.
1
12796
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 add the option to the listbox. It works for <select> or <asp:listbox> controls. var opt = document.CreateElement("OPTION"); opt.text = "test"; opt.value="test";
16
1431
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
10731
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 like: OnSelectedIndexChanged="javascript:SetOwner('<%= lstOwner.ClientID %>');" I get an error.
6
11442
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
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7621
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.