RadAjaxPanel makes a base web page rendered twice!

12 posts, 0 answers
  1. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 01 Jul 2008 Link to this post

    ASPX:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClearCaching.aspx.cs" Inherits="Web_PersonnelInfoQuery_ClearCaching" %>

    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

    <!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>Sample Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        </div>
        <telerik:RadAjaxPanel ID="myPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">   
        <telerik:RadDatePicker ID="RadDatePicker1" Runat="server" AutoPostBack="True"
            onselecteddatechanged="RadDatePicker1_SelectedDateChanged">
    <DateInput InvalidStyleDuration="100" autopostback="True"></DateInput>
        </telerik:RadDatePicker>
        </telerik:RadAjaxPanel>

        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server"
            height="75px" Transparency="15" width="75px">
            <img alt="Loading..."
                src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' originalAttribute="src" originalPath="<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>"
                style="border:0px;" />
        </telerik:RadAjaxLoadingPanel>
        </form>
    </body>
    </html>

    C#:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class Web_PersonnelInfoQuery_ClearCaching : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void RadDatePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        {
     // do something here
     string s = string.Format("this is {0} test", "a");
     s += "!";
        }
    }

    Note that we make Web_PersonnelInfoQuery_ClearCaching inherited from BasePage, and the code of BasePage is quite simple.

    BasePage:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Text;

    public class BasePage : Page
    {
        protected override void Render(HtmlTextWriter writer)
        {
            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
            base.Render(htmlWriter);
            string html = stringWriter.ToString();

            MatchCollection collection = Regex.Matches(html, "<(a|link|img|script|input|form).[^>]*(href|src|action)=(\\\"|'|)(.[^\\\"']*)(\\\"|'|)[^>]*>", RegexOptions.IgnoreCase);

            foreach (Match match in collection)
            {
                if (match.Groups[match.Groups.Count - 2].Value.IndexOf("~") != -1)
                {
                    string url = this.Page.ResolveUrl(match.Groups[match.Groups.Count - 2].Value);
                    html = html.Replace(match.Groups[match.Groups.Count - 2].Value, url);
                }
            }
            #endregion
            writer.Write(html);
        }
    }

    what surprised me is that base.Render(htmlWriter) was executed twice, as long as we put RadAjaxPanel on a page, but other controls such as RadGrid, DatePicker, RadToolbar, MS UpdatePanel... work perfectly.

    can anybody tell me why?

     

  2. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 01 Jul 2008 Link to this post

    in addition, RadAjaxManager will also cause this problem.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 01 Jul 2008 Link to this post

    up!
  5. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 01 Jul 2008 Link to this post

    telerik, I think this is a severe problem, could you give us some advice ?
  6. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 02 Jul 2008 Link to this post

    anybody helps me ?
  7. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 05 Jul 2008 Link to this post

    oh, my god, nobody can help me ?
  8. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 07 Jul 2008 Link to this post

    Hi :)

    If you are overriding standart page lifecycle methods as the ones you described this is normal behaviour.
    The reason this happens is that in RadAjaxManager uses the Page.SetRenderMethodDelegate method to
    intercept the page render mechanism. Now, this delegate is called once by the framework and another time in the overriden method (when you call base.Render(writer);) since those are virtual methods.

    Please read the following forum post on the same topic:
    http://www.telerik.com/community/forums/thread/b311D-ehmht.aspx


    Thank you...
    <John:Peel />
  9. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 08 Jul 2008 Link to this post

    thank you, john, but could you give me some demo codes to resolve my trouble?
  10. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 08 Jul 2008 Link to this post

    hello


    You can use a flag or counter to keep track which call to the render method you are in, but I do not suggest you to override the Render method

    ...
    <John:Peel />
  11. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 08 Jul 2008 Link to this post

    but if I do not override the Render method, how can I do what I need such as replacing ~ relative path, including common styles, scripts.. and so on.
  12. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 09 Jul 2008 Link to this post

    hi:)

    The Header property gets a reference to an HtmlHead object that you can use to set document header information for the page. The HtmlHead allows you to add information such as style sheets, style rules, a title, and metadata to the head element.


    The following code example demonstrates how to access the HtmlHead control programmatically using the Header property and how to change the script element and style element:

    .aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title>Untitled Page</title> 
        <script type="text/javascript" src="testjs/JScript.js"></script> 
        <link href="testcss/StyleSheet.css" rel="stylesheet" type="text/css" /> 
    </head> 
    <body> 
        <form id="form1" runat="server"
            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <div> 
            </div> 
        </form> 
    </body> 
    </html> 
     

    .cs
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
     
    public partial class _Default : System.Web.UI.Page  
        protected void Page_Load(object sender, EventArgs e) 
        { 
            LiteralControl literalControl = (LiteralControl)Page.Header.Controls[1]; 
            literalControl.Text = literalControl.Text.Replace("test", String.Empty); 
     
            HtmlLink htmlLink = (HtmlLink)Page.Header.Controls[2]; 
            htmlLink.Href = htmlLink.Href.Replace("test", String.Empty); 
        } 
     
    }    



    ...
    <John:Peel />
  13. Weibin
    Weibin avatar
    17 posts
    Member since:
    May 2008

    Posted 09 Jul 2008 Link to this post

    john, thank you, but I don't think manipulating Page.Header is a good idea.
    when/where the link or script tag appears is random.

    if I exchange <link> and <script> position,Page.Header.Controls[1] and Page.Header.Controls[2] will have different meanings.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017