468,765 Members | 1,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

FormView and ObjectDataSource events

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
Mar 19 '07 #1
2 1962
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 (wa****@online.microsoft.com, 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.

Mar 20 '07 #2
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 (wa****@online.microsoft.com, 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.

Mar 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by ThePurpleCat | last post: by
reply views Thread by =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post: by
8 posts views Thread by =?Utf-8?B?QXNo?= | last post: by
6 posts views Thread by Chris | last post: by
5 posts views Thread by =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.