server.transfer and UpdatePanel in Beta2

Last post 01-31-2007 1:07 PM by lking. 6 replies.

Sort Posts:

  • server.transfer and UpdatePanel in Beta2

    11-22-2006, 9:48 PM
    • Loading...
    • vhouck
    • Joined on 03-16-2006, 12:51 AM
    • Posts 8

    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.Confused

     

    here is the details of my testing scenario:

    1. 2 pages needed located in separate folders
    2. Page 1 is used to call page 2 using server.transfer
    3. Page 2 has an UpdatePanel with a button to trigger some Async call

    code for page 1: 

    1    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="callTest.aspx.cs" Inherits="test1_callTest" %>
    2    
    3    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    4    
    5    <html xmlns="http://www.w3.org/1999/xhtml" >
    6    <head runat="server">
    7        <title>Untitled Page</title>
    8    </head>
    9    <body>
    10       <form id="form1" runat="server">
    11       <div>
    12         <asp:LinkButton runat="server" ID="lnkBtnToBeta2test" Text="beta2test.aspx" OnClick="lnkBtnToBeta2test_Click"></asp:LinkButton>
    13       <asp:HyperLink runat="server" ID="lnkToBeta2Test" NavigateUrl="~/test2/beta2Test.aspx">HyperLink</asp:HyperLink>
    14       </div>
    15       </form>
    16   </body>
    17   </html>
    18   
    

    HTML for Page 2 (called "beta2Test")

    1    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="beta2Test.aspx.vb" Inherits="restricted_beta2Test" %>
    2    
    3    <%@ Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    4        Namespace="Microsoft.Web.UI" TagPrefix="asp" %>
    5    
    6    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    7    
    8    <html xmlns="http://www.w3.org/1999/xhtml" >
    9    <head runat="server">
    10       <title>Untitled Page</title>
    11   </head>
    12   <body>
    13   
    14       <form id="form1" runat="server">
    15       <div>
    16       
    17       </div>
    18           <asp:ScriptManager runat="server" EnablePartialRendering="true" ID="sm" >
    19           </asp:ScriptManager>
    20           <asp:UpdatePanel runat="server" ID="up">
    21               <ContentTemplate>
    22               <script type="text/javascript" language="javascript">
    23               function show()
    24               {
    25                   var hidEventArg = document.getElementById("__EVENTARGUMENT");
    26                   var hidEventTarget = document.getElementById("__EVENTTARGET");
    27                   if((hidEventArg) && (hidEventTarget))
    28                   {
    29                       alert("hidEventArg content is: " + hidEventArg.value + " and hidEventTarget content is: " + hidEventTarget.value);       
    30                   }
    31                   else
    32                   {                
    33                       alert('cannot find controls');
    34                   }    
    35               }
    36               </script>
    37                   <asp:Label runat="server" ID="lbltext"></asp:Label>
    38                   <br />
    39                   <asp:TextBox runat="server" ID="txtText"></asp:TextBox>
    40                   <br />
    41                   <asp:LinkButton runat="server" ID="lnkBtnText" Text="submit" OnClientClick="Javascript:show();"></asp:LinkButton>
    42               </ContentTemplate>
    43           </asp:UpdatePanel>
    44       </form>
    45   </body>
    46   </html>
    47   
    

      Code behind for page 2 (called "beta2Test" )

    1    
    2    Partial Class restricted_beta2Test
    3        Inherits System.Web.UI.Page
    4        Private _accessTimes As Integer
    5        Public Property accessTimes() As Integer
    6            Get
    7                If _accessTimes = 0 Then
    8                    Dim value As String = ViewState.Item("accessTimes")
    9                    If String.IsNullOrEmpty(value) Then
    10                       value = Context.Items.Item("accessTimes")
    11                       If Not String.IsNullOrEmpty(value) Then
    12                           _accessTimes = value
    13                           ViewState.Item("accessTimes") = value
    14                       Else
    15                           _accessTimes = 1
    16                       End If
    17                   Else
    18                       Context.Items.Item("accessTimes") = value
    19                       _accessTimes = value
    20                   End If
    21               End If
    22               Return _accessTimes
    23           End Get
    24           Set(ByVal value As Integer)
    25               If value Then
    26                   ViewState.Item("accessTimes") = value
    27                   Context.Items.Item("accessTimes") = value
    28               End If
    29               _accessTimes = value
    30           End Set
    31       End Property
    32   
    33       Protected Sub lnkBtnText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnText.Click
    34           lbltext.Text &= ";" & txtText.Text
    35       End Sub
    36   
    37       Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    38           lnkBtnText.PostBackUrl = Page.AppRelativeVirtualPath
    39           If accessTimes = 2 Then
    40               accessTimes = accessTimes + 1
    41               Server.Transfer(Page.AppRelativeVirtualPath)
    42           End If
    43           accessTimes = accessTimes + 1
    44   
    45           'Dim sourceDirectory As String = lnkBtnText.AppRelativeTemplateSourceDirectory
    46       End Sub
    47   End Class
    48   
    
      

     

     

  • Re: server.transfer and UpdatePanel in Beta2

    11-23-2006, 4:01 PM
    • Loading...
    • vhouck
    • Joined on 03-16-2006, 12:51 AM
    • Posts 8

    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
     

  • Re: server.transfer and UpdatePanel in Beta2

    11-27-2006, 11:55 PM
    • Loading...
    • cbolon
    • Joined on 05-30-2006, 3:10 PM
    • Posts 11

    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.

     

  • Re: server.transfer and UpdatePanel in Beta2

    11-28-2006, 4:48 PM
    • Loading...
    • vhouck
    • Joined on 03-16-2006, 12:51 AM
    • Posts 8

    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

  • Re: server.transfer and UpdatePanel in RTM 1.0 (was Beta2)

    01-30-2007, 10:53 PM
    • Loading...
    • lking
    • Joined on 02-27-2006, 11:18 AM
    • Posts 22

    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

  • Re: server.transfer and UpdatePanel in RTM 1.0 (was Beta2)

    01-31-2007, 12:42 AM
    • Loading...
    • jodywbcb
    • Joined on 03-12-2003, 3:52 PM
    • West Seattle,WA
    • Posts 985

    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...

    -- jody
    My Blogs on .Net 2.0 and Ajax
    http://csk.wbcb.com
    http://ArtbyJody.com
  • Re: server.transfer and UpdatePanel in RTM 1.0 (was Beta2)

    01-31-2007, 1:07 PM
    • Loading...
    • lking
    • Joined on 02-27-2006, 11:18 AM
    • Posts 22

    Thanks for the info Jody..

    Looks like I will stay with the response.redirect.

    Thanks

    Lance

     

Page 1 of 1 (7 items)
Microsoft Communities
Page view counter