473,320 Members | 1,846 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,320 software developers and data experts.

passing variable from code behind to function in javascript

Just wondering if someone could provide an example of passing a variable from
the code behind to javascript in vb. I want to have one control have focus
with the page loading with one condition and have another control with focus
after the page loads from a different condition. A gets set in the code
aspx.vb file and the script might look something like,
<script language="javascript">
function DoHighlight(a)
{
if a = 1 {
document.Form1.dr_lst_system.focus();
}
else
{
Form1.textbox1.focus();
}
}
</script>

thanks.
--
Paul G
Software engineer.
Nov 19 '05 #1
5 3498
Hi Paul,

It is impossible to pass a variable value from the server to the client.
Server-side code executes on the server. Client-side code executes on the
client.

That said, it is certainly possible to WRITE client-side scripting code
(which will be executed on the client) dynamically from the server side.
That is what you need to do.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Just wondering if someone could provide an example of passing a variable
from
the code behind to javascript in vb. I want to have one control have
focus
with the page loading with one condition and have another control with
focus
after the page loads from a different condition. A gets set in the code
aspx.vb file and the script might look something like,
<script language="javascript">
function DoHighlight(a)
{
if a = 1 {
document.Form1.dr_lst_system.focus();
}
else
{
Form1.textbox1.focus();
}
}
</script>

thanks.
--
Paul G
Software engineer.

Nov 19 '05 #2
Paul,

This is normally done with hidden input controls. Put a line

<input type=hidden runat=server id=inhA>

in the .aspx file. If you switch from Html view to Design and back, you will
find in the code-behind a definition for inhA as an obyect of type
System.Web.UI.HtmlControls.HtmlInputHidden.

You can now set inhA.Value="1" on server side and check if (inhA.value ==
"1") on client side.

Eliyahu

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Just wondering if someone could provide an example of passing a variable from the code behind to javascript in vb. I want to have one control have focus with the page loading with one condition and have another control with focus after the page loads from a different condition. A gets set in the code
aspx.vb file and the script might look something like,
<script language="javascript">
function DoHighlight(a)
{
if a = 1 {
document.Form1.dr_lst_system.focus();
}
else
{
Form1.textbox1.focus();
}
}
</script>

thanks.
--
Paul G
Software engineer.

Nov 19 '05 #3
Hi thanks for the response. Here is what I have but it does not seem to be
working. In the Java script I have
<form id="Form1" method="post" runat="server">
<input type="hidden" runat="server" id="inhA" NAME="inhA">
<script language="javascript" event="onload" for="window">
if (inhA.value == 0)
{Form1.dr_tx_names.focus();}
if (inhA.value == 1)
{Form1.dr_lst_system.focus();}
</script>and in the aspx.vb file I have
in page load event
If Not Page.IsPostBack Then 'only first time page loads
Me.inhA.Value = 0
and in a dropdown event select-causes the page to reload I have
Me.inhA.Value = 1
**************so I want one control two have focus if inhA = 0 and the other
to have focus if inhA = 1.
thanks for the information.
--
Paul G
Software engineer.
"Eliyahu Goldin" wrote:
Paul,

This is normally done with hidden input controls. Put a line

<input type=hidden runat=server id=inhA>

in the .aspx file. If you switch from Html view to Design and back, you will
find in the code-behind a definition for inhA as an obyect of type
System.Web.UI.HtmlControls.HtmlInputHidden.

You can now set inhA.Value="1" on server side and check if (inhA.value ==
"1") on client side.

Eliyahu

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Just wondering if someone could provide an example of passing a variable

from
the code behind to javascript in vb. I want to have one control have

focus
with the page loading with one condition and have another control with

focus
after the page loads from a different condition. A gets set in the code
aspx.vb file and the script might look something like,
<script language="javascript">
function DoHighlight(a)
{
if a = 1 {
document.Form1.dr_lst_system.focus();
}
else
{
Form1.textbox1.focus();
}
}
</script>

thanks.
--
Paul G
Software engineer.


Nov 19 '05 #4
On Wed, 29 Jun 2005 11:02:04 -0700, Paul wrote:
Just wondering if someone could provide an example of passing a variable from
the code behind to javascript in vb. I want to have one control have focus
with the page loading with one condition and have another control with focus
after the page loads from a different condition. A gets set in the code
aspx.vb file and the script might look something like,
<script language="javascript">
function DoHighlight(a)
{
if a = 1 {
document.Form1.dr_lst_system.focus();
}
else
{
Form1.textbox1.focus();
}
}
</script>

thanks.

Something like
if(<%=a%> = 1) will work (a is a server-side variable)
Nov 19 '05 #5
ok thanks for the information.
--
Paul G
Software engineer.
"intrader" wrote:
On Wed, 29 Jun 2005 11:02:04 -0700, Paul wrote:
Just wondering if someone could provide an example of passing a variable from
the code behind to javascript in vb. I want to have one control have focus
with the page loading with one condition and have another control with focus
after the page loads from a different condition. A gets set in the code
aspx.vb file and the script might look something like,
<script language="javascript">
function DoHighlight(a)
{
if a = 1 {
document.Form1.dr_lst_system.focus();
}
else
{
Form1.textbox1.focus();
}
}
</script>

thanks.

Something like
if(<%=a%> = 1) will work (a is a server-side variable)

Nov 19 '05 #6

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

Similar topics

1
by: Patrice | last post by:
Hi, I'm trying to use a javascript function passing a vb variable. I don't understand why it doesn't work. Can someone help me? Thanks in advance. Here is my javascript function used to...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
1
by: cirillo_curiosone | last post by:
Hi, i'm new to javascript. I started studing it on the web few weeks ago, but still haven't been able to solve one big problem: HOT TO PASS VALUES FROM A SCRIPT VARIABLE TO A CHILD HTML...
8
by: Mike Fellows | last post by:
Ok, im not sure if this is at all possible and if it is how i go about it is beyond me i have a piece of client side code that requires a piece of data from the server side (an ID number in this...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
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...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.