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

User control with in a parent aspx page cant see the view state

Morning,

I have been having trouble with a my embedded user control not being
able to see the view state that I set in its parent page.

I have done a test with the following and I still cant get it to work!

PARENT PAGE (default.aspx):

private void Page_Load(object sender, System.EventArgs e)
{
int nPageID = 7;

ViewState["test1"] = nPageID;

//or
//ViewState.Add("test1", nPageID);
}

EMBEDDED USER CONTROL:

private void Page_Load(object sender, System.EventArgs e)
{
try
{
int test = (int)ViewState["test1"]);
}
}

when int test = (int)ViewState["test1"]); is run I get object not set
to an instance of an object.

What do I need to do so that my embedded user control can see the view
state set in my parent page?

thanks
RuSs
Nov 16 '05 #1
2 7751
Russell wrote:
What do I need to do so that my embedded user control can see the view
state set in my parent page?

thanks
RuSs


ViewState is a protected property, which to cut a long story short,
means that it can only be accessed from the parent page.

If you want to pass values from the parent page to the user control, add
properties to the user control and set them from the parent page.

HTH

--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk
Nov 16 '05 #2
Hi Russell,

the viewstate is control specific. The member is a protected property so you
can only access it from within your control (a page is a control too) or
controls derived from your control.

To share information between the page and a control, use properties on the
control, sessions state or public members on the page.

--
Patrik Löwendahl
www.cshrp.net - 'Elegant code by witty programmers'
"Russell" <ru************@hotmail.com> wrote in message
news:15**************************@posting.google.c om...
Morning,

I have been having trouble with a my embedded user control not being
able to see the view state that I set in its parent page.

I have done a test with the following and I still cant get it to work!

PARENT PAGE (default.aspx):

private void Page_Load(object sender, System.EventArgs e)
{
int nPageID = 7;

ViewState["test1"] = nPageID;

//or
//ViewState.Add("test1", nPageID);
}

EMBEDDED USER CONTROL:

private void Page_Load(object sender, System.EventArgs e)
{
try
{
int test = (int)ViewState["test1"]);
}
}

when int test = (int)ViewState["test1"]); is run I get object not set
to an instance of an object.

What do I need to do so that my embedded user control can see the view
state set in my parent page?

thanks
RuSs

Nov 16 '05 #3

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

Similar topics

11
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div,...
4
by: Pham Nguyen | last post by:
I have two maybe related questions about view state and the life cycle of controls: 1) When does the view state in a control get restored? I thought there was a LoadViewState event that occured...
6
by: Jim | last post by:
I have a user control that I am dynamically loading into an aspx page. When I fill out the text boxes and submit the form using a command button on the aspx page I lose the value from the user...
5
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
1
by: Demetri | last post by:
I'm trying to determine if we want to use panels or user controls for our pages. Our primary concern is performance, page loading and posting speed. To illustrate my question, lets use the...
3
by: Mark Rae | last post by:
Hi, Just a general quickie on setting properties of user controls from the parent form. Let's say I have a user control called note.ascx which displays a datagrid. That datagrid is populated...
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...
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
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
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
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,...
0
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...

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.