ObjectDataSource OnSelected event raised twice

Discussion in 'ASP .Net' started by chris.c.woodward@gmail.com, Jul 10, 2007.

  1. Guest

    This event seems to be being raised twice in my codebehind. I have
    only one SelectMethod and do not have a SelectCountMethod. Its causing
    a problem because I'm dynamically loading a user control into a
    PlaceHolder control in the method and am having to do a check to see
    if it already exists or not otherwise it gets loaded twice. Also it
    would be nice to figure out what the heck is going on! Here is the
    code ...


    protected void odsCatalogues_Selected(object sender,
    ObjectDataSourceStatusEventArgs e)
    {
    Response.Write("event called");
    Response.Write("<br />");


    if (e.ReturnValue != null)
    {
    PagedDataSource pds = (PagedDataSource)e.ReturnValue;
    totalRowCount = pds.DataSourceCount;

    lblPageInfo.Text = totalRowCount + " records found. Page "
    + (pageIndex + 1) + " of " + pageCount;

    if (PlaceHolder1.Controls.Count == 0)
    {
    Control control1 = Page.LoadControl("~/UserControls/
    NumericPager.ascx");
    UserControls_NumericPager numericPager1 =
    (UserControls_NumericPager)control1;
    numericPager1.PageCount = pageCount;
    numericPager1.PageIndex = pageIndex;
    PlaceHolder1.Controls.Add(numericPager1);
    }
    }
    }


    Anybody got any ideas why this event is being called twice?
    , Jul 10, 2007
    #1
    1. Advertising

  2. nahid Guest

    On Jul 10, 8:25 pm, wrote:
    > This event seems to be being raised twice in my codebehind. I have
    > only one SelectMethod and do not have a SelectCountMethod. Its causing
    > a problem because I'm dynamically loading a user control into a
    > PlaceHolder control in the method and am having to do a check to see
    > if it already exists or not otherwise it gets loaded twice. Also it
    > would be nice to figure out what the heck is going on! Here is the
    > code ...
    >
    > protected void odsCatalogues_Selected(object sender,
    > ObjectDataSourceStatusEventArgs e)
    > {
    > Response.Write("event called");
    > Response.Write("<br />");
    >
    > if (e.ReturnValue != null)
    > {
    > PagedDataSource pds = (PagedDataSource)e.ReturnValue;
    > totalRowCount = pds.DataSourceCount;
    >
    > lblPageInfo.Text = totalRowCount + " records found. Page "
    > + (pageIndex + 1) + " of " + pageCount;
    >
    > if (PlaceHolder1.Controls.Count == 0)
    > {
    > Control control1 = Page.LoadControl("~/UserControls/
    > NumericPager.ascx");
    > UserControls_NumericPager numericPager1 =
    > (UserControls_NumericPager)control1;
    > numericPager1.PageCount = pageCount;
    > numericPager1.PageIndex = pageIndex;
    > PlaceHolder1.Controls.Add(numericPager1);
    > }
    > }
    > }
    >
    > Anybody got any ideas why this event is being called twice?


    can you pleasae provide some aditional code how do you bind the grid

    nahid
    http://nahidulkibria.blogspot.com/
    http://www.kaz.com.bd
    nahid, Jul 10, 2007
    #2
    1. Advertising

  3. Guest

    Thanks for your reply.

    I'm using a DataList bound to an ObjectDataSource. Here is the HTML
    markup in the relevant .aspx page with some code removed for clarity:

    <asp:DataList ID="dlCatalogues" runat="server"
    DataSourceID="odsCatalogues" EnableViewState="false">

    ...

    </asp:DataList>

    <asp:ObjectDataSource ID="odsCatalogues" runat="server"
    SelectMethod="SelectCatalogues" TypeName="AGT.Business.EventDB"
    OnSelected="odsCatalogues_Selected"
    OnSelecting="odsCatalogues_Selecting">
    <SelectParameters>
    <asp:parameter ... />
    <asp:ControlParameter ... /
    >

    <asp:QueryStringParameter ... /
    >

    <asp:QueryStringParameter ... /
    >

    <asp:QueryStringParameter ... /
    >

    <asp:parameter ... />
    </SelectParameters>
    </asp:ObjectDataSource>
    , Jul 11, 2007
    #3
  4. nahid Guest

    On Jul 11, 2:35 pm, wrote:
    > Thanks for your reply.
    >
    > I'm using a DataList bound to an ObjectDataSource. Here is the HTML
    > markup in the relevant .aspx page with some code removed for clarity:
    >
    > <asp:DataList ID="dlCatalogues" runat="server"
    > DataSourceID="odsCatalogues" EnableViewState="false">
    >
    > ...
    >
    > </asp:DataList>
    >
    > <asp:ObjectDataSource ID="odsCatalogues" runat="server"
    > SelectMethod="SelectCatalogues" TypeName="AGT.Business.EventDB"
    > OnSelected="odsCatalogues_Selected"
    > OnSelecting="odsCatalogues_Selecting">
    > <SelectParameters>
    > <asp:parameter ... />
    > <asp:ControlParameter ... /
    >
    > <asp:QueryStringParameter ... /
    >
    > <asp:QueryStringParameter ... /
    >
    > <asp:QueryStringParameter ... /
    >
    > <asp:parameter ... />
    > </SelectParameters>
    > </asp:ObjectDataSource>


    can you please check this post
    http://www.dotnetspider.com/qa/Question13248.aspx
    hope help

    nahid
    http://nahidulkibria.blogspot.com/
    http://www.kaz.com.bd
    nahid, Jul 11, 2007
    #4
  5. Guest

    Think I've figured out what was going on.

    The ObjectDataSource markup contained this line:

    <asp:ControlParameter DefaultValue="0" Name="clientId" Type="Int32"
    ControlID="DDList1" PropertyName="SelectedValue" />

    where DDList1 is actually a data driven UserControl I have created.

    Replacing the line with:

    <asp:parameter DefaultValue="0" Name="clientId" Type="Int32" />

    and setting the value in the ObjectDataSource Selecting event:

    protected void odsCatalogues_Selecting(object sender,
    ObjectDataSourceSelectingEventArgs e)
    {
    e.InputParameters["clientId"] =
    Convert.ToInt32(DDList1.SelectedValue);
    }

    meant that my DataList databinding was now not occurring twice.

    Still not sure why this should be but this work around has fixed it.

    :)
    , Jul 11, 2007
    #5
  6. pholly

    Joined:
    Dec 3, 2008
    Messages:
    1
    I know it's been over a year since this thread has been active, but I ran
    into a similar problem and after debugging found what the problem was.

    I had a DataList that was calling DataBind on it's objectDataSource twice.
    While debugging I found that the first call was happening because of code in
    the Master page of the page. We have a function called "FindControl" which
    recursively goes through all the controls on the page to find a specific
    control with a specified id. This function uses [control].Controls to
    recursively call. When the function got to the DataList, calling DataList1.
    Controls caused DataBind to occur and the Select function to get called.

    So the point is whenever DataList.Controls is called, it will try to fill in
    the DataItems. Doing so raises the DataBind event on the DataSource control.

    Hope this helps all those who are searching.
    Philip
    pholly, Dec 3, 2008
    #6
    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?RGFuIFNpa29yc2t5?=

    SqlDataSource OnSelected Event Not Firing

    =?Utf-8?B?RGFuIFNpa29yc2t5?=, Jul 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,071
    m.unterauer
    Aug 23, 2006
  2. Samuel Shulman

    Load Event is Raised Twice

    Samuel Shulman, Jan 22, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    342
    Samuel Shulman
    Jan 22, 2007
  3. Bieniu
    Replies:
    0
    Views:
    408
    Bieniu
    Apr 18, 2008
  4. NH
    Replies:
    2
    Views:
    527
    Andrew L. Van Slaars
    Dec 17, 2004
  5. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    241
    Steven Cheng[MSFT]
    Mar 23, 2006
Loading...

Share This Page