This is a migrated thread and some comments may be shown as answers.

RadAjaxPanel makes a base web page rendered twice!

11 Answers 164 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Weibin
Top achievements
Rank 1
Weibin asked on 01 Jul 2008, 10:28 AM

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?

 

11 Answers, 1 is accepted

Sort by
0
Weibin
Top achievements
Rank 1
answered on 01 Jul 2008, 10:49 AM
in addition, RadAjaxManager will also cause this problem.
0
Weibin
Top achievements
Rank 1
answered on 01 Jul 2008, 12:02 PM
up!
0
Weibin
Top achievements
Rank 1
answered on 02 Jul 2008, 03:37 AM
telerik, I think this is a severe problem, could you give us some advice ?
0
Weibin
Top achievements
Rank 1
answered on 02 Jul 2008, 09:11 AM
anybody helps me ?
0
Weibin
Top achievements
Rank 1
answered on 05 Jul 2008, 03:20 PM
oh, my god, nobody can help me ?
0
plamen
Top achievements
Rank 1
answered on 07 Jul 2008, 10:06 AM
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 />
0
Weibin
Top achievements
Rank 1
answered on 08 Jul 2008, 02:16 PM
thank you, john, but could you give me some demo codes to resolve my trouble?
0
plamen
Top achievements
Rank 1
answered on 08 Jul 2008, 03:24 PM
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 />
0
Weibin
Top achievements
Rank 1
answered on 09 Jul 2008, 02:44 AM
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.
0
plamen
Top achievements
Rank 1
answered on 09 Jul 2008, 07:40 AM
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 />
0
Weibin
Top achievements
Rank 1
answered on 09 Jul 2008, 10:46 AM
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.
Tags
General Discussions
Asked by
Weibin
Top achievements
Rank 1
Answers by
Weibin
Top achievements
Rank 1
plamen
Top achievements
Rank 1
Share this question
or