Getting Request.form data

4 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 19 Jul 2013 Link to this post

    First up I know I'm being lazy, but the button is in a user control, and using the request.form is easier than recreating the user control on postback and getting the value.
     
    That said how would I get the checked value of a RadButton that is configured as a toggle button to look like a checkbox? The data is in the form :

    {"text":"","value":"","checked":true,"target":"","navigateUrl":"","commandName":"","commandArgument":"","autoPostBack":false,"selectedToggleStateIndex":0,"validationGroup":null,"readOnly":false}

     
    Its the Checked value I need. .

    Andy

  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 24 Jul 2013 Link to this post

    Hi Andy,

    Request.Form command is used to retrieve user input from forms. RadButton, however, is a script control, which means that it is not rendered just as a simple input. Therefore you can use its server-side method - SelectedToggleStateIndex, in order to retrieve the checked value of the RadButton configured as a toggle button. For example:

    ASPX:
    <telerik:RadButton ID="RadButton1" runat="server" ToggleType="CustomToggle" ButtonType="ToggleButton"
        AutoPostBack="true">
        <ToggleStates>
            <telerik:RadButtonToggleState Text="UnChecked" PrimaryIconCssClass="rbToggleCheckbox"></telerik:RadButtonToggleState>
            <telerik:RadButtonToggleState Text="Filled" PrimaryIconCssClass="rbToggleCheckboxFilled"></telerik:RadButtonToggleState>
            <telerik:RadButtonToggleState Text="Checked" PrimaryIconCssClass="rbToggleCheckboxChecked"
                Selected="true"></telerik:RadButtonToggleState>
        </ToggleStates>
    </telerik:RadButton>
    <br />
    Selected Index is:
    <asp:Label ID="Label1" Text="text" runat="server" />
    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = RadButton1.SelectedToggleStateIndex.ToString();
    }

    You can also find useful the server-side API of RadButton.



    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 24 Jul 2013 Link to this post

    Thanks but as this exists in a user control it is destroyed on postback, As I said in my OP I'm looking to get the value without recreating the control on the server.

    The string values exists in the requestForm object already, was looking at a way to use it.

    Andy
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 26 Jul 2013 Link to this post

    Hello Andy,

    You can get the Client State of the RadButton from the Request.Form collection through the name of the RadButton's input name property. For example:
    ASPX:
    <telerik:RadButton ID="RadButton1" runat="server" Text="postback" />
    <myusercontrol:myUC ID="uc1" runat="server" />
    <br />
    ToggleStateIndex is:
    <asp:Label ID="Label1" runat="server" />
    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            string toggleState = Request.Form["uc1_RadButton1_ClientState"];
            int startIndex = toggleState.IndexOf("selectedToggleStateIndex") + 26;
            int length = toggleState.IndexOf(",", startIndex) - startIndex;
            toggleState = toggleState.Substring(startIndex, length);
            Label1.Text = toggleState;
        }
    }

    ASCX:
    <telerik:RadButton ID="RadButton1" runat="server" ToggleType="CustomToggle" ButtonType="ToggleButton"
        AutoPostBack="true">
        <ToggleStates>
            <telerik:RadButtonToggleState Text="UnChecked" PrimaryIconCssClass="rbToggleCheckbox"></telerik:RadButtonToggleState>
            <telerik:RadButtonToggleState Text="Filled" PrimaryIconCssClass="rbToggleCheckboxFilled"></telerik:RadButtonToggleState>
            <telerik:RadButtonToggleState Text="Checked" PrimaryIconCssClass="rbToggleCheckboxChecked"
                Selected="true"></telerik:RadButtonToggleState>
        </ToggleStates>
    </telerik:RadButton>

    where the highlighted text is the name of the RadButton's input.  Note, however, that the ClientState of the RadButton,  will only be available if the button itself is clicked. Therefore I can suggest you to use a hidden field where you can store the RadButton's ToggleState, so that it can be obtained later.


    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top