FormView and ObjectDataSource events

J

J055

Hi

I have 2 user controls and 1 parent page. One user control contains a
Gridview and the other a FormView. When the GridView row Select command is
fired it bubbles an event to the parent page with the primary key ID of the
row. The parent page sets a property with the ID in the second User control
(FormView) . The FormView then Binds to an ObjectDataSource to select the
record. I don't understand why the events occur as follows:

Begin PreRender
FormView_DataBound
ods_Selecting
ods_ObjectCreating
FormView_DataBound
End PreRender

The first FormView_DataBound is pointless because the ObjectDataSource
hasn't called the SelectMethod yet. What is the best way to handle this to
avoid errors? Why does this happen?

Also I understand the best way to notify the parent page is to raise an
event in the user control. What is the recommended way to notify a user
control that something has happened in the parent page?

Many thanks
Andrew
 
W

Walter Wang [MSFT]

Hi Andrew,

Are you binding the ObjectDataSource to the FormView via DataSourceID
property? According to ASP.NET Page Life Cycle Overview
(http://msdn2.microsoft.com/en-us/library/ms178472.aspx), during PreRender
event, each data bound control whose DataSourceID property is set calls its
DataBind method.

I think you might be able to create a private member variable in the
UserControl that contains the FormView to act as a flag: it's only set
after the ObjectDataSource's SelectMethod is called; then you check for
this flag in DataBound event.

For a (user) control, it's recommended to not to rely on the client (it's
the Page here). I think to notify the user control that something has
happened in the parent page, you call a public method or set a property in
the user control.

Anyway, would you please post more code if above suggestion doesn't apply
for your scenario or the issue is still not solved? Thanks.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Andrew,

I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top