Showing posts with label functionality. Show all posts
Showing posts with label functionality. Show all posts

Wednesday, March 28, 2012

PageMethod calls are not asynchronous

I created a test app to try out the PageMethod functionality. I can make four calls to a PageMethod and I can verify that they are called asynchronously via the tracing statements. So I moved the test page into an existing website that I converted to AJAX and it appears that the methods are call synchronously. Is there a setting somewhere that I might be missing? It is the exact same page in both sites. Any suggestions are greatly appreciated. I've included the log results and methods for reference.

Test App Trace (This is the expected result. Notice that all of the "In Server Method" entries occur before any of the "Out Server Method" entries):

Post PageMethodsfor 1Post PageMethodsfor 2Post PageMethodsfor 3Post PageMethodsfor 4In Server Method: 1 - 633088835535430360In Server Method: 2 - 633088835538237248In Server Method: 3 - 633088835543249548In Server Method: 4 - 633088835548261848Out Server Method: 4 - 633088835573122856Out Server Method: 3 - 633088835578335648Out Server Method: 2 - 633088835590766152Out Server Method: 1 - 633088835600089030

Converted App Trace(This is not the expected result. Notice that the "In Server Method" entries alternate with the "Out Server Method" entries):

Post PageMethodsfor 1
Post PageMethodsfor 2
Post PageMethodsfor 3
Post PageMethodsfor 4
In Server Method: 1 - 633088837286126504
Out Server Method: 1 - 633088837375044706
In Server Method: 2 - 633088837378352824
Out Server Method: 2 - 633088837407023180
In Server Method: 3 - 633088837408627116
Out Server Method: 3 - 633088837421057620
In Server Method: 4 - 633088837423664016
Out Server Method: 4 - 633088837477596364

Server Method:

 [WebMethod]public static int GetHitCount(int grid) { Debug.WriteLine("In Server Method: " + grid.ToString() +" - " + DateTime.Now.Ticks.ToString());int sleep = rand.Next(1000, 10000); System.Threading.Thread.Sleep(sleep); // Sleep to slow down the process Debug.WriteLine("Out Server Method: " + grid.ToString() +" - " + DateTime.Now.Ticks.ToString());return rand.Next(1, 100); }

Client Methods:

function GetAllData() { PageMethodCall(1); PageMethodCall(2); PageMethodCall(3); PageMethodCall(4); } function PageMethodCall(context) { var waitImg = document.getElementById("imgWait" + context); waitImg.style.visibility =''; PageMethods.GetHitCount(context,OnSucceeded, OnError, context); Sys.Debug.trace('Post PageMethods for ' + context); }

Ok, I still don't have a good solution but I've found the problem. Though a process of elimination, I've determined that the existance of a Global.asax file is causing the problem. When I got into my test project and select "Add New Item" -> "Global Application Class", the request begin to queue. I have made no changes to the Global.asax.

Hi there, this is some kind of combined issue. -- It's about the session access. Strange ,right? What you can try is to set "enableSessionState="false|ReadOnly", the request is executed asyncronously. But as long as you change to true which is the default, your requests are piped up.

Note, the pipe-up behavior only happens for the requests from the same browser. If you have two browsers, it is always executed asyncronously.

The things that I haven't found out is where this crappy logic is. If you take a look at the system generated global.asax.cs , it is quite clean. I guess it is somewhere in HttpApplication which is the base class.

Hope this could help a bit.


Access to Session state variables must be performed synchronously. You can either set EnableSessionState to false or readonly, or you can use a different session state provider that allows asynchronous access to state variables.

Saturday, March 24, 2012

Paging freeze after partial postback

HiI am a newbie to the AJAX stage, I created an application very similar in functionality as the to do list HDI video demo.My problem is when I do a partial page back and the new data is refreshed into my gridview the paging stops to function. You can click on the page numbers and there it will stay till I fire

a full page postback. I have an updatePanel with a Gridview and a dropdownlist included in the panel. The dropdownlist just selects different departments in our organization.

I set the updatePanel to conditionalupdate and specified my trigger as dorpdownlist selected index change, enabled the paging and enablepagingandsorting on my gridview.

What did I miss on my path to AJAX ?

Can you post your code where its freezing. Check with breakpoints?


hello.

if the dropdown is inside the panel, then you simply don't need to set up triggers.

btw, here's a quick example:

i have the following ona code file on app_code:

public class Obj
{
private Int32 _id;
private String _name;

public int Id
{
get { return _id; }
set { _id = value; }
}

public string Name
{
get { return _name; }
set { _name = value; }
}
}


public class ObjDS
{
public List<Obj> Get()
{
List<Obj> objs = new List<Obj>
{
new Obj{Id = 1, Name = "Luis"} ,
new Obj{Id = 2, Name = "Jose"} ,
new Obj{Id = 3, Name = "Jose"} ,
new Obj{Id = 4, Name = "Jose"}

}
;
return objs;
}
}

and then, on an aspx page, i have this:

<asp:ScriptManager runat="server" ID="manager" />
<asp:UpdatePanel runat="server" ID="panel">
<contenttemplate>
<asp:GridView ID="GridView1" runat="server"
PageSize="2"
DataSourceID="source" AllowPaging="true">
</asp:GridView>

<asp:ObjectDataSource
TypeName="ObjDs"
SelectMethod="Get"
ID="source" runat="server">
</asp:ObjectDataSource>
<%= DateTime.Now.ToString() %>
</contenttemplate>
</asp:UpdatePanel>

it's working here. does it work there?


Hi LuisThanks for the reply.I am using a database queried created dataset and not a custom dataset,does this make a difference?What gets me is that after the page has loaded for a first time the paging works and after a partial postback the rest of the controls workexcept the datagrid's paging.

I'll have a crack at your code and let you know.


Hi Dexza,

Here is a working sample which is written based on your description. Please compare it with yours.

<%@. Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server"
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.DropDownList1.Items.Add("111");
this.DropDownList1.Items.Add("222");
}
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

}
</script
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%=DateTime.Now.ToString()%>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" PageSize="2" AllowPaging="true">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" InsertVisible="False"
ReadOnly="True" SortExpression="EmployeeID" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString%>"
SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title] FROM [Employees]"
DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = @.EmployeeID" InsertCommand="INSERT INTO [Employees] ([LastName], [FirstName], [Title]) VALUES (@.LastName, @.FirstName, @.Title)"
UpdateCommand="UPDATE [Employees] SET [LastName] = @.LastName, [FirstName] = @.FirstName, [Title] = @.Title WHERE [EmployeeID] = @.EmployeeID">
<DeleteParameters>
<asp:Parameter Name="EmployeeID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="EmployeeID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>

Best regards,

Jonathan


Hello.

Jonathan, i haven't run the code, but i'm curious: why did you associate a trigger with a server control that is inside an updatepanel?


Hi Luis Abreu,

Thanks for your attention. I just generated a sample based on the description of the thread owner. Yes , I agree with you that we don't need a trigger in this situation. Thanks

Best regards,

Jonathan


hello again.

well, i just asked because i might be missing something...thanks for the clarification.


Hi guys I have found my problem regarding the paging issue fromContributor post I noticed that on his properties he had only AllowPaging set to true and I had AllowPaging and EnablePagingAndSortingCallback set to true. So I changed it to false and of we go. Paging and sorting is up and running. Now I still have the problem where after selecting something different from my dorpdownlist that the updating does not work, but if I go back to the data the page was loaded with it works fine. So I have two questions. Why does the paging and sorting stop to function with a partial postback if EnablePagingAndSortingCallback is set to true. And what is wrong with the update function. Here is my code.

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%> <%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1"%> <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"> <title>Untitled Page</title> <linkhref="StyleSheet.css"rel="stylesheet"type="text/css"/></head> <body> <formid="form1"runat="server"> <asp:ScriptManagerID="ScriptManager1"runat="server"/> <br/> <br/> <br/> <br/> <asp:PanelID="Panel2"runat="server"BorderColor="Silver"BorderStyle="Solid"BorderWidth="1px" Height="50px"Width="125px"> <asp:UpdatePanelID="UpdatePanel1"runat="server"EnableViewState="False"UpdateMode="Conditional"> <ContentTemplate> <asp:GridViewID="GridView1"runat="server"AllowPaging="True" AutoGenerateColumns="False"BackColor="SteelBlue"DataKeyNames="IdeaNumber"DataSourceID="ObjectDataSource1"ForeColor="White"GridLines="None"Width="504px"AllowSorting="True"> <Columns> <asp:CommandFieldShowEditButton="True"/> <asp:BoundFieldDataField="IdeaNumber"HeaderText="IdeaNumber"InsertVisible="False" ReadOnly="True"SortExpression="IdeaNumber"/> <asp:BoundFieldDataField="IdeaName"HeaderText="IdeaName"SortExpression="IdeaName"/> <asp:CheckBoxFieldDataField="IdealDone"HeaderText="IdealDone"SortExpression="IdealDone"/> </Columns> <AlternatingRowStyleBackColor="LightBlue"ForeColor="SteelBlue"/> </asp:GridView> <asp:ObjectDataSourceID="ObjectDataSource1"runat="server"DeleteMethod="Delete" EnableViewState="False"InsertMethod="Insert"OldValuesParameterFormatString="original_{0}" SelectMethod="GetIdeaData"TypeName="IdeaDataSetTableAdapters.IdeaTableTableAdapter" UpdateMethod="Update"> <DeleteParameters> <asp:ParameterName="Original_IdeaNumber"Type="Int32"/> </DeleteParameters> <UpdateParameters> <asp:ParameterName="IdeaName"Type="String"/> <asp:ParameterName="IdealDone"Type="Boolean"/> <asp:ParameterName="Original_IdeaNumber"Type="Int32"/> </UpdateParameters> <SelectParameters> <asp:ControlParameterControlID="DropDownList1"Name="IsDone"PropertyName="SelectedValue" Type="Boolean"/> </SelectParameters> <InsertParameters> <asp:ParameterName="IdeaName"Type="String"/> <asp:ParameterName="IdealDone"Type="Boolean"/> </InsertParameters> </asp:ObjectDataSource> <asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"> <asp:ListItemValue="false">To do</asp:ListItem> <asp:ListItemValue="true">Completed</asp:ListItem> </asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTriggerControlID="GridView1"EventName="RowEditing"/> </Triggers> </asp:UpdatePanel> </asp:Panel> <br/> <br/> </form></body>

</html>


hello.

well, not sure on what's happening there...anyways, i'll just leave my 2 cents. first, if you have an updatepanel, i'm not sure if you'll be wining much with the grid's paging and sorting through callbakcs (if you have the time, compare the size of each request - yeah, i believe that through callbacks you'll have less to transport but you can't do other interesting things).

second, i can't seem to think of a good reason why the callback mechanism should not working with the updatepanel partial postbacks. try using fiddler to see what's happening between client and server...