473,473 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pass Values from .aspx page to .ascx page

1 New Member
Hi All,

I want to pass values from .apsx page(textbox value) to .ascx page.
Any sort of help will be appreciated.
Regards
Dec 26 '07 #1
3 11010
nateraaaa
663 Recognized Expert Contributor
Hi All,

I want to pass values from .apsx page(textbox value) to .ascx page.
Any sort of help will be appreciated.
Regards
Use Session to pass from values from aspx page to user control.

aspx page
Expand|Select|Wrap|Line Numbers
  1. Session["value"] = somevariable.ToString();
ascx
Expand|Select|Wrap|Line Numbers
  1. if(Session["value"] != null)
  2. {
  3. //do whatever you need to do.
  4. }
Nathan
Dec 27 '07 #2
tiger888
4 New Member
[quote]

Expand|Select|Wrap|Line Numbers
  1.  
  2. Using Session variable will be best choice.
  3.  
  4. In Page_load method define a session variable
  5.  
  6. Session["text"]= this.txtbox.Text.ToString();
  7.  
  8. Next aspx page retrieve the value in page_Load method
  9.  
  10. this.txtbox.Text=Session["txt"].ToString();
  11.  
thanks
[/quote
Dec 27 '07 #3
amphibian1
7 New Member
Make sure you really want those objects to go into the session, though, because they will remain there as the user navigates around your site. If you only want those objects to be available for one page load, you may want to take another approach.

The solution I've come up with is to reserve one slot in the session for a System.Collections.Hashtable that gets cleared every time you load a new page. I put page-specific objects in there, while I put things like user information / preferences directly in the session.

Below, I've put an example class that does this. Has anyone else come up with a different solution for doing something similar?

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Web;
  4.  
  5. public class PageManager
  6. {
  7.   const string CONTEXT = "context";
  8.  
  9.   public object GetFromContext(Page page, string key)
  10.   {
  11.     return ((Hashtable)page.Session[CONTEXT])[key];
  12.   }
  13.  
  14.   public void PutIntoContext(Page page, string key, object value)
  15.   {
  16.     ((Hashtable)page.Session[CONTEXT])[key] = value;
  17.   }
  18.  
  19.   public object GetFromSession(Page page, string key)
  20.   {
  21.     return page.Session[key];
  22.   }
  23.  
  24.   public void PutIntoSession(Page page, string key, object value)
  25.   {
  26.     page.Session[key] = value;
  27.   }
  28.  
  29.   //this should get called on every page load
  30.   public void ClearContext(Page page)
  31.   {
  32.     page.Session[CONTEXT] = new Hashtable();
  33.   }
  34. }
Dec 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tom | last post by:
Hi, I have this question below but still cannot fix it. http://communities.microsoft.com/newsgroups/previewFrame.as p? ICP=msdn&sLCID=us&sgroupURL=microsoft.public.dotnet.framewo...
5
by: Ben | last post by:
Hi I am using a User Control which is referenced by an ASPX page. How can I pass a string parameter to the user control, from the base ASPX page. Thanks Ben
0
by: ab_j | last post by:
I have a user control that contains a dropdown which I want to use as a menu on multiple .aspx pages. Basically, all I am trying to do is pass the selected value of the dropdown in the user...
12
by: Phil Certain | last post by:
Hi, I'm trying to do something very simple...or at least it should be. I have created a host page (gen.aspx) and a very simple user control (us.ascx). The corresponding code-behind files are...
5
by: Chad | last post by:
Alright, I've been searching all over and it seems I'm just not looking for the right thing, since what I want to do seems extremely simple I just don't know the correct syntax. All I get is how to...
0
by: fernandezr | last post by:
Hi, I've got a user control that is referenced twice on the same page and I'd like to access the textbox values on postback so I can update a database. How can get the values for each instance of...
0
by: cjbland | last post by:
This one has me stumped and I've spent countless hours trying to find a solution. I have a UserControl being called from my main .aspx page. main-page.aspx: <%@ Register TagPrefix="my"...
0
by: - Pavana | last post by:
Hello, I am trying to pass variable value from an aspx page to an ascx page, but haven't been successful. This is the code: In the .ascx.cs file: public string filefolder; public string...
2
by: simon | last post by:
Hello, relatively new .net programmer. using vb.net (v2.0) I have an aspx page that contains 2 user controls (ascx) on it. the left control is basically navigation hyperlinks the right control...
0
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,...
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...
1
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.