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