onItemDataBound event not firing on first go thru since moving to .net 2.0

Discussion in 'ASP .Net' started by TS, Nov 27, 2006.

  1. TS

    TS Guest

    I have this custom data list control and i override the onItemDatabound
    event. After upgrading to vs 2005, this event is not always getting called,
    though it does at other times. No changes were made when upgrading to 2.0

    is there any reason for this because of .net 2.0?

    thanks
    TS, Nov 27, 2006
    #1
    1. Advertising

  2. TS

    Eric Guest

    What type of control is this? In general, I think the event is
    ataBound in .NET 2.0.

    TS wrote:
    > I have this custom data list control and i override the onItemDatabound
    > event. After upgrading to vs 2005, this event is not always getting called,
    > though it does at other times. No changes were made when upgrading to 2.0
    >
    > is there any reason for this because of .net 2.0?
    >
    > thanks
    Eric, Nov 27, 2006
    #2
    1. Advertising

  3. TS

    TS Guest

    it is a control that inherits from DataList. The databinding does occur
    after the page has posted back in some other parts of code - which correctly
    calls the onDataBound event.

    Also, this code worked correctly in 1.x but now fails.

    thanks!

    "Eric" <> wrote in message
    news:...
    > What type of control is this? In general, I think the event is
    > ataBound in .NET 2.0.
    >
    > TS wrote:
    >> I have this custom data list control and i override the onItemDatabound
    >> event. After upgrading to vs 2005, this event is not always getting
    >> called,
    >> though it does at other times. No changes were made when upgrading to 2.0
    >>
    >> is there any reason for this because of .net 2.0?
    >>
    >> thanks

    >
    TS, Nov 27, 2006
    #3
  4. TS

    TS Guest

    Also Why is it that this custom dataList of mine calls DataBind()
    automatically (i know this because when my itemDataBound event runs, it runs
    twice when i manually call DataBind())?

    I also have a regular dataGrid on the page, but if i dont' set DAtaBind()
    for it, it won't bind itself. Since DataList and DataGrid both inherit from
    BAseDataList, i would expect both to either call databind() automatically or
    not at all.

    Whats the deal here?

    thanks

    "TS" <> wrote in message
    news:%...
    >I have this custom data list control and i override the onItemDatabound
    >event. After upgrading to vs 2005, this event is not always getting called,
    >though it does at other times. No changes were made when upgrading to 2.0
    >
    > is there any reason for this because of .net 2.0?
    >
    > thanks
    >
    TS, Nov 27, 2006
    #4
  5. TS

    TS Guest

    I have been looking at
    http://msdn2.microsoft.com/en-us/library/aa479321.aspx but it doesn't
    mention the base class for DataList, BaseDataList. Am i to assume that the
    topics in this article don't relate to DAtaList or DataGrid (both inherit
    from BaseDataList)?

    thanks

    "TS" <> wrote in message
    news:%...
    >I have this custom data list control and i override the onItemDatabound
    >event. After upgrading to vs 2005, this event is not always getting called,
    >though it does at other times. No changes were made when upgrading to 2.0
    >
    > is there any reason for this because of .net 2.0?
    >
    > thanks
    >
    TS, Nov 27, 2006
    #5
  6. TS

    TS Guest

    actually i think that it doesn't call DataBind() automatically, i found a
    spot that was calling it anyways.


    "TS" <> wrote in message
    news:ug5LL%...
    > Also Why is it that this custom dataList of mine calls DataBind()
    > automatically (i know this because when my itemDataBound event runs, it
    > runs twice when i manually call DataBind())?
    >
    > I also have a regular dataGrid on the page, but if i dont' set DAtaBind()
    > for it, it won't bind itself. Since DataList and DataGrid both inherit
    > from BAseDataList, i would expect both to either call databind()
    > automatically or not at all.
    >
    > Whats the deal here?
    >
    > thanks
    >
    > "TS" <> wrote in message
    > news:%...
    >>I have this custom data list control and i override the onItemDatabound
    >>event. After upgrading to vs 2005, this event is not always getting
    >>called, though it does at other times. No changes were made when upgrading
    >>to 2.0
    >>
    >> is there any reason for this because of .net 2.0?
    >>
    >> thanks
    >>

    >
    >
    TS, Nov 28, 2006
    #6
  7. TS

    Eric Guest

    If a control has a DataSource, DataBind will automatically be called.
    I'm not sure if this is the case for you or not.

    Are you using .NET 1.1 or 2.0? It sounds like you're still using 1.1.
    2.0 doesn't have the DataGrid control (it has been replaced with the
    GridView) and the onItemDatabound event is generally called DataBound.

    TS wrote:
    > actually i think that it doesn't call DataBind() automatically, i found a
    > spot that was calling it anyways.
    >
    >
    > "TS" <> wrote in message
    > news:ug5LL%...
    > > Also Why is it that this custom dataList of mine calls DataBind()
    > > automatically (i know this because when my itemDataBound event runs, it
    > > runs twice when i manually call DataBind())?
    > >
    > > I also have a regular dataGrid on the page, but if i dont' set DAtaBind()
    > > for it, it won't bind itself. Since DataList and DataGrid both inherit
    > > from BAseDataList, i would expect both to either call databind()
    > > automatically or not at all.
    > >
    > > Whats the deal here?
    > >
    > > thanks
    > >
    > > "TS" <> wrote in message
    > > news:%...
    > >>I have this custom data list control and i override the onItemDatabound
    > >>event. After upgrading to vs 2005, this event is not always getting
    > >>called, though it does at other times. No changes were made when upgrading
    > >>to 2.0
    > >>
    > >> is there any reason for this because of .net 2.0?
    > >>
    > >> thanks
    > >>

    > >
    > >
    Eric, Nov 28, 2006
    #7
  8. Although it's recommended to use GridView in 2.0, DataGrid is still
    supported in 2.0. It's actually improved to support a new way of
    databinding that using DataSource control.

    When you're using declarative way to set the DataSourceID property of a
    data-bound control, you don't have to call DataBind() manually; but you
    have to call DataBind() if you're setting DataSource property in code.

    TS, would you please post some code of your DataList inherited control?
    Thanks.


    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Nov 28, 2006
    #8
  9. TS

    TS Guest

    to re-iterate, after the first time the databind event occurs during a
    postback, it fails. The second time and every time after that, you postback
    and call it and it works.

    "TS" <> wrote in message
    news:%...
    >i have attached the code and this is the method that binds it:
    > private void LoadReport()
    > {
    > this.report = new Report(GetReportXmlDocument(), mReportName, "table",
    > "TEA");
    > this.rplCriteria.ControlsAssemblyFile =
    > this.report.BaseControlAssemblyFile;
    > this.rplCriteria.DataSource = this.report.Parameters;
    > this.rplCriteria.DataBind();
    >
    > // If the report contains no control parameters & not initial page load,
    > go straight to the report viewer
    > if (this.rplCriteria.Items.Count == 0 && IsPostBack){
    > RunReport();
    > }
    > else{
    > this.lblReportTitle.Text = this.report.Title;
    > }
    > }
    >
    > every time when it goes to bind, its data source has items. The first or
    > second time the page posts back, the onItemDataBound event won't fire,
    > after that it does. Again, the datasource is the same always, and the code
    > worked correctly in 1.x.
    >
    > thanks!
    >
    > "Walter Wang [MSFT]" <> wrote in message
    > news:...
    >> Although it's recommended to use GridView in 2.0, DataGrid is still
    >> supported in 2.0. It's actually improved to support a new way of
    >> databinding that using DataSource control.
    >>
    >> When you're using declarative way to set the DataSourceID property of a
    >> data-bound control, you don't have to call DataBind() manually; but you
    >> have to call DataBind() if you're setting DataSource property in code.
    >>
    >> TS, would you please post some code of your DataList inherited control?
    >> Thanks.
    >>
    >>
    >> Sincerely,
    >> Walter Wang (, remove 'online.')
    >> Microsoft Online Community Support
    >>
    >> ==================================================
    >> Get notification to my posts through email? Please refer to
    >> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    >> ications. If you are using Outlook Express, please make sure you clear
    >> the
    >> check box "Tools/Options/Read: Get 300 headers at a time" to see your
    >> reply
    >> promptly.
    >>
    >> Note: The MSDN Managed Newsgroup support offering is for non-urgent
    >> issues
    >> where an initial response from the community or a Microsoft Support
    >> Engineer within 1 business day is acceptable. Please note that each
    >> follow
    >> up response may take approximately 2 business days as the support
    >> professional working with you may need further investigation to reach the
    >> most efficient resolution. The offering is not appropriate for situations
    >> that require urgent, real-time or phone-based interactions or complex
    >> project analysis and dump analysis issues. Issues of this nature are best
    >> handled working with a dedicated Microsoft Support Engineer by contacting
    >> Microsoft Customer Support Services (CSS) at
    >> http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >> ==================================================
    >>
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >>

    >
    >
    >
    TS, Nov 28, 2006
    #9
  10. TS

    TS Guest

    OK the way the page is set up, initial page load occurs then a postback
    occurs which calls the databind. If I put a call to databind during initial
    page load, the itemDataBound event is called correctly. For some reason the
    intial call to databind when called during the 1st postback is causing
    problems.

    One other thing to keep in mind is that for some reason the page_load &
    page_pre_render are running twice (probably all the page's events). The page
    load runs twice, then pre-render runs twice in that exact order, so it
    DOESNT' do a load-->pre-render-->Load-->pre-render. IT DOES
    load-->load-->pre-render-->pre-render. I am attaching the stack track to
    show you the difference comparing the 1st load to the 2nd load which both
    occur on a single request for the page.

    I have verified that this does not happen in VS 2003 with the same page and
    i can find no other pages in vs 2005 that have their load event run twice.
    This page is identical except for vs 2005 specific revisions which don't
    change anything. This page does have a base class, but its load event only
    runs ONCE!

    When I put a call to databind during initial page load, the itemDataBound
    event is called correctly for both page posts.

    If you think double events firing is unrelated to our issue then no
    investigation is required.

    Thanks!

    "TS" <> wrote in message
    news:...
    > to re-iterate, after the first time the databind event occurs during a
    > postback, it fails. The second time and every time after that, you
    > postback
    > and call it and it works.
    >
    > "TS" <> wrote in message
    > news:%...
    >>i have attached the code and this is the method that binds it:
    >> private void LoadReport()
    >> {
    >> this.report = new Report(GetReportXmlDocument(), mReportName, "table",
    >> "TEA");
    >> this.rplCriteria.ControlsAssemblyFile =
    >> this.report.BaseControlAssemblyFile;
    >> this.rplCriteria.DataSource = this.report.Parameters;
    >> this.rplCriteria.DataBind();
    >>
    >> // If the report contains no control parameters & not initial page load,
    >> go straight to the report viewer
    >> if (this.rplCriteria.Items.Count == 0 && IsPostBack){
    >> RunReport();
    >> }
    >> else{
    >> this.lblReportTitle.Text = this.report.Title;
    >> }
    >> }
    >>
    >> every time when it goes to bind, its data source has items. The first or
    >> second time the page posts back, the onItemDataBound event won't fire,
    >> after that it does. Again, the datasource is the same always, and the
    >> code
    >> worked correctly in 1.x.
    >>
    >> thanks!
    >>
    >> "Walter Wang [MSFT]" <> wrote in message
    >> news:...
    >>> Although it's recommended to use GridView in 2.0, DataGrid is still
    >>> supported in 2.0. It's actually improved to support a new way of
    >>> databinding that using DataSource control.
    >>>
    >>> When you're using declarative way to set the DataSourceID property of a
    >>> data-bound control, you don't have to call DataBind() manually; but you
    >>> have to call DataBind() if you're setting DataSource property in code.
    >>>
    >>> TS, would you please post some code of your DataList inherited control?
    >>> Thanks.
    >>>
    >>>
    >>> Sincerely,
    >>> Walter Wang (, remove 'online.')
    >>> Microsoft Online Community Support
    >>>
    >>> ==================================================
    >>> Get notification to my posts through email? Please refer to
    >>> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    >>> ications. If you are using Outlook Express, please make sure you clear
    >>> the
    >>> check box "Tools/Options/Read: Get 300 headers at a time" to see your
    >>> reply
    >>> promptly.
    >>>
    >>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
    >>> issues
    >>> where an initial response from the community or a Microsoft Support
    >>> Engineer within 1 business day is acceptable. Please note that each
    >>> follow
    >>> up response may take approximately 2 business days as the support
    >>> professional working with you may need further investigation to reach
    >>> the
    >>> most efficient resolution. The offering is not appropriate for
    >>> situations
    >>> that require urgent, real-time or phone-based interactions or complex
    >>> project analysis and dump analysis issues. Issues of this nature are
    >>> best
    >>> handled working with a dedicated Microsoft Support Engineer by
    >>> contacting
    >>> Microsoft Customer Support Services (CSS) at
    >>> http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >>> ==================================================
    >>>
    >>> This posting is provided "AS IS" with no warranties, and confers no
    >>> rights.
    >>>

    >>
    >>
    >>

    >
    >
    TS, Nov 28, 2006
    #10
  11. Hi TS,

    Thanks for your detailed description. Based on my understanding, the
    initial issue you mentioned about your control's OnItemDataBound event is
    actually caused by the whole page's events will be fired twice?

    Since I have difficulty to run your attached code (it's not complete and
    doesn't have a webform to test the issue), I'm afraid I cannot tell what
    went wrong exactly. Is it possible for you to create a small but complete
    web site project which can reproduce the issue you described? Thank you
    very much for your effort.

    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], Nov 29, 2006
    #11
  12. TS

    TS Guest

    i'll try to get to that in a day or 2.

    What could be a reason for each of the page's events firing twice each in a
    row (remember that it goes Load->Load->Render->Render and NOT
    Load->render->Load->Render)

    thanks

    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi TS,
    >
    > Thanks for your detailed description. Based on my understanding, the
    > initial issue you mentioned about your control's OnItemDataBound event is
    > actually caused by the whole page's events will be fired twice?
    >
    > Since I have difficulty to run your attached code (it's not complete and
    > doesn't have a webform to test the issue), I'm afraid I cannot tell what
    > went wrong exactly. Is it possible for you to create a small but complete
    > web site project which can reproduce the issue you described? Thank you
    > very much for your effort.
    >
    > 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.
    >
    TS, Dec 1, 2006
    #12
  13. One possible cause is registering the same event handler twice.

    Anyway, let's see if it can be reproduced easily.

    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], Dec 1, 2006
    #13
  14. Re: onItemDataBound event not firing on first go thru since moving to .net 2.0 WebApplicationTest.zip [1/2]

    Hi,

    It seems the attached file is corrupt. Would you please send it again to me
    via email? 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], Dec 8, 2006
    #14
  15. TS

    TS Guest

    We took this offline and it is now fixed. The below answer will explain why
    the onItemDataBound event was not getting called consistently - deals with
    new data binding model of .net 2.x:

    I had to add a line of code to also set base.DataSource when I was
    overriding the implementation because BaseDataList.DataSource's Setter
    changes an internal flag: "this.RequiresDataBinding = true"; this is a
    important flag to let the engine know that this control will do the
    databinding. I think this is one important change from 1.1 to 2.0 since it
    needs to add support for data source controls (declarative data binding via
    DataSourceID).

    "TS" <> wrote in message
    news:%...
    >I have this custom data list control and i override the onItemDatabound
    >event. After upgrading to vs 2005, this event is not always getting called,
    >though it does at other times. No changes were made when upgrading to 2.0
    >
    > is there any reason for this because of .net 2.0?
    >
    > thanks
    >
    TS, Dec 12, 2006
    #15
    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?ZGFuYw==?=

    DataGrid ItemCommand event not firing if not first page

    =?Utf-8?B?ZGFuYw==?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,148
    =?Utf-8?B?ZGFuYw==?=
    Oct 26, 2005
  2. GOKU24

    OnItemDataBound event not firing

    GOKU24, Jul 8, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    158
    GOKU24
    Jul 8, 2003
  3. THTB
    Replies:
    0
    Views:
    182
  4. Max Williams
    Replies:
    3
    Views:
    166
    Robert Klemme
    Jan 6, 2009
  5. Mista_Blista
    Replies:
    2
    Views:
    132
    Mista_Blista
    Feb 26, 2004
Loading...

Share This Page