473,395 Members | 1,915 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.

Passing values between pages

Hello,

In my Aspx.cs page in Page_load event I have for example:
String x;
x = "10";
How can I use the x value in a javascript function in the Aspx page?

thanks

Sep 23 '07 #1
4 2197
In page_load you can place the value of x into a hidden field. IIRC, you can
add the "runat=server" attribute to a plain 'ole html hidden field. Doing
this makes it accessible to your C# code behind.

-HTH

"zion" <zi**@msn.comwrote in message
news:O4**************@TK2MSFTNGP04.phx.gbl...
Hello,

In my Aspx.cs page in Page_load event I have for example:
String x;
x = "10";
How can I use the x value in a javascript function in the Aspx page?

thanks

Sep 23 '07 #2
"zion" <zi**@msn.comwrote in message
news:O4**************@TK2MSFTNGP04.phx.gbl...
In my Aspx.cs page in Page_load event I have for example:
String x;
x = "10";
How can I use the x value in a javascript function in the Aspx page?
One way to do it is to write <%= x %inside your javascript code in the
aspx page in the place where you want to access x. Note that this will only
work if x is a public field or method inside your class, so it can't be a
local variable of the Page_Load method.

Another way is to build the javascript code inside your server code. You
can then concatenate into the code the value of any variables that you want,
such as the local variable x, and then you send this javascript into the
page by means of any of the methods provided for this purpose, such as
ClientScript.RegisterClientScriptBlock.

Sep 23 '07 #3
To clarify...

Doing this ["runat=server"] makes it [your hidden html field] accessible to
your C# code behind.

In your code behind you'd then write the value of x to the hidden field.

Then the page gets rendered down to the browser where the hidden field has
the value of x.

You can read and write the value of the hidden field via JavaScript in the
client/browser.

Then, on postback, the C# codebehind can read the value of the hidden field
to see what the new value is.

-HTH..

-S

"Smithers" <A@B.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
In page_load you can place the value of x into a hidden field. IIRC, you
can add the "runat=server" attribute to a plain 'ole html hidden field.
Doing this makes it accessible to your C# code behind.

-HTH

"zion" <zi**@msn.comwrote in message
news:O4**************@TK2MSFTNGP04.phx.gbl...
>Hello,

In my Aspx.cs page in Page_load event I have for example:
String x;
x = "10";
How can I use the x value in a javascript function in the Aspx page?

thanks


Sep 23 '07 #4
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:%2****************@TK2MSFTNGP03.phx.gbl...
"zion" <zi**@msn.comwrote in message
news:O4**************@TK2MSFTNGP04.phx.gbl...
Note that this will only work if x is a public field or method inside your
class
I say x should be a protected field, not public.

- Michael Starberg
Sep 25 '07 #5

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

Similar topics

5
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
5
by: Raju V.K | last post by:
I am developing a web site which requires a set og unique values be transferred between pages and server many times. There fore i decided to put the values in an array so that only one reference to...
1
by: Matt M | last post by:
Ok. So I'm passing values between web pages, as per microsoft's framework development guide (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht...
4
by: rick | last post by:
Does anyone having a working example of passing values between web forms pages? I tried the example in the ms- help but I can't get by the following: To read property values from the source...
4
by: Gibs | last post by:
Hi I have two aspx pages in a frame and in the top page i am creating the controls dynamically and putting in a place holder. I have a hyperlink in this page to populate the data in the bottom...
2
by: VS_NET_DEV | last post by:
Hi All, There two ways of passing values between pages - 1) Context.Items.Add 2) Context.Handler (cast the page1 class etc) I know for sure #2 does not store the values between requests. How...
1
by: olduncleamos | last post by:
Hello all. With a background in ASP, I am finding the work required for passing values between pages mystifying. For various obvious reasons, I have eliminated using cookies and session to store...
1
by: Steve | last post by:
After a few hours of trial and error I have reached the following conclusions, can you please tell me if I am right: I have 2 aspx pages both with the same master page and I wish to pass values...
3
by: dbuchanan | last post by:
newbie question What are the various ways that data can be passed between pages. For example; How is data about the logged in user passed to subsequent pages Thank you, Doug
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.