Ah, I see your issue now. You are definately dealing with a timing issue.
My suggestion would be to try creating an event handler for the Load event of
the user control from the parent page. You know that the view state
information has been updated at that point. Check out this list of events in
order of execution (taken from someone else):
1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDatahandler.LoadPostdata)
6. Load
7. Load postback data for dynamical controls added on Page_Load
8. Raise Changed Events (postback, IPostBackDatahandler.RaisePostDataChanged)
9. Raise postback event (postback, IPostBackEventHandler.RaisePostBackEvent)
10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose
If you create an event handler in the main page for the Load event, you
could then call the SaveData function at that time and you should have the
updated information. An example of this event declaration would look like:
myControl.Load += new System.EventHandler(this.Control_Load);
As a separate suggestion, when loading the user control dynamically, perhaps
set some sort of flag (property, variable, etc) in the user control. Then in
the Load event of the user control, check for the flag and process
accordingly.
Let me know if this doesn't cover it for you.
Ian Suttle
http://www.NewsFuel.com
"Anders K. Jacobsen [DK]" wrote:
Sorry for not being more specific the first time.
No problem!
You may be attempting to access the user control data before the viewstate
information has been updated to the controls. If this were the case, you
would get the default values of the user control instead of the updated
input.
Ok
To ensure that your timing is correct, add an event handler to the main
page
that subscribes to the user control's save button (you may have to declare
the button in the control as public). The code would resemble the
following:
But. Mu user control dont have a save button. The problem is that they are
self contained. Each usercontrol fetch its own data from a datastore into
its textboxes. Now. if the user presses the one and only save button on the
mainform (where the usercontrols are added to) i need to comunicate to the
usercontrol ( by its public SaveData() method ). My problem is. If I held
the references to the usercontrol in an arrayList of usercontrols references
(In a session var )and called these on OnSaveClick, so when debugging its
textbox value was not updated. Maybe because of the viewstate problem you
refered to.
But again. the save button is the main page which has the placeholder which
has the usercontrols.
Thanks for your time until now!
Anders, Denmark
this.userControlName.btnSave.Click += new
System.EventHandler(this.handleSaveClick);
With this example, the parent page has a function called handleSaveClick
that will get called when the user control's save button is clicked. You
can
then access the information in the user control at the proper time.
If this is still a bit confusing, don't feel bad. Let me know if you
require further explanation.
Thanks,
Ian Suttle
http://www.IanSuttle.com
http://www.NewsFuel.com - Aggregated Technology News
"Anders K. Jacobsen [DK]" wrote:
> You are most likely accessing the control too early. I would suggest
> tracing out when your controls are loaded and when you are attempting
> to
> access the data within. You may need to create some sort of event to
> notify
> the observer that the data has been loaded.
Im not quite sure i follow. To recap.
I have my main page. To this i add usercontrols which contains textboxes
with initial values. Now user changes these values in the usercontrols
which
was added to the mainpage through a placeholder.
Now the user push a save button on the main page.
1. How do a GET the reference to these usercontrols?
2. Reagarding that i access the usercontrol before load. The usercontrols
are loaded correctly, and I guess the new values in the usercontrols
textboxes should be available in alle events on the mainpage...right?
Anders