473,805 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I get viewstate data during Page.OnInit

Hi,

I'm round-tripping some values my page requires using hidden form fields -
my page class requires these values in its OnInit event.

I would like to be able to use viewstate to do this - however the load
viewstate does not happen until after OnInit and before OnLoad.

Is there anything I can do to make the viewstate data available for my
OnInit code. Any pointers to examples gratefully accepted.

Thanks

Donal
Nov 18 '05 #1
7 8550
Donal,
As you stated, viewstate reloads after OnInit and before the Load event.
Because of this, viewstate will never be available in the OnInit phase. Any
code that depends on viewstate must execute after viewstate is loaded. You
must code your page around this requirement.

Best regards,
Jeffrey Palermo

"Donal McWeeney" <ma****@newsgro up.nospam> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Hi,

I'm round-tripping some values my page requires using hidden form fields -
my page class requires these values in its OnInit event.

I would like to be able to use viewstate to do this - however the load
viewstate does not happen until after OnInit and before OnLoad.

Is there anything I can do to make the viewstate data available for my
OnInit code. Any pointers to examples gratefully accepted.

Thanks

Donal

Nov 18 '05 #2
Hi Donal,

I think Jeffery's suggestion is reasonable since the LoadViewState occurs
after the page's Init event and can't be manually changed. Also, as the
asp.net Page's ViewState is based on the normal html input hidden field(
<input type="hidden" name="__VIEWSTA TE"
value="fjk43j53 kj43mefdSds/jfdsjfksdfdsm-" /> ) , if you do need to store
some custom datas in page and be retrieved in the sequential request before
the page's LoadViewSTate, I suggest you try putting some <input
type="hidden" ..> elements on the page and store datas in it. How do you
think ?
If there's any other questions, please feel free to post here. Thanks.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Thanks for the confirmation guys...

Thanks

Donal
Nov 18 '05 #4
"Donal McWeeney" <ma****@newsgro up.nospam> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Hi,

I'm round-tripping some values my page requires using hidden form fields -
my page class requires these values in its OnInit event.

I would like to be able to use viewstate to do this - however the load
viewstate does not happen until after OnInit and before OnLoad.


Why not just put the values in your own hidden form fields and read the
values in OnInit? Put them into an HtmlHidden control. No ViewState
involved.

John Saunders
Nov 18 '05 #5
You're welcome, Donal.

Nov 18 '05 #6
Thanks John,

Thats what I am doing at the moment - just thought that ViewState would be
cleaner.

Thanks

Donal

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:Ok******** *****@TK2MSFTNG P14.phx.gbl...
"Donal McWeeney" <ma****@newsgro up.nospam> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Hi,

I'm round-tripping some values my page requires using hidden form
fields - my page class requires these values in its OnInit event.

I would like to be able to use viewstate to do this - however the load
viewstate does not happen until after OnInit and before OnLoad.


Why not just put the values in your own hidden form fields and read the
values in OnInit? Put them into an HtmlHidden control. No ViewState
involved.

John Saunders

Nov 18 '05 #7
"Donal McWeeney" <ma****@newsgro up.nospam> wrote in message
news:u1******** ********@tk2msf tngp13.phx.gbl. ..
Thanks John,

Thats what I am doing at the moment - just thought that ViewState would be
cleaner.


It would be cleaner. Just not if you need it in OnInit...

Of course, if you're building custom controls, you can hide the ugliness
behind properties.

John Saunders
Nov 18 '05 #8

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

Similar topics

2
4892
by: theo | last post by:
Hi... I wish to extract the text content of an Xml file and assign it to DropDownList controls at runtime.I can get the Xml file text content into the DropDownList controls (Ex...if 5 Xml text tags then 5 dropdownlist controls each containing the 5 Xml text tags). Problem,when I save the user DropDownList selected items by means of a button click the web form looses the PlaceHolder viewstate and generates the following error..."Object...
9
21653
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
3
2654
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event and this causes control B to be created, when this is done the VIEWSTATE is lost for CONTROL B. In the EVENT that causes CONTROL B to be created I have to set
8
4283
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this...
2
3204
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp The problem I am having is that the data in the custom datagridcolumn is not saved to viewstate and after postback, the column does not contain data.
2
3042
by: Dave A | last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate. The drop down list is quite large so I would prefer to avoid using the view state so I set EnableViewState on the page to false. To enable the drop down list to bind to a datasource I bind it during the OnInit. I do a response.Write during the SelectedIndexChanged event to verify that the event fires. ...
6
2865
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in order for a dynamically created control to persist its state, it needs to be created and loaded into the page control hierarchy before the viewstate is loaded. The proposed solution, and that which I have been using, has been to create all of...
0
1901
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 is clicked the usercontrol raises an event indicating that the data in the database that relates to this user control is to be deleted.
2
11006
by: Rotsey | last post by:
Hi, I have a web site that uses user controls to display different formats of timesheets. I have a browse page that has prev/next buttons to browse through a set of timesheets. As I say they can be different user controls for each timesheet type.
0
9718
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
10363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
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
10107
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6876
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
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
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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.