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

user control cant access ViewState of Parent control

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 protected member
'System.Web.UI.Control.ViewState' via a qualifier of type
'System.Web.UI.Control'; the qualifier must be of type
'ASP.ItemOrderGrid' (or derived from it)

Source Error:
Line 5:Trace.Write( "LoadId", Parent.ViewState["LoadId"].ToString( )) ;

Do I understand this correctly? The parent control of a user control
is the Page control? Basically, I want the user control to be able to
access the state bag of the page it is instantiated on. Is that doable?

thanks,
-Steve

Nov 19 '05 #1
5 7631
Why do you need to do this? Typically the parent control would have a public
property exposing the dat you need to get at. Or if it's simply some data
you control needs to persist across the postback you put it in your own ViewState
collection.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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 protected member
'System.Web.UI.Control.ViewState' via a qualifier of type
'System.Web.UI.Control'; the qualifier must be of type
'ASP.ItemOrderGrid' (or derived from it)

Source Error:
Line 5:Trace.Write( "LoadId", Parent.ViewState["LoadId"].ToString( ))
;
Do I understand this correctly? The parent control of a user control
is the Page control? Basically, I want the user control to be able to
access the state bag of the page it is instantiated on. Is that
doable?

thanks,
-Steve


Nov 19 '05 #2

Brock Allen wrote:
Why do you need to do this?
I want all my pages to always be able to retrieve some detailed info
about its referer page: RawUrl and the PageTitle. Using this info, a
page can have a LinkButton with text=RefererPageTitle. When the "return
to referer" LinkButton is clicked, the code will Response.Redirect(
RawUrl of the referer ) ;

So I built a table, called a PageLoadMaster. In Page_Load, when
IsPostBack = false, I call a function to create a PageLoad row for the
page. That function stores the RawUrl and TitleText of the page in the
row and returns a guid key to the row. This guid, in string form, which
is called the LoadId, is stored in the StateBag ( fun name! ) of the
Page control.
string LoadId = LoadMaster.NewPage( Request, "Customer home" ) ;
ViewState["LoadId"] = LoadId ;

Now a user control on the page does a redirect to another page. I want
to pass to that page the LoadId of this refering page:
string LoadId = Parent.ViewState["LoadId"].ToString( ) ;
Response.Redirect( Url + "?RefererLoadId=" + LoadId ) ;

The assumption being that the Parent of a user control will always be a
Page control. ( I guess I could walk up the Parent tree of a control
until I came to a Page control. )
Typically the parent control would have a public
property exposing the data you need to get at. Or if it's simply some data you control needs to persist across the postback you put it in your own ViewState collection.
I guess. Playing with it, I was able to add a StateBag member to the
user control called "ParentStateBag".
public StateBag ParentStateBag ;

Then, in the Page_Load of the parent, set the ParentStateBag reference
to the ViewState of the page.
itemOrderGrid.ParentStateBag = ViewState ;

( not sure if this would always work or not. What if ASP.NET rebuilds
the StateBag of a page at some point. My user control will then
reference an old copy of the ViewState of its parent. )

I have to laugh at this encapsulation stuff. If I can get at the
StateBag of the parent this way, why not allow access thru the
ViewState property?

-Steve

-Brock
DevelopMentor
http://staff.develop.com/ballen
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 protected member
'System.Web.UI.Control.ViewState' via a qualifier of type
'System.Web.UI.Control'; the qualifier must be of type
'ASP.ItemOrderGrid' (or derived from it)

Source Error:
Line 5:Trace.Write( "LoadId", Parent.ViewState["LoadId"].ToString( )) ;
Do I understand this correctly? The parent control of a user control is the Page control? Basically, I want the user control to be able to access the state bag of the page it is instantiated on. Is that
doable?

thanks,
-Steve


Nov 19 '05 #3
> I want all my pages to always be able to retrieve some detailed info
about its referer page: RawUrl and the PageTitle.

The assumption being that the Parent of a user control will always be
a Page control. ( I guess I could walk up the Parent tree of a control
until I came to a Page control. )


The page is always accessible directly via the Page property. So then in
your control why don't you call Page.Request.UrlReferrer? :)

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #4

Brock Allen wrote:
I want all my pages to always be able to retrieve some detailed info about its referer page: RawUrl and the PageTitle.

The assumption being that the Parent of a user control will always be a Page control. ( I guess I could walk up the Parent tree of a control until I came to a Page control. )
The page is always accessible directly via the Page property. So then

in your control why don't you call Page.Request.UrlReferrer? :)


I just checked that ( trace.write is great! ) and it does contain the
RawUrl of the referrer. When I checked into UrlReferrer last week I
could have sworn it did not contain the QueryString. What is the
emoticon for "stupid face"?

But I still like the idea of storing the info in a table. That way I
can always get at extra info like the PageTitle and place it as the
text on the return link.

thanks!

-Steve

Nov 19 '05 #5
> What is the emoticon for "stupid face"?

:S

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #6

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

Similar topics

2
by: Russell | last post by:
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...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
3
by: J-T | last post by:
I have a aspx page which loaded different user contols based on the users' entries.In one of my child user controls I have a property like below: public String PostID { get { return (String)...
3
by: Jordan | last post by:
My ASP.NET 1.1. app dynamically loads a user control into a PlaceHolder control that exists in an aspx page. The user control is loaded during the Page_Load event of the aspx. The PlaceHolder's...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
6
by: Rob Morgan | last post by:
I have a grid and a user control on the same page. The user control has a save button that triggers a click event server side. Once the click event happens the page renders, but I need to update...
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: Dave A | last post by:
I have a user control that is dynamically loaded into a repeater; (so the user control appears several times) The user control features a text box and a delete button. When the delete button...
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
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
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
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...

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.