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

Javascript Variable

I have a boolean variable defined in the aspx.cs code for my webpage. I need
to read the value of this variable in the javascript code that i have in the
codebehind file. Is there a way to do this??

I've tried the following but I get an error saying that "edit_clicked is
undefined."

if (edit_clicked == false)
<do what i have to do...>
Nov 16 '05 #1
3 1967
Parveen,

You can not do this. Basically, javascript runs on the client side, and
the C# code runs on the server side. If you want to pass information
between them, then you will have to have the server side write the variable
value when it is declared, and have the client issue a postback when the
value changes (so the server can process it).

All in all, not a trivial operation. What are you trying do to?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Parveen" <Pa*****@discussions.microsoft.com> wrote in message
news:24**********************************@microsof t.com...
I have a boolean variable defined in the aspx.cs code for my webpage. I
need
to read the value of this variable in the javascript code that i have in
the
codebehind file. Is there a way to do this??

I've tried the following but I get an error saying that "edit_clicked is
undefined."

if (edit_clicked == false)
<do what i have to do...>

Nov 16 '05 #2
hi,

I think you have a little confusion between server side and client side,
c# code runs in the server, in the client it runs javascript ( most of the
time is like this anyway) , sometimes you need to interact and there are
several ways of doing it, you coudl trigger an action from the server side
by setting a variable that will be read in javascript like this:

in the aspx page :
<script>
var WhatToDo="";
function DoWhatYouHaveToDo()
{
if (WhatToDo!="")
DoSomething();
}
</script>
</HEAD>
<body onload="DoWhatYouHaveToDo();">
then in the code behind you can do this:

Controls.Add( new LiteralControl("<script>WhatToDo='DoIt';</script>) );

it will add that piece of code at the end of the page so you will have the
variable with a value assigned when you run the function.
Is this what you want?

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Parveen" <Pa*****@discussions.microsoft.com> wrote in message
news:24**********************************@microsof t.com...
I have a boolean variable defined in the aspx.cs code for my webpage. I
need
to read the value of this variable in the javascript code that i have in
the
codebehind file. Is there a way to do this??

I've tried the following but I get an error saying that "edit_clicked is
undefined."

if (edit_clicked == false)
<do what i have to do...>

Nov 16 '05 #3
Thanks for your reply...I'm trying to control when to show an alert box for
the webpage. This decision is based on the value of the C# variable...does
this make sense?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Parveen,

You can not do this. Basically, javascript runs on the client side, and
the C# code runs on the server side. If you want to pass information
between them, then you will have to have the server side write the variable
value when it is declared, and have the client issue a postback when the
value changes (so the server can process it).

All in all, not a trivial operation. What are you trying do to?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Parveen" <Pa*****@discussions.microsoft.com> wrote in message
news:24**********************************@microsof t.com...
I have a boolean variable defined in the aspx.cs code for my webpage. I
need
to read the value of this variable in the javascript code that i have in
the
codebehind file. Is there a way to do this??

I've tried the following but I get an error saying that "edit_clicked is
undefined."

if (edit_clicked == false)
<do what i have to do...>


Nov 16 '05 #4

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

Similar topics

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...
1
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.