I recently upgraded to asp.net ajax beta 2 and I have been experiencing problems when using UpdatePanels located in pages accessed using server.transfer, here is the context:
I have a quite simple page using an UpdatePanel which I access from a menu using server.transfer
When clicking on a button, the first Async call works and the updatePanel content panel content is changed as expected
BUT when I click a second time I get a PageRequestManagerParserErrorException" and/or a 404 page not found
Looking at the request I find that the second time around the button triggers a request using a wrong page path, it seems it is getting mixed up with the URL in the browser which does not correspond to the actual page since server.transfer is used.
The bottom line is I created a few test pages with the minimum code and the combination of using server.transfer to navigate to the page using the UpdatePanel is definitely at the root of my problem; I doubled checked the various web.config
settings and even tested this bug using the sample website. NOTE that I tested using a hyperlink to access the very same page and I don't get any problem.
Does anyone have any suggestion, I am out of idea.[*-)]
here is the details of my testing scenario:
2 pages needed located in separate folders
Page 1 is used to call page 2 using server.transfer
Page 2 has an UpdatePanel with a button to trigger some Async call
Partial Class restricted_beta2Test
Inherits System.Web.UI.Page
Private _accessTimes As Integer
Public Property accessTimes() As Integer
Get
If _accessTimes = 0 Then
Dim value As String = ViewState.Item("accessTimes")
If String.IsNullOrEmpty(value) Then
value = Context.Items.Item("accessTimes")
If Not String.IsNullOrEmpty(value) Then
_accessTimes = value
ViewState.Item("accessTimes") = value
Else
_accessTimes = 1
End If
Else
Context.Items.Item("accessTimes") = value
_accessTimes = value
End If
End If
Return _accessTimes
End Get
Set(ByVal value As Integer)
If value Then
ViewState.Item("accessTimes") = value
Context.Items.Item("accessTimes") = value
End If
_accessTimes = value
End Set
End Property
Protected Sub lnkBtnText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnText.Click
lbltext.Text &= ";" & txtText.Text
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lnkBtnText.PostBackUrl = Page.AppRelativeVirtualPath
If accessTimes = 2 Then
accessTimes = accessTimes + 1
Server.Transfer(Page.AppRelativeVirtualPath)
End If
accessTimes = accessTimes + 1
'Dim sourceDirectory As String = lnkBtnText.AppRelativeTemplateSourceDirectory
End Sub
End Class
If you find the code sample from my previous post confusing, check out this other post with a cleaner and clearer example on my problem:
http://forums.asp.net/thread/1439208.aspx
The .NET AJAX problem with Server.Transfer has been noted sporadically for the last year. It looks like a Framework issue. The Framework provides correct callback/postback page identity to a control when its page has been accessed directly by URL or by cross-page
postback but not when it has been accessed by Server.Transfer. When controls have the wrong page identity the first AJAX callback fails.
Telerik encountered the same problem with its AJAX-enabled controls and bypassed it by adding a parameter to be set in Page_Load that identifies a page to a control. |Microsoft ought to solve the problem for everyone by fixing the Framework, but so far nothing
has been done.
Weird though, I have been using server.transfer up to now without any issues, problems started when I upgraded to Asp.net Ajax Beta 2 also, its not the First but the Second postback that fails !?
Could you elaborate a little on the workaround with the extra parameter?
Thank you for your help, at least I know I am looking for a workaround and not a fix ;)
I have a update 2 panels that contains a text box each. Each text box has an text changed event that calls a web service to validate the value.
The call to the web service the first time works fine, but the second call throws a Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was:
404.
When I inspect the second call with fiddler, the url path is incorrect.
Lets say the path of the page that does the server.transfer = /app1/folder1/transferer/page1.aspx.
The page that gets called from the server.transfer path = /app1/folder1/receiver/page2.aspx.
The path of the second call ends up as /app1/folder/transferer/page2.aspx.
From the Telerik website... and I would probably concur as server transfers in my opinion are kind of evil and induces a bunch of unwanted state from previous pages...
As outlined in our documentation the Server.Transfer method is not supported by our ajax controls. In fact we are not aware of any ajax framework out there supporting this method. We suggest you to use
Response.Redirect instead. If this is a must for your project you can try setting EnableViewStateMac="false" of the Page directive to false and see if that helps, but note that it is not supported.
So, their description of how to resolve it... If you are using Ajax anyways - there really should not be a reason for a server.transfer because you can add all the code you want to the serverside to handle what you want the control to do without it really
effecting the end-user experience...
Just my two cents - and I doubt there is a work around for the server.transfer as they are two seperate pages and therefore the whole DOM element on the broswer is effectively 'corrupted'. Ajax is meant to asynch controls (while the hype says pages as it
is sexier to say that a page is ajaxed- in reality it really is only on a control basis) .. Doing a server.transfer is basically from both a server and browser perspective the same thing that is done with html rewriting..Another portion of the problem is dealing
with the browsers cache when pages are requested as kind of explained here:
http://www.howtoadvice.com/StopCaching
In my opinion - doing a server.transfer in any enviroment and particularly Ajax - where you can asynchronously load and unload dynamic controls is counter intuitive to the issues of trying to work around why a server.transfer will not work (particulary in
a ajax enviroment where everything is about just playing with the browser's dom )...
You probably will not be able to get this to work as what you prefer with existing code that includes server.transfers. If the server.transfer had some kind of boolean that could be tracked by an IHTTP handler to detect it was a transfer - then you would
have probably been able to worlk around it... You could of course write or if you are using a custom Ihttp handler - to do a REGEX on the incoming url and if matches transfer then redirect to reciever...might be a workaround... but I think there are better
ways to do it to fully utilizeAjax and reap the perf benefit and UI experience...
vhouck
Member
40 Points
8 Posts
server.transfer and UpdatePanel in Beta2
Nov 23, 2006 01:48 AM|LINK
I recently upgraded to asp.net ajax beta 2 and I have been experiencing problems when using UpdatePanels located in pages accessed using server.transfer, here is the context:
Looking at the request I find that the second time around the button triggers a request using a wrong page path, it seems it is getting mixed up with the URL in the browser which does not correspond to the actual page since server.transfer is used.
The bottom line is I created a few test pages with the minimum code and the combination of using server.transfer to navigate to the page using the UpdatePanel is definitely at the root of my problem; I doubled checked the various web.config settings and even tested this bug using the sample website. NOTE that I tested using a hyperlink to access the very same page and I don't get any problem.
Does anyone have any suggestion, I am out of idea.[*-)]
here is the details of my testing scenario:
code for page 1:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="callTest.aspx.cs" Inherits="test1_callTest" %> <!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 runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:LinkButton runat="server" ID="lnkBtnToBeta2test" Text="beta2test.aspx" OnClick="lnkBtnToBeta2test_Click"></asp:LinkButton> <asp:HyperLink runat="server" ID="lnkToBeta2Test" NavigateUrl="~/test2/beta2Test.aspx">HyperLink</asp:HyperLink> </div> </form> </body> </html>HTML for Page 2 (called "beta2Test")
Code behind for page 2 (called "beta2Test" )
Partial Class restricted_beta2Test Inherits System.Web.UI.Page Private _accessTimes As Integer Public Property accessTimes() As Integer Get If _accessTimes = 0 Then Dim value As String = ViewState.Item("accessTimes") If String.IsNullOrEmpty(value) Then value = Context.Items.Item("accessTimes") If Not String.IsNullOrEmpty(value) Then _accessTimes = value ViewState.Item("accessTimes") = value Else _accessTimes = 1 End If Else Context.Items.Item("accessTimes") = value _accessTimes = value End If End If Return _accessTimes End Get Set(ByVal value As Integer) If value Then ViewState.Item("accessTimes") = value Context.Items.Item("accessTimes") = value End If _accessTimes = value End Set End Property Protected Sub lnkBtnText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnText.Click lbltext.Text &= ";" & txtText.Text End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load lnkBtnText.PostBackUrl = Page.AppRelativeVirtualPath If accessTimes = 2 Then accessTimes = accessTimes + 1 Server.Transfer(Page.AppRelativeVirtualPath) End If accessTimes = accessTimes + 1 'Dim sourceDirectory As String = lnkBtnText.AppRelativeTemplateSourceDirectory End Sub End Classvhouck
Member
40 Points
8 Posts
Re: server.transfer and UpdatePanel in Beta2
Nov 23, 2006 08:01 PM|LINK
If you find the code sample from my previous post confusing, check out this other post with a cleaner and clearer example on my problem: http://forums.asp.net/thread/1439208.aspx
Thanks,
V
cbolon
Member
55 Points
11 Posts
Re: server.transfer and UpdatePanel in Beta2
Nov 28, 2006 03:55 AM|LINK
The .NET AJAX problem with Server.Transfer has been noted sporadically for the last year. It looks like a Framework issue. The Framework provides correct callback/postback page identity to a control when its page has been accessed directly by URL or by cross-page postback but not when it has been accessed by Server.Transfer. When controls have the wrong page identity the first AJAX callback fails.
Telerik encountered the same problem with its AJAX-enabled controls and bypassed it by adding a parameter to be set in Page_Load that identifies a page to a control. |Microsoft ought to solve the problem for everyone by fixing the Framework, but so far nothing has been done.
vhouck
Member
40 Points
8 Posts
Re: server.transfer and UpdatePanel in Beta2
Nov 28, 2006 08:48 PM|LINK
Bugger!
Weird though, I have been using server.transfer up to now without any issues, problems started when I upgraded to Asp.net Ajax Beta 2 also, its not the First but the Second postback that fails !?
Could you elaborate a little on the workaround with the extra parameter?
Thank you for your help, at least I know I am looking for a workaround and not a fix ;)
Vincent
lking
Member
94 Points
22 Posts
Re: server.transfer and UpdatePanel in RTM 1.0 (was Beta2)
Jan 31, 2007 02:53 AM|LINK
Has anyone found a solution for this?
I'm seeing the same thing.
I have a update 2 panels that contains a text box each. Each text box has an text changed event that calls a web service to validate the value.
The call to the web service the first time works fine, but the second call throws a Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 404.
When I inspect the second call with fiddler, the url path is incorrect.
Lets say the path of the page that does the server.transfer = /app1/folder1/transferer/page1.aspx.
The page that gets called from the server.transfer path = /app1/folder1/receiver/page2.aspx.
The path of the second call ends up as /app1/folder/transferer/page2.aspx.
Any ideas would be greatly appreciated
Thanks
Lance
jodywbcb
Contributor
4482 Points
985 Posts
Re: server.transfer and UpdatePanel in RTM 1.0 (was Beta2)
Jan 31, 2007 04:42 AM|LINK
From the Telerik website... and I would probably concur as server transfers in my opinion are kind of evil and induces a bunch of unwanted state from previous pages...
As outlined in our documentation the Server.Transfer method is not supported by our ajax controls. In fact we are not aware of any ajax framework out there supporting this method. We suggest you to use Response.Redirect instead. If this is a must for your project you can try setting EnableViewStateMac="false" of the Page directive to false and see if that helps, but note that it is not supported.
So, their description of how to resolve it... If you are using Ajax anyways - there really should not be a reason for a server.transfer because you can add all the code you want to the serverside to handle what you want the control to do without it really effecting the end-user experience...
Just my two cents - and I doubt there is a work around for the server.transfer as they are two seperate pages and therefore the whole DOM element on the broswer is effectively 'corrupted'. Ajax is meant to asynch controls (while the hype says pages as it is sexier to say that a page is ajaxed- in reality it really is only on a control basis) .. Doing a server.transfer is basically from both a server and browser perspective the same thing that is done with html rewriting..Another portion of the problem is dealing with the browsers cache when pages are requested as kind of explained here: http://www.howtoadvice.com/StopCaching
In my opinion - doing a server.transfer in any enviroment and particularly Ajax - where you can asynchronously load and unload dynamic controls is counter intuitive to the issues of trying to work around why a server.transfer will not work (particulary in a ajax enviroment where everything is about just playing with the browser's dom )...
You probably will not be able to get this to work as what you prefer with existing code that includes server.transfers. If the server.transfer had some kind of boolean that could be tracked by an IHTTP handler to detect it was a transfer - then you would have probably been able to worlk around it... You could of course write or if you are using a custom Ihttp handler - to do a REGEX on the incoming url and if matches transfer then redirect to reciever...might be a workaround... but I think there are better ways to do it to fully utilizeAjax and reap the perf benefit and UI experience...
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
lking
Member
94 Points
22 Posts
Re: server.transfer and UpdatePanel in RTM 1.0 (was Beta2)
Jan 31, 2007 05:07 PM|LINK
Thanks for the info Jody..
Looks like I will stay with the response.redirect.
Thanks
Lance