Web User Controls

  • Thread starter Thread starter Luke Ward
  • Start date Start date
L

Luke Ward

Hi All

I created web user control that has a few properties and an Update method.
These controls all get initialised and configured (all properties set) at
the page load event.

Today I included an if(!this.IsPostBack) {} around the initialisation code,
so that if an error occurred when the user was trying to update the
database, I could send them back with all their amended data in tact (not
the data back from database).

Now, when I try to update the page, my user controls still exist, but their
properties are no longer set!! Is there a way around this, I'm new to .Net
and may just be taking the wrong train of thought.

Any advice would be greatly appreciated.

Many Thanks

Luke
 
Luke said:
Hi All

I created web user control that has a few properties and an Update
method. These controls all get initialised and configured (all
properties set) at the page load event.

Today I included an if(!this.IsPostBack) {} around the initialisation
code, so that if an error occurred when the user was trying to update
the database, I could send them back with all their amended data in
tact (not the data back from database).

Now, when I try to update the page, my user controls still exist, but
their properties are no longer set!! Is there a way around this, I'm
new to .Net and may just be taking the wrong train of thought.

Any advice would be greatly appreciated.

My question to you is what mechanism are you using to repopulate the data
back into the controls after an update, either successful or failure. I
would guess that on a successful update you would want to initialise the
page as you do on first load so that any data that might have been modified
by triggers or other actions on the database would be retrieved. If that's
the case, you're initialise code needs to be enhanced slightly so that in
the else of your if(!IsPostBack) you still reload the control data from the
database if the update were successful.

Also in the else, you need to decide how you want to reload the controls
with the user input data if the update failed. You can use one of the built
in mechanisms such as viewstate or you can write your own.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
Thanks Tom

You guess right, on success I can reload the page as first load, on failure
I want to preserve the page and user entered data. So I suppose I just need
to reset all the properties of my user controls on failure or success, I
just thought they would stay set for some reason.

Thanks

Luke
 
Back
Top