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

how to access the viewstate on an inherited page?

I have a base page with an HTMLForm object (added to the base page control
heiarchy during Init).

In the design of pages derived from this base page, I can choose to create
controls and add them to the HTMLForm object I'm inheriting, to create a
postback form. And on one particular page I'm doing just that; defining
controls on the derived page (during Init) and adding these controls to the
inherited HTMLForm object's control collection. These controls include a
dropdownlist (that autopostbacks) and a submit button. The dropdownlist is
physically above the button in the HTMLForm's control heiarchy.

In the codebehind of the derived page, I have a event handlers for both the
dropdownlist's SelectedIndexChanged event (to handle the autopostback of the
dropdown) as well as the button's Click event.

During the Init process of the derived page, I instantiate the dropdown and
the button (as well as the other input controls for the form) and add them
to the HTMLForm's control heiarchy. I do this during Init based on my
belief that that LoadViewState, which occurs after init, expects to find an
identical form control heiarchy between postbacks. So the form has to be
established and receptive by the end of the Init phase.

Now here's the problem I'm experiencing: if I post back to this page, the
SelectedIndexChanged event is firing on every postback, irrespective of
whether or not the button or the dropdown is used to invoke the postback.

I have a guess at the reason for this - during Init, when the dropdown is
instantiated, it's selectedIndex is 0. When LoadViewState does it's thing,
it's changing the selectedIndex to (whatever the user had selected) and this
triggers a SelectedIndexChanged event. (?)

If that's correct, then I thought I'd resolve it one of two ways - either
check the viewstate of the dropdown against it's selectedindex/value and use
that as a way to determine if the combo "really" had it's index changed
(i.e. by the user) or, maybe obtain the viewstate data and assign the
selected index prior to loadViewState happening.

Both of those methods have been shot down due to the fact that ViewState is
nothing at all points of the lifecycle I can think of to check it. Init,
Load, PreRender, LoadViewState - It's always nothing.

But the application *is* restoring viewstate. If I override LoadViewState,
the savedState object is always nothing. So I don't understand how to read
the viewstate, aside the __VIEWSTATE in request.form, but that's not very
helpful to me. I expected to be able to access Me.ViewState(somekey) (or at
least maybe MyBase.ViewState(somekey)) but it's always empty. I don't
understand how the page is actually restoring it's viewstate, if it's always
empty to me? Confusing.
Nov 19 '05 #1
0 1271

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

Similar topics

0
by: Reinhard Vornholt | last post by:
Hi, I am trieing to save the complete viewstate of a page and restore it at a later point. That should work like this: - Someone leaves the page and switches to an other page in the same...
1
by: leal ting | last post by:
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList lealting@hotmail.com] the class inherited...
1
by: Marty U. | last post by:
Virus Scanning is causing our Sessions to drop and the application to restart. So my only solution is to utilize ViewState for about 3 small strings on each page in C#. However, I am not using VS...
4
by: BobRoyAce | last post by:
I have a C# ASP.NET page that I inherited which has two panels on it. It only ever shows one or the other. Initially, it shows panel one. Then, if the user clicks on a certain button, it ultimately...
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...
3
by: Jeff User | last post by:
Hello I am using C#, .net1.1 Vis Studio 2003 I am using homeBase.aspx.cs page as a base for several other aspx/aspx.cs web pages. The base page handles some operations that are common to all...
8
by: clintonG | last post by:
I've got a big fat cow -- a wiazrd control with 19 steps -- and I need to put Bessie back in the barn. I need to learn how to cache the Viewstate for this page and maintain state should the user...
9
by: Alexander van Doormalen | last post by:
I have a situation that user controls are dynamically loaded within a page. To know which control to 're-add' to the page I saved the control path in the ViewState. This Control is added using...
3
by: Mark B | last post by:
I have an MCMS website that I inherited. It was originally built in .NET 1.1 and then ported to .NET 2.0. They built it with inherited base classes to mimic what is now done with master pages. ...
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...
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
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
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...

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.