Can value or text be included in viewstate postback?

5 posts, 0 answers
  1. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 07 Jul 2009 Link to this post

    Great job Telerik on RadListBox.  We have a couple homegrown alternatives to this and have been hoping you would release this type of control so we could standardize.

    One of our current projects relies on multiple combinations of controls created in runtime, after init.  To view these object and their values on postback, we are taking advantage of request.form in the postback and parsing the results.

     Dim str As String 
     Dim str2 As String = "" 
    For Each str In Request.Form 
       str2 += str & "  -  " & Request.Form(str) & "<br>"    
    Next 
     
    Response.Write(str2) 


    RadListbox gives us a method of tracing the users actions click by click, but it would be great if the postback could include either the text, or preferably the value, of the RadListboxItem along with the ordinal position changes.  We frequently need to randomize the position of the listitems in these situations to prevent bias so we will currently need to store additional data in hidden controls for the ordinal mapping.  I realize this is not standard usage of the control, but if you could add for future consideration either an ordered list of all values within Radlistbox in request.form (preferable), or include the value in the ordinal move data as it is now, it would streamline the process significantly.

    The example beliw is the output of a 4 item list where the last item (3) is placed in position 0 recursively until the list is in it's original position again.

    QUIHereType_ClientState - {"logEntries":[{"Type":5,"Index":"3","Data":{"NewIndex":"0"}},{"Type":5,"Index":"3","Data":{"NewIndex":"0"}},{"Type":5,"Index":"3","Data":{"NewIndex":"0"}},{"Type":5,"Index":"3","Data":{"NewIndex":"0"}}],"selectedIndices":[0],"checkedIndices":[],"scrollPosition":0} 



    Thanks again for your excellent work with this release.

    -Joel

    [edit]  subject line should not have included the word viewstate...

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 08 Jul 2009 Link to this post

    Hi Joel,

    In fact you can deserialize the client state in order to obtain the index of the items that have been logged. Once having their indexes, it is easy to obtain the text/value of a given item. Example code:

    string rlbClientState = Request.Form["RadListBox1_ClientState"]; 
                JavaScriptSerializer serializer = new JavaScriptSerializer(); 
                RadListBoxClientState state = serializer.Deserialize<RadListBoxClientState>(rlbClientState); 
     
                foreach (ClientStateLogEntry entry in state.LogEntries) 
                { 
                    int index = int.Parse(entry.Index); 
                    string itemText = RadListBox1.Items[index].Text;     
                } 


    Kind regards,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 08 Jul 2009 Link to this post

    Thank you for your reply.

    I am not sure I will be able to use this since the listbox is created in runtime, after init, but I would like to try it as it will be applicable to future projects.  I am running into an error of unknown type "RadListBoxClientState".   Do I need to import something?
    Imports System.Web.Script.Serialization 
     
    Partial Class Testing_ListBox 
        Inherits System.Web.UI.Page 
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
            If IsPostBack Then 
                Dim rlbClientState As String = Request.Form("RadListBox1_ClientState") 
                Dim serializer As New JavaScriptSerializer() 
                Dim state As RadListBoxClientState = serializer.Deserialize(Of RadListBoxClientState)(rlbClientState) 
     
                For Each entry In state.LogEntries 
                    Dim index As IntegerInteger = Integer.Parse(entry.Index) 
                    Dim itemText As String = RadListBox1.Items(index).Text 
                    Response.Write(index & "-------" & itemText) 
                Next 
            End If 
        End Sub 
    End Class 

  5. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 09 Jul 2009 Link to this post

    Hi Joel,

    Yes, I have forgotten to mention that you need to import the Telerik.Web namespace in order to use RadListBoxClientState class. The control being added after Init is not a problem, since it's addition is before PreRender. You only need to use Form.Controls instead of Page.Controls.

    Best wishes,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Todd
    Todd avatar
    3 posts
    Member since:
    Sep 2008

    Posted 19 Nov 2010 Link to this post

    This worked perfectly for my situation.

    We are dynamically adding RadListBox controls to a page, and upon postback I need via the Request.Form[] the value of the control, as the control is not accessible for some reason. Can't find it via FindControl() to save my life.

    I am able to get the serialized value from this line:

    string newValue = Request.Form[String.Format("ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_NewInput_{0}actual_ClientState", newTermAF.ID.ToString())].ToString();

    then using the JavaScriptSerializer I am able to get the newValue to a RadListBoxClientState object and get each value of each RadListBoxItem.

    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    RadListBoxClientState state = serializer.Deserialize<RadListBoxClientState>(newValue);
    for (int i = 0; i < state.LogEntries.Length; i++)
    {
         newValue = state.LogEntries[i].Data["value"].ToString();
         fieldTermsTable.Rows.Add(new string[2] { newTermAF.Name, newTermAFValue });
    }


    Thanks!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017