Problem with view state in an asp page.

  • Thread starter Thread starter Bren
  • Start date Start date
B

Bren

I am developing a web based app. in .net, with C# as the code
behind.the problem I am having is with view state for a page. the page
is capturing an event fired in an object. the event changes the
properties of various controls in the UI. the event is fired when the
user enters some info. on the page, initiating a post back etc.
However, when i test the page, the changes that should appear in the
UI don't happen. debugging through the code everything appears in
order - page loads, the event is captured and the properties are set
in the controls (which are labels). how ever, when you look at the
controls during pre-render the controls have their original values. if
I add code that adds proeprties to view state when the event fires,
when you try yo get these properties back during pre-render they are
null. it as if the page has locked view state, or is using the
original view state info. - either way the changes that should be
happening are ignored ....any ideas much appreciated.
 
Rajesh,

There isn't a whole lot of code involved but heres a snippet...

this code is in the aspx page. the page has an instance of an object
called salesOrderLine, which has an event EnquiryPropertyChanged. the
aspx page has an event handler added during load and has the follwing
delegate to handle the event....


private void salesOrderLine_EnquiryPropertiesChanged (object sender,
CustomEventArgs e)
{
this.labelEnquiry.Text = "Enquiry Changed";
this.labelSalesOrderUpdated = "Update Complete";
}

as you can see I am simply putting some simple text into two labels.
when you step through the code it runs fine, except that the text does
not appear in the UI. I put a debugger in the above event and also in
the OnPreRender event of the aspx page - when I look at the the two
labels
immediately after setting the text, their text properties show me the
correct thing - if I then look at the labels during prerender, they show
their text properties as empty, which was their default state..
 
I have a page with a button and a handler for its click event. I did exactly
what you described with 2 labels and viewstate and all is working as
expected. If your page is somewhat complex with other events and logic, I
suggest you create a simple web page like I did with only a button and 2
labels and see if you still get it.
 
Back
Top