FormView and ObjectDataSource events

Discussion in 'ASP .Net' started by J055, Mar 19, 2007.

  1. J055

    J055 Guest

    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
     
    J055, Mar 19, 2007
    #1
    1. Advertising

  2. 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 (, 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.
     
    Walter Wang [MSFT], Mar 20, 2007
    #2
    1. Advertising

  3. 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 (, 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.
     
    Walter Wang [MSFT], Mar 22, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    FormView and ObjectDataSource - Delete doesn't work

    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jun 3, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    4,364
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=
    Jun 3, 2005
  2. Pao
    Replies:
    1
    Views:
    423
  3. Chris
    Replies:
    5
    Views:
    507
    Jon Paal [MSMD]
    Mar 31, 2007
  4. KaOne
    Replies:
    3
    Views:
    698
    Steven Cheng[MSFT]
    Jun 20, 2007
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    375
    Chris
    Aug 30, 2005
Loading...

Share This Page