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

Code-Behind variables

Is it possible to access an variables' value, using javascript
The variable is created on the code behind
What i want to know is if i give a value to an variable created in the code behind, is it possible to retvrive its value directel
, in the .aspx file by using for eg javascript

Thanks in advance
Nov 18 '05 #1
7 2058
Server side code and client side code is totally different and
seperate. You will need to provide a client side variable with the
value from the server side. Maybe a hidden form variable?

On Fri, 5 Mar 2004 17:56:07 -0800, "Marco"
<an*******@discussions.microsoft.com> wrote:
Is it possible to access an variables' value, using javascript.
The variable is created on the code behind.
What i want to know is if i give a value to an variable created in the code behind, is it possible to retvrive its value directely
, in the .aspx file by using for eg javascript.

Thanks in advance


Nov 18 '05 #2
i woust to be an asp programmer, and that was i woust to do, hidden textboxes to set some values, i also know the difference between server and client code. But i tought it was possible for eg, get an variable's value in the .aspx page by using the viewsatate(), even if that variables was created in the server

Thanks again mat
;
Marco
Nov 18 '05 #3
In the code-behind:

Dim x as Integer = 10
response.write "<SCRIPT LANGUAGE='JavaScript'>"
response.write "var x = " & x
response.write "alert('The server side variable x was passed to the client
and its value is ' + x)"
response.write "</SCRIPT>"
"Marco" <an*******@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
i woust to be an asp programmer, and that was i woust to do, hidden textboxes to set some values, i also know the difference between server and
client code. But i tought it was possible for eg, get an variable's value in
the .aspx page by using the viewsatate(), even if that variables was created
in the server.
Thanks again mate
;)
Marco

Nov 18 '05 #4
I dont understand what you have said, its not possible to use the response.write object in the code-behind page. In my case the that page is called chat.aspx.cs, using c#.

Thanks again,
Marco
Nov 18 '05 #5
Notice that it is using Response.Write calls, which generates HTML. In
this case, it's Javascript code. Response.Write was used a LOT in
original ASP coding. The tags <%= and %> are actually just a shortcut
for Response.Write the code inside.

Viewstate is used by the server, and is not available for use on the
client. Modifying it's value will result in errors on the server. The
values in Viewstate are Base64 encoded, which means although it
"could" be read, it's not very easy - to put it mildly. Look at <input
type=hidden> tags. If you add the runat="server" property, you get a
..NET object to code against, but you will have to use it's Attributes
collection rather than just setting it's Value property.
On Fri, 5 Mar 2004 19:31:06 -0800, "Marco"
<an*******@discussions.microsoft.com> wrote:
I dont understand what you have said, its not possible to use the response.write object in the code-behind page. In my case the that page is called chat.aspx.cs, using c#.

Thanks again,
Marco


Nov 18 '05 #6
Of course you can use Response.Write from the code behind. Response is the
HTTPResponse object and is native to .NET. Write will write the string into
the Response stream that is being sent to the client browser. Since what
I'm writing is JavaScript, it will be sent to the browser and then the
browser will insert it into what it winds up rendering. It will function as
normal JavaScript, except that the variable "x" will have gotten its value
from the server variable "x".

It doesn't matter if you are using C# or VB.NET, the Response object is part
of the .NET Framework, not an element of any particular language.

The only thing you'd change in my code is you'd change how the server
variable was declared, capitalize according C# and add your semi-colons
where C# wants them.
"Marco" <an*******@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
I dont understand what you have said, its not possible to use the response.write object in the code-behind page. In my case the that page is
called chat.aspx.cs, using c#.
Thanks again,
Marco

Nov 18 '05 #7
> Notice that it is using Response.Write calls, which generates HTML.

Well no, more accurately it simply sends TEXT to the browser (note: it may
be any value from any data-type, but it gets sent to the client as text).
The text could be anything at all (HTML, JavaScript, VBScript, XML, etc.).
The "Write" method of the "Response" object doesn't care what text you write
and it doesn't "generate" anything. It just sends what you tell it to.
The tags <%= and %> are actually just a shortcut for Response.Write the code inside.

More accurately, just the "=" used as a prefix for some expression that
results in a value that can be sent to the browser is a shortcut for
Response.Write. And, you could only use that shortcut when the script block
was only going to contain that one command (ie. <% ="Hello World" %>).

The <% and the %> are actually shorthand for <SCRIPT> and </SCRIPT>. They
are the way to indicate a server side script block.
Viewstate is used by the server, and is not available for use on the
client. Modifying it's value will result in errors on the server. The
values in Viewstate are Base64 encoded, which means although it
"could" be read, it's not very easy - to put it mildly.
It is very easy to add and read items to/from ViewState in the CodeBehind
using ViewState.Add(key, value) and ViewState.Item(key). The stored and
then read value can then be use in any way that you want to, including
sending down to the client.
Look at <input> type=hidden> tags. If you add the runat="server" property, you get a .NET object to code against, but you will have to use it's Attributes
collection rather than just setting it's Value property.


Um no. If you have marked the hidden form field as runat=server, you can
code against its .value property directly from the codebehind.

You've given several mistaken or misleading pieces of advice and/or facts
here. I suggest you read up on this or try it out before commenting.

Nov 18 '05 #8

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
4
by: KenFehling | last post by:
Hello. I am wondering if there exists a piece of software that takes multiple .js files that are nicely indented and commented and create one big tightly packed .js file. I'm hoping the one file...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
7
by: blackrosezy | last post by:
#include char *code; void main() { char buf = "book";
13
by: frk.won | last post by:
I am interested in learning how to use the VS 2005 code snippets. However, I wish to know what are the best ways to source control the code snippets? Are there any source safe/subversion...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.