RadAjaxManager ViewState and PreRenderComplete

2 posts, 0 answers
  1. Emmsa
    Emmsa avatar
    66 posts
    Member since:
    Oct 2006

    Posted 10 Feb 2012 Link to this post

    Hi there,

    I have a class called BasePage, it is a Page that helps me with common tasks. One is to persist some info in ViewState.
    This BasePage saves the ViewState info in the PreRenderComplete event (so the real page can modify this info in the PreRender event)

    The problem I have is that it does not work if I use RadAjaxManager

    Is there any way to solve this problem? 

    This is an example

    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="scriptManager"></asp:ScriptManager>
        <telerik:RadAjaxManager runat="server" ID="manager">
            <telerik:AjaxSetting AjaxControlID="lnk1">
                <telerik:AjaxUpdatedControl ControlID="lbl" />

        <asp:LinkButton runat="server" Text="Sum with Ajax" ID="lnk1" OnClick="lnk_Click">

        <asp:LinkButton runat="server" Text="Sum without Ajax" ID="LinkButton1" OnClick="lnk2_Click">

        <asp:Panel runat="server" ID="pnlAjax">
          <asp:Label runat="server" Text="Label" ID="lbl"></asp:Label><br />
          <asp:Label runat="server" Text="Label" ID="Label1"></asp:Label><br />

    public partial class Demos_KeepInViewStateWithAjaxTest : Page
      int _count;
      public int Count
          return _count;
          _count = value;
      protected void Page_Load(object sender, EventArgs e)
        //Restore ViewState
        if (ViewState["Count"] == null)
          ViewState["Count"] = 0;

        Count = Convert.ToInt32(ViewState["Count"]);

        PreRenderComplete += new EventHandler(Demos_KeepInViewStateWithAjaxTest_PreRenderComplete);

      void Demos_KeepInViewStateWithAjaxTest_PreRenderComplete(object sender, EventArgs e)
        ViewState["Count"] = Count.ToString();

      protected void lnk_Click(object sender, EventArgs e)
        lbl.Text = Count.ToString();
        Count += 1;

      protected void lnk2_Click(object sender, EventArgs e)
        lbl.Text = Count.ToString();
        Count += 1;

    Darío K
  2. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 15 Feb 2012 Link to this post

    Hello Darío ,

    The described issue is actually expected in case Ajax is used on the page. You could test the same application with regular asp UpdatePanel instead of RadAjax and the behaviour will be the same.
    You could review the following online resources which elaborates on this matter:

    Maria Ilieva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top