Saturday, March 24, 2012

PageRequestManagerTimeOutException

Hey,

I have several problems and I need your help.

Problem 1: In a MasterPage, I have a timer which always runs to check whether there is any new update in the database, If I let the website running over night, in the next morning I will see that the memory will increase to >1GB in Task Manager and raise an error "Sys.WebForms.PageRequestManagerTimeOutException: The server request timed out", I have searched to find the solution for this, there is a tip to add AsyncPostBackTimeOut into the scriptManager like this:

<asp:ScriptManagerID="ScriptManager1"AsyncPostBackTimeOut="600"runat="server">

</asp:ScriptManager>

But the problem is still occured! like the firgure below:

Does anybody know how to catch this exception! Thanks in advance

Problem 2: I add a datagrid inside a Panel1. First take a look at the figure below:

If I scroll down the scrollbar and click on a button View, the scrollbar will be automatically moved on the top. I tried to add this:

this.Page.MaintainScrollPositionOnPostBack =true;

In the end of code lines of event for button "View" but problem is till occured! Again, please help me!

Problem 3: (last problemSmile )

First take a look at the figure below:

This is a datagrid, it is nice that when the mouse hovers at every row, the background color of that row will be changed to gray. But is it possible that I click on every place at that row and I get the event which is the same with click on button View. is it possible? Thanks,

Your help will be appreciated!

Thank you so much in advance,

Joesy

Hi Joesy,

P1:

You can add your own exception handler, like this:

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args)
{
if (args.get_error() != undefined)
{
var errorMessage = args.get_error().message;

args.set_errorHandled(true);
alert("My custom exception handler: " + errorMessage);
}
}
</script>

Please also note this:

AsyncPostBackTimeout : Gets or sets a value that indicates the period of time,in seconds, before asynchronous postbacks time out if no response is received.

P2:

The position can't be maintained because the scroll position of a control inside the page will be lost between postbacks.

You need implement this with your own code. For instance:

1. Add a hiddenfield to the page, which will be used to save current scroll position.

2. Save current scroll position to the hiddenField before the page postbacks. document.getElementById("hiddenField").value =document.getElementById("grdWithScroll").scrollTop;

3. Set the scroll position to the value of the HiddenField after the page postback. document.getElementById("grdWithScroll").scrollTop=document.getElementById("hiddenField").value ;

P3:

Yes, it's possible. Basically, you can add a onclick event handler to the generated <tr> tag in which trigger the corresponding button's click event.

Hope this helps.


Hey Raymond,

Firstly, Thank you very much for your reply, It has been a time and you are the only one who replied to my post. I am very appreciated about your help.

P1: I solvedYes

P2: Could you please give me a full code that I need to implement?

P3: Could you please help me to give me more details? it is the best to give me an example.

Thanks in advances,

Joesy


Hi Joesy,

Here is a sample regarding the last 2 questions:

<%@. 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) { } protected void Button1_Click(object sender, EventArgs e) { } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Button btn = e.Row.FindControl("Button2") as Button; btn.OnClientClick = "$get('HiddenField1').value = $get('Panel3').scrollTop;"; e.Row.Attributes.Add("onclick", "$get('" + btn.ClientID + "').click();"); } } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> </script></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Panel ID="Panel3" runat="server" Height="130px" Width="564px" ScrollBars="Auto"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated"> <Columns> <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" /> <asp:TemplateField> <ItemTemplate> <asp:Button ID="Button2" runat="server" Text="Button" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString%>" SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title] FROM [Employees]"></asp:SqlDataSource> </asp:Panel>   <asp:Button ID="Button1" runat="server" OnClientClick="$get('HiddenField1').value = $get('Panel3').scrollTop;" OnClick="Button1_Click" Text="Button" /> <asp:HiddenField ID="HiddenField1" runat="server" /> </form><script type="text/javascript">function pageLoad(){ $get('Panel3').scrollTop = $get('HiddenField1').value;}</script></body></html>

Hey Raymond,

Thank you very much for your help, We are nearly to solve the problem. but i am using DataGrid view instead of GridView, so is it any chance, you could help me to provide me a sample solution? This is the data grid inside the panel:

<asp:PanelID="Panel1"runat="server"ScrollBars="Vertical"Width="99%"Height="440px"

BorderWidth="1px"BorderColor="#E0E0E0"Wrap="False"HorizontalAlign="Justify"

EnableTheming="False">

<asp:DataGridID="Log_GridView"runat="server"Width="95%"OnItemCommand="Log_GridView_ItemCommand"

AutoGenerateColumns="False"ForeColor="#333333"Font-Names="Verdana"HorizontalAlign="Justify"

EnableTheming="True"AllowPaging="True"PageSize="250"CellPadding="0"DataKeyField="ID"

OnPageIndexChanged="Log_GridView_PageIndexChanged"OnItemDataBound="Log_GridView_ItemDataBound"

GridLines="Vertical">

<EditItemStyleBackColor="#2461BF"></EditItemStyle>

<SelectedItemStyleBackColor="#D1DDF1"ForeColor="#333333"BorderColor="#80FF80"

Font-Bold="True"></SelectedItemStyle>

<PagerStyleBackColor="#2461BF"ForeColor="White"HorizontalAlign="Center"></PagerStyle>

<AlternatingItemStyleBackColor="White"></AlternatingItemStyle>

<ItemStyleBackColor="#EFF3FB"></ItemStyle>

<HeaderStyleBackColor="#507CD1"ForeColor="White"Font-Bold="True"></HeaderStyle>

<Columns>

<asp:BoundColumnDataField="ID"HeaderText="ID"ReadOnly="True"Visible="False"></asp:BoundColumn>

<asp:BoundColumnDataField="LastName"HeaderText="Last Name"></asp:BoundColumn>

<asp:BoundColumnDataField="FirstName"HeaderText="First Name"></asp:BoundColumn>

<asp:BoundColumnDataField="Badgenumber"HeaderText="Badge Nr"></asp:BoundColumn>

<asp:ButtonColumnHeaderText="View"ButtonType="PushButton"CommandName="View_Button"

Text="View">

<ItemStyleWidth="10%"></ItemStyle>

</asp:ButtonColumn>

</Columns>

</asp:DataGrid></asp:Panel>

Could you please help me as soon as possible?

Thank you very much,

Kind regards,

Joesy


It's pretty much the same code as the above one, in ItemDataBound event of the DataGrid.


Hi JoeySY, how were you able to fixed the error for your Problem 1. I have the same problem.

Thanks.


Hey wowief,

It has been a long time since I came back to my post.

For problem 1. I added this:

<httpRuntimeexecutionTimeout="5000"/>

into system.web and problem is solved!

Good luck

Joesy

No comments:

Post a Comment