Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 22, 2013 @ 02:56
    Nicholas Westby
    0

    Anchor Tags That Runat Server Don't Perform AJAX Postbacks Inside Umbraco

    When I run identical code in Umbraco and outside of Umbraco (in Visual Studio), it runs perfectly outside of Umbraco, but it fails inside of Umbraco. It is a list of <a> tags with runat="server" that are inside of an update panel. They are supposed to cause an AJAX postback, but they instead cause a full page postback. And this seems to be specific to Umbraco. Here's my Umbraco template:

    <%@ Master Language="VB" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <script runat="server">
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
          lvRecents.DataSource = New List(Of String)() From {"a", "b", "c"}
          lvRecents.DataBind()
        End If
      End Sub
      
      Protected Sub recentItem_Click(sender As Object, e As EventArgs)
        System.Threading.Thread.Sleep(5000)
        lblDate.Text = DateTime.Now.ToString()
        upRecents.Update()
      End Sub
    </script>
    <!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>Anchor Postbacks</title>
    </head>
    <body>
      <form id="frmMain" runat="server">
        <asp:ScriptManager runat="server" ID="mainMan" EnablePartialRendering="true" />
        <%-- Write a bunch of line breaks so we can observe postback-induced scrolling. --%>
        <% For i As Integer = 0 To 100%>
          <br />
        <% Next%>
        
        <%-- Anchors in this update panel should perform AJAX postbacks (not full postbacks). --%>
        <asp:UpdatePanel runat="server" ID="upRecents" UpdateMode="Conditional" ChildrenAsTriggers="false">
          <ContentTemplate>
            <ul>
              <asp:ListView runat="server" ID="lvRecents">
                <ItemTemplate>
                  <li><a runat="server" id="recentItem" onserverclick="recentItem_Click"><%# DirectCast(Container.DataItem, String)%></a></li>
                </ItemTemplate>
              </asp:ListView>
            </ul>
            <asp:Label runat="server" ID="lblDate" />
          </ContentTemplate>
        </asp:UpdatePanel>
      </form>
    </body>
    </html>
    </asp:Content>

    And here's my masterpage (that runs fine outside of Umbraco in Visual Studio), the only difference being the MasterPageFile:

    <%@ Page Language="vb" MasterPageFile="Default.Master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <script runat="server">
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
          lvRecents.DataSource = New List(Of String)() From {"a", "b", "c"}
          lvRecents.DataBind()
        End If
      End Sub
      
      Protected Sub recentItem_Click(sender As Object, e As EventArgs)
        System.Threading.Thread.Sleep(5000)
        lblDate.Text = DateTime.Now.ToString()
        upRecents.Update()
      End Sub
    </script>
    <!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>Anchor Postbacks</title>
    </head>
    <body>
      <form id="frmMain" runat="server">
        <asp:ScriptManager runat="server" ID="mainMan" EnablePartialRendering="true" />
        <%-- Write a bunch of line breaks so we can observe postback-induced scrolling. --%>
        <% For i As Integer = 0 To 100%>
          <br />
        <% Next%>
        
        <%-- Anchors in this update panel should perform AJAX postbacks (not full postbacks). --%>
        <asp:UpdatePanel runat="server" ID="upRecents" UpdateMode="Conditional" ChildrenAsTriggers="false">
          <ContentTemplate>
            <ul>
              <asp:ListView runat="server" ID="lvRecents">
                <ItemTemplate>
                  <li><a runat="server" id="recentItem" onserverclick="recentItem_Click"><%# DirectCast(Container.DataItem, String)%></a></li>
                </ItemTemplate>
              </asp:ListView>
            </ul>
            <asp:Label runat="server" ID="lblDate" />
          </ContentTemplate>
        </asp:UpdatePanel>
      </form>
    </body>
    </html>
    </asp:Content>

    Note that I tried removing the xhtmlConformance element from the web.config, but that didn't help. Note also that I was able to solve the problem using RegisterAsyncPostBackControl, but that caused an additional problem that UpdateProgress controls don't run when their AssociatedUpdatePanelID attribute is set. Any ideas what could be causing this behavior in Umbraco (that is, full page postbacks rather than AJAX postbacks)? Any fixes?

    Note: I'm on Umbraco 4.7.1. And ASP.NET 4.0. Chrome browser. You can notice the full page postback by the progress bar in the browser tab title and by the fact that the page scrolls to the beginning of the document on postback.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 23, 2013 @ 00:52
    Nicholas Westby
    100

    To answer myself, this appears to be fixed in the latest version of Umbraco (4.11.3.1). Either that, or there was a web.config difference.

Please Sign in or register to post replies

Write your reply to:

Draft