0
votes

What i'm trying to accomplish is a partial page reload on just an child ascx control. However, if I put a break on default.aspx on Page Load the break will hit on the timer tick. My ideal scenario would be the default.aspx never reloads.

Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    </Scripts>
</telerik:RadScriptManager>
<script type="text/javascript">
    //Put your JavaScript code here.
</script>
<div>
    <asp:Label runat="server" ID="DynLabel"></asp:Label>
    <asp:PlaceHolder ID="PlaceHolderDyn" runat="server"></asp:PlaceHolder>
</div>
</form>

Default.aspx.cs

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Guid g;
        g = Guid.NewGuid();
        DynLabel.Text = g.ToString();
        PlaceHolderDyn.Controls.Add(LoadControl("~/Docks/DynControl.ascx"));


    }


}

DynControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DynControl.ascx.cs" Inherits="Docks_DynControl" %>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="Timer1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="LoadingPanel1">
            </telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>
    <telerik:AjaxSetting AjaxControlID="DropDownList1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="Panel1"></telerik:AjaxUpdatedControl>
            <telerik:AjaxUpdatedControl ControlID="Panel2"></telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick"></asp:Timer>
<asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional" ViewStateMode="Enabled">
<ContentTemplate>
    <asp:PlaceHolder ID="DynamicPlaceHolder" runat="server"></asp:PlaceHolder>
    <asp:Labelrunat="server" ID="DynamiclabelAscx"/>
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>

DynControl.aspx.cs

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

public partial class Docks_DynControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
     public void Timer1_Tick(object sender, EventArgs e)
    {

        Guid g;
        g = Guid.NewGuid();
        DynamiclabelAscx.Text = g.ToString();


    }


}

So basically the label on the Default.aspx will be static, only load once, and the timer will reload the label on the ascx and it will always change. That works, but how can i prevent the default.aspx from reloading on the timer?

Thanks!

2

2 Answers

0
votes

After doing some research, here is the answer to your question:

An asynchronous postback behaves much like a synchronous postback. All the server page life-cycle events occur, and view state and form data are preserved. However, in the rendering phase, only the contents of the UpdatePanel control are sent to the browser. The rest of the page remains unchanged.

MSDN Source

So wrapping the Default.aspx Page_Load method in !IsPostBack seems to be the way to go:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Guid g;
        g = Guid.NewGuid();
        DynLabel.Text = g.ToString();
        PlaceHolderDyn.Controls.Add(LoadControl("~/Docks/DynControl.ascx"));
    }
}
0
votes

Thanks to Scott for the extended conversation.

The best way I've figured out to prevent postback is to have everything contained in that additional control aspx/ascx in an IFrame that points to that aspx. This will cause only that page to render any postback.