Viewstate : Comparing a controls previous value to it's new value

I'd like to compare the original values of a pages web controls to their new values upon postback.

The problem is I can't seem to get any values from viewstate.

for example some psudocode;

sub pageinit()

myVar = cint(viewstate("dropdownListcontrolID"))
myvar2 = cint(viewstate("textBoxControLID"))

end sub

This doesn't error out, but all values = 1, which cannot be the case. I must be missing something. Viewstate seems like the most logical place to look for the controls previous values. Or do you recommend I do it a different way? thanks rc
0
robertc
2/28/2009 10:06:32 PM
asp.net.state-management 8807 articles. 0 followers. Follow

2 Replies
1204 Views

Similar Articles

[PageSpeed] 15

Not familiar with VB, but if you're trying to access viewstate in Page_Init it won't work because loading of viewstate occurs after the init event.  You can try perhaps in Page_Load instead.


C# <---> VB.Net Translator
0
MetalAsp
3/1/2009 6:02:01 PM

In OnInit event the ViewState is not available because the LoadViewState occurs after the page's Init event. Refer Page lifecycle



My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
0
budugu
3/1/2009 6:11:49 PM
Reply:

Similar Artilces:

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to asp.net i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.http://www.heliosfx.com...

Default value for Dropdownlist that get's it's value from Database.
Hi, I am using an Object Data Souce to retrieve the value of a Dropdownlist from a table on MS SQL server 2005. I want to make a default value appear on the Dropdownlist intially, should i enter the default value into the database table or is that a better way of doing it? Any suggestions will be very much appreciated. E  No need for database just set sekected value after databingind protected void Page_Load(object sender, EventArgs e) { DataBind(); ListItem defaultItem = new ListItem("Select a Person", "-1"); th...

Control's (object's) default value??
How or where can I see an asp.net control's default value? Say, for example the Visible property for webcontrols? Would be preferable if I could quickly see it in Visual Web Developer but MSDN online documentation would also be nice. Also how can I do this in general for all .Net objects?...

why a string column with a '' value synchronize from ASE to ASA, in ASA it's value become ' ' with a blank in it?
"darcy.zhai" <zhaizy@e-future.com.cn> wrote in news:43967064@forums-2-dub of sybase.public.sqlanywhere.mobilink: Please try to ask your question in the _body_ of the post, not the subject line. There are many people that never really look at the subject line (like myself most of the time). > why a string column with a '' value synchronize from ASE to ASA, in > ASA it's value become ' ' with a blank in it? This has to do with nullability. First, connect to ASE via ISQL and try the same query ML is executing. What is returned? An...

obtain ANY control's (textbox/dropdown) value in GridView's HeaderTemplate
Given this templated GridView column containing either Textbox's or DropDownLists......          <asp:TemplateField >              <HeaderTemplate>                      <asp:TextBox ID="TextBoxWellName" runat="server"  Visible="False" l"></asp:TextBox>           &nb...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

ObjectDataSource 'odsUser' has no values to insert. Check that the 'values' dictionary contains values
Hi All! I am currently trying to pull 2 values from two different sources (Details View & a Session) to use in a Stored Proceedure.  I have spent quite a bit of time trying to determine what is occuring without any luck. However, by the Subject Line you can tell that it's not getting anything for some reason?  Here are the components:Object Datasource:<asp:ObjectDataSource ID="odsUser" runat="server" DataObjectTypeName="System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=************]]"DeleteMethod="RemoveEnrollment...

Session and View state values are changed: mixed with simultaneous users' session and viewstate values.
I have developed one aspx page(c#) that includes 7pages of the input form: each page is surrounded with panel control. It will be hidden or shown depending on which page the user wants to go. There are several update panels that contain gridview controls on the page. The source of the gridview is session value (arrayList). Whenever the page is postbacked by clicking previous and next buttons to show a certain page and hide other page panels, or adding new list data into the arrayList of the session value ( the value is retrieved on the pertaining gridview), the session and server control val...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

Can a User Control's Page_Load retrieve a value set in the parent's Page_Load?
I want to use a control to perform a specific task, but I want it to vary based on the page it is on. I was hoping to set a value in the Page_Load event of the Parent, and have that value retrieved by the Page_Load event of the user control. I am not sure what order these events fire in, Can I be certain that the parent event will fire first?...

Help Me...How can i recovery my Control's value[viewstate] (about ITemplate)
, Hi , everyone... i got a problem, i write an control , the control allow user to use Tempalte mode to add any control to it(my designed-control), but i find a critical problem, any control that added in my control will lose it viewstate...it means that it can't recovery the pre-values. for example, if i add a button and a textbox controls to test Control. well, when i input some words to textbox, and then i click the button.......the textbox value will be clear.....??? how to keep control's value??? my test code is as following : ( I hope any one can help me, please.....thx) &...

How to get return value or output value after insert new record (Scott's tutor used BLL)
I ve created a DAL and BLL following Scott s tutorials and I don't know how to get return value or output value after insert new record.In Stored Procudure: INSERT INTO .... RETURN SCOPE_IDENTITY()or : I declare out put variable: @newRecordId INT OUTPUTthen at the end SP: SET @newRecordId = SCOPE_IDENTITY()in the BLL, I have used addnew function following the Scott' tutor.But I don't know how to get newRecordId.Someone can help me,Thank a lot   Here's an example for you: ASPX <asp:detailsview id="dvSuppliers" runat="server" autogenerat...

Meke Control's property disabled or enabled based on another property's entered value ?
Does anyone know how to disable or enable a property in properties window based on value entered in another property?Please advise.Regards,Dimitry...

Changing control's selected value with viewstate before page is delivered back
This should be an easy thing to do, but I have yet to make anything work. I have three dropdown lists. Each one is a different method for searching a database, such as color, size, type.. A user selects a dropdown (say color) and selects a value from that dropdown (say red) and a OnSelectedIndexChanged fires and autopostback's to do the search and return the results. All this works fine except that when the results return the dropdown used shows the value the user selected (red). I want any dropdown used to be reset to the "first time loaded" value of  "select". I've tried to...