Reading the viewstate object.

3 posts, 0 answers
  1. Wim van der Linden
    Wim van der Linden avatar
    37 posts
    Member since:
    Nov 2008

    Posted 15 Oct 2009 Link to this post


    I've got a problem with the viewstate object, when for example using a textbox within the xmlhttppanel.
    I've read the following in the help documentation.

    "Callback - When a client callback is used, the server Page does not go through its whole lifecycle, but only a small part of it. The client state is not updated, and it is not sent back to the client-side. When Callbacks are used, a POST request is made from the client to the server, and the values of all FORM fields, such as hidden fields (!including the view state field!) are sent to the server. When the view state is large, this could mean increased overhead. On the other hand, no extra files are needed to use this mode (unlike when using a WebService). "

    However when the callback gets executed my pageload gets triggered, but I do not get the viewstate data.

    What should I do to retrieve the data from the viewstate field?

    kind regards,
  2. Pero
    Pero avatar
    1156 posts

    Posted 20 Oct 2009 Link to this post

    Hi Wim,

    I am sorry but I cannot fully understand your scenario. Please take a look at the following project, where I store a Value (entered from a TextBox) in the ViewState and when a callback is initialized on the XmlHttpPanel the value is shown in the TextBox hosted inside the Panel.

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <telerik:RadScriptBlock runat="server">
            <script type="text/javascript">
                function SetValue()
                    var panel = $find("<%=XmlPanel1.ClientID %>");
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:TextBox ID="txtViewState" runat="server" Text="[Initial Text]">
        </asp:TextBox><asp:Button ID="Button1" runat="server" Text="Store Some Value in ViewState"
            OnClick="Button1_OnClick" />
        <br />
        <asp:Button ID="btnMakePostback" runat="server" Text="Make Postback" />
        <br />
        <br />
        <input type="button" value="Retrieve Value From ViewState" onclick="SetValue(); return false;" />
        <br />
        <br />
        <telerik:RadXmlHttpPanel ID="XmlPanel1" runat="server" OnServiceRequest="XmlPanel1_ServiceRequest"
            <asp:TextBox ID="TextBox1" runat="server" Text="[Empty Text]"></asp:TextBox>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    public partial class _Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            if (IsCallback)
                TextBox1.Text = (string)ViewState["SomeValue"];
        protected void Button1_OnClick(object sender, EventArgs e)
            ViewState["SomeValue"] = txtViewState.Text;
        protected void XmlPanel1_ServiceRequest(object sender, Telerik.Web.UI.RadXmlHttpPanelEventArgs e)
    Please provide more information and (possibly) a running project where the problem with accessing the ViewState can be observed.

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft R3 2016 release webinar banner
  4. Wim van der Linden
    Wim van der Linden avatar
    37 posts
    Member since:
    Nov 2008

    Posted 20 Oct 2009 Link to this post

    Hello Pero,

    Thank you for the answer but I think I've been looking at the problem the wrong way.
    After reading things about the viewstate I realised it has nothing to do with the viewstate.

    The point was that I had a textbox within the xmlhttppanel.
    when I modify it's text I didn't get the textchanged event on the serverside.

    But I now realise the control is not ment for this.

    thank you for your answer and sorry for taking up your time.

    kind regards
Back to Top