469,648 Members | 1,413 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

AJAX + ObjectDataSource Refresh Issue

Tried this over in CSharp.General and didn't get anything, so I
thought I'd try again here. If there's an AJAX specific group I could
ask this in, please let me know...I did look.

I'm trying to code what I think is a fairly typical Master/Detail
scenario with two GridViews, using AJAX. Using the Northwind sample,
I have two ObjectDataSources - one which pulls data from the Orders
table, and one that pulls the related data from [Order Details].
Each
has a GridView, each on its own UpdatePanel.
According to timestamps I put on each update panel and the main page,
everything works as it should. The proper panels get refresh for
each
operation (selecting, paging, sorting on the Master GridView). So
why
am I bothering you if it works?
I coded a two second thread.sleep in the Details GridView's
ObjectDataSource to simulate heavy processing latency. Paging and
sorting the Master GridView work as expected - no sleeping - UNTIL I
select a record to show the detail. Once a record is selected, the
[Order Details] _Selecting method fires with every refresh, whether
or
not a new record is selected.
The [Order Details] update panel does NOT refresh, but for some
reason
it is still calling the _Selecting method for the ObjectDataSource.
I've tried moving the ObjectDataSource inside the details update
panel
with no luck.
It doesn't seem like what I'm doing is very atypical. Am I missing
something obvious? Here's the code for the page in question:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ObjectDataSource ID="dsOrders" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetOrderList"
TypeName="dsOrdersTableAdapters.taOrderList"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_OrderID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="EmployeeID" Type="Int32" />
<asp:Parameter Name="OrderDate" Type="DateTime" />
<asp:Parameter Name="RequiredDate" Type="DateTime" />
<asp:Parameter Name="ShippedDate" Type="DateTime" />
<asp:Parameter Name="ShipVia" Type="Int32" />
<asp:Parameter Name="Freight" Type="Decimal" />
<asp:Parameter Name="ShipName" Type="String" />
<asp:Parameter Name="ShipAddress" Type="String" />
<asp:Parameter Name="ShipCity" Type="String" />
<asp:Parameter Name="ShipRegion" Type="String" />
<asp:Parameter Name="ShipPostalCode" Type="String" />
<asp:Parameter Name="ShipCountry" Type="String" />
<asp:Parameter Name="Original_OrderID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="EmployeeID" Type="Int32" />
<asp:Parameter Name="OrderDate" Type="DateTime" />
<asp:Parameter Name="RequiredDate" Type="DateTime" />
<asp:Parameter Name="ShippedDate" Type="DateTime" />
<asp:Parameter Name="ShipVia" Type="Int32" />
<asp:Parameter Name="Freight" Type="Decimal" />
<asp:Parameter Name="ShipName" Type="String" />
<asp:Parameter Name="ShipAddress" Type="String" />
<asp:Parameter Name="ShipCity" Type="String" />
<asp:Parameter Name="ShipRegion" Type="String" />
<asp:Parameter Name="ShipPostalCode" Type="String" />
<asp:Parameter Name="ShipCountry" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
<asp:Label ID="lblPageTime" runat="server" Text="Label"></
asp:Label>
<asp:UpdatePanel ID="UpdatePanel2" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblMasterTime" runat="server"
Text="Label"></
asp:Label>
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="OrderID"
DataSourceID="dsOrders">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="Order
ID" InsertVisible="False" ReadOnly="True"
SortExpression="OrderID">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="CompanyName"
HeaderText="Customer" SortExpression="CompanyName">
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="OrderDate"
DataFormatString="{0:d}" HeaderText="Date Ordered"
HtmlEncode="False" ReadOnly="True"
SortExpression="OrderDate">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="RequiredDate"
DataFormatString="{0:d}" HeaderText="Date Required"
HtmlEncode="False" SortExpression="RequiredDate">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ShippedDate"
DataFormatString="{0:d}" HeaderText="Date Shipped"
HtmlEncode="False" SortExpression="ShippedDate">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:CommandField SelectText="View Details"
ShowSelectButton="True" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:ObjectDataSource ID="dsOrderDetails" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetOrderDetailsList"
TypeName="dsOrdersTableAdapters.taOrderDetails"
OnSelecting="dsOrderDetails_Selecting">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1"
Name="OrderID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:Label ID="lblChildTime" runat="server" Text="Label"></
asp:Label>
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" DataKeyNames="OrderID,ProductID"
DataSourceID="dsOrderDetails">
<Columns>
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="Quantity"
HeaderText="Quantity" SortExpression="Quantity" />
<asp:BoundField DataField="Discount"
HeaderText="Discount" SortExpression="Discount" />
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/
Default.aspx">View without AJAX</asp:HyperLink>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
lblPageTime.Text = DateTime.Now.ToLongTimeString();
lblMasterTime.Text = DateTime.Now.ToLongTimeString();
lblChildTime.Text = DateTime.Now.ToLongTimeString();
}
protected void dsOrderDetails_Selecting(object sender,
ObjectDataSourceSelectingEventArgs e) {
System.Threading.Thread.Sleep(2000);
}
}

May 2 '07 #1
0 5233

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Nico VanHaaster | last post: by
7 posts views Thread by =?Utf-8?B?Tmlrb2xheSBFdnNlZXY=?= | last post: by
reply views Thread by yisroem | last post: by
10 posts views Thread by Piotr Nowak | last post: by
11 posts views Thread by =?Utf-8?B?R2VyaGFyZA==?= | last post: by
3 posts views Thread by SAL | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.