473,698 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2206
In page_load you can place the value of x into a hidden field. IIRC, you can
add the "runat=serv er" attribute to a plain 'ole html hidden field. Doing
this makes it accessible to your C# code behind.

-HTH

"zion" <zi**@msn.comwr ote in message
news:O4******** ******@TK2MSFTN GP04.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.comwr ote in message
news:O4******** ******@TK2MSFTN GP04.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.Re gisterClientScr iptBlock.

Sep 23 '07 #3
To clarify...

Doing this ["runat=serv er"] 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******** *******@TK2MSFT NGP02.phx.gbl.. .
In page_load you can place the value of x into a hidden field. IIRC, you
can add the "runat=serv er" attribute to a plain 'ole html hidden field.
Doing this makes it accessible to your C# code behind.

-HTH

"zion" <zi**@msn.comwr ote in message
news:O4******** ******@TK2MSFTN GP04.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.o rgwrote
in message news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
"zion" <zi**@msn.comwr ote in message
news:O4******** ******@TK2MSFTN GP04.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
5941
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 contains: <?php $_SESSION = ""; $_SESSION = "";
1
7784
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: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION = ""; echo "<form method='POST' action='login.php'>
5
7610
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 the array is needed ratherthan idividual reference. The situation is like this: When the page is loaded based on the user input say 6 values are created like character1="tom", character2="jerry", Character3="micky", Character4="donald",...
1
3034
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 ml/cpconPassingServerControlValuesBetweenPages.asp) So, I have two pages, one that has some public properties and fires a Server.Transfer("receivepage.aspx"); The receivepage.aspx can then get some of the public properties I've set on the first page.
4
3138
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 page in the call page. 1. Create a global instance varible that is typed to the class of the source page. the sample provided
4
2345
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 aspx page. When the user clicks this hyperlink i need to populate the bottom aspx pagebased on the user imputs. So i need to pass the values from the top aspx page to bottom aspx page. how can i achieve this. Please give some ideas...
2
2009
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 about #1. Does it store values between requests? i.e. The Context.Items. collection A)Is it like the Session variables?
1
2708
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 state data. The only ASP.NET options left is to use the Server.Transfer to transfer to page 2 from page 1, and then use the context to get whatever values in page 1 from page 2. I do find this indeed a very elegant solution as now I can pass...
1
2340
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 from one to the other. 1. The postbackurl method doesn't seem to work with master pages. If I take away the master pages it works. 2. The server.transfer method also doesn't work if I try to acess the
3
2277
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
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8893
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7721
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.