Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ObjectDataSource OnSelected event raised twice

Reply
Thread Tools

ObjectDataSource OnSelected event raised twice

 
 
chris.c.woodward@gmail.com
Guest
Posts: n/a
 
      07-10-2007
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?

 
Reply With Quote
 
 
 
 
nahid
Guest
Posts: n/a
 
      07-10-2007
On Jul 10, 8:25 pm, chris.c.woodw...@gmail.com 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

 
Reply With Quote
 
 
 
 
chris.c.woodward@gmail.com
Guest
Posts: n/a
 
      07-11-2007

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:

<aspataList ID="dlCatalogues" runat="server"
DataSourceID="odsCatalogues" EnableViewState="false">

...

</aspataList>

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

<asp:QueryStringParameter ... /
>

<asp:QueryStringParameter ... /
>

<asp:QueryStringParameter ... /
>

<asparameter ... />
</SelectParameters>
</asp:ObjectDataSource>

 
Reply With Quote
 
nahid
Guest
Posts: n/a
 
      07-11-2007
On Jul 11, 2:35 pm, chris.c.woodw...@gmail.com 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:
>
> <aspataList ID="dlCatalogues" runat="server"
> DataSourceID="odsCatalogues" EnableViewState="false">
>
> ...
>
> </aspataList>
>
> <asp:ObjectDataSource ID="odsCatalogues" runat="server"
> SelectMethod="SelectCatalogues" TypeName="AGT.Business.EventDB"
> OnSelected="odsCatalogues_Selected"
> OnSelecting="odsCatalogues_Selecting">
> <SelectParameters>
> <asparameter ... />
> <asp:ControlParameter ... /
>
> <asp:QueryStringParameter ... /
>
> <asp:QueryStringParameter ... /
>
> <asp:QueryStringParameter ... /
>
> <asparameter ... />
> </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


 
Reply With Quote
 
chris.c.woodward@gmail.com
Guest
Posts: n/a
 
      07-11-2007
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:

<asparameter 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.



 
Reply With Quote
 
pholly pholly is offline
Junior Member
Join Date: Dec 2008
Posts: 1
 
      12-03-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Annoying problem with event being raised twice Bieniu ASP .Net 0 04-18-2008 03:51 PM
Load Event is Raised Twice Samuel Shulman ASP .Net 4 01-22-2007 03:42 PM
SqlDataSource OnSelected Event Not Firing =?Utf-8?B?RGFuIFNpa29yc2t5?= ASP .Net 1 08-23-2006 02:07 PM
ObjectDataSource method as another ObjectDataSource David Thielen ASP .Net Web Controls 3 03-23-2006 01:50 AM
ItemDataBound Event - How to access the previous record when this event is raised in DataGrid? NH ASP .Net Datagrid Control 2 12-17-2004 03:58 PM



Advertisments