473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ObjectDataSource OnSelected event raised twice

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 '07 #1
4 4463
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

Jul 10 '07 #2

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 '07 #3
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:

<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
Jul 11 '07 #4
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 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press...
5
by: Ole M | last post by:
I'm having some trouble using the ObjectDataSource in ASP.NET 2.0. I have a wrapper that contains the static methods for Select and Update. The Update-method takes the business object as...
3
by: CWWong | last post by:
I am using DetailsView using ObjectDataSource with DataSourceTypeName assigned to the specific class. SelectMethod, UpdateMethod and DeleteMethod is working successfully, except InsertMethod. The...
9
by: J055 | last post by:
Hi I'm trying to get an instance of UserLists to persist after it's been used by the GridView. I understand from the documentation that The OnObjectCreated event allows access to the instance. I...
0
by: Dan Sikorsky | last post by:
I'm using a stored procedure as the select command for an SqlDataSource tied to a GridView. I've verified the sp returns rows in the Management Studio as well as in VS2005 when I Configure the...
10
by: J055 | last post by:
Hi I've been trying out SqlCacheDependency using the ObjectDataSource and SQL Server 2005. It all works quite well with the minimum of configuration, e.g. <asp:ObjectDataSource...
4
by: Samuel Shulman | last post by:
Hi Can anyone explain why the Load Even is raised twice in the web page? What can be done to avoid it? Thanks, Samuel
3
by: KaOne | last post by:
Hi All, excuse me in advance for my not very perfect english. I need some help about a problem with a FormView bounded to an ObjectDataSource. In practise I have an ObjectDataSource that uses some...
4
by: TarTar | last post by:
Hello, I have already posted this problem, but I have not received any response yet. I will try to describe it again. We have a list control (e.g. DataList) and an ObjectDataSource on an...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.