469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

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 3321
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by domeceo | last post: by
1 post views Thread by cirillo_curiosone | last post: by
8 posts views Thread by Mike Fellows | last post: by
pbmods
1 post views Thread by pbmods | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.