This is a migrated thread and some comments may be shown as answers.

Retrieving ComboBox Value through Request.Form

7 Answers 326 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
fightclub777
Top achievements
Rank 1
fightclub777 asked on 14 Mar 2008, 03:36 AM
Hello,

I have a particular scenario where I need to retrieve the ComboBox Value through a Request.Form method.

For a standard ASP.NET dropdownlist control, the following code returns the selected item value:

Request.Form("DropDownID")

However, with the comboBox, I cannot get the value.  Upon finding the control Key, i see that there are two options:

"ComboBoxID_Input", which returns the Text Value and
"CombboBoxID_ClientState", which returns something like this:

"{"logEntries":[],"value":"1461","text":"5 Business Days","enabled":true}"

Is there a way to extract the value easily, without having to dissect the "clientState" string?

Thank you.

7 Answers, 1 is accepted

Sort by
0
fightclub777
Top achievements
Rank 1
answered on 18 Mar 2008, 07:30 AM
no one? :(
0
Accepted
Simon
Telerik team
answered on 18 Mar 2008, 09:51 AM
Hi fightclub777,

These two fields: "ComboBoxID_Input" and "ComboBoxID_ClientState" contain all additional information of the RadComboBox. The only way to get the value as you require is to parse the client state string. You could use the following approach:
        string clientState = Request.Form[this.RadComboBox1.ClientID + "_ClientState"]; 
 
        Regex regex = new Regex(".+\"value\":\""); 
 
        clientState = regex.Replace(clientState, String.Empty); 
 
        regex = new Regex("\",\"text\".+"); 
 
        clientState = regex.Replace(clientState, String.Empty); 

Finally, in the clientState variable you have the value of the RadComboBox.

I hope this helps.

Kind regards,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
bemara57
Top achievements
Rank 1
answered on 08 May 2008, 03:56 PM
Boy is this ugly.. but it works. Hopefully you guys find a way to make it more standard so I can just do Request.Form[dropDownUniqueID]. Doing it your way added about 20 lines of code for each dropdown value I want to retrieve instead of just a one liner "Request.Form[dropDownUniqueID]". I have to add a static class that stores the UniqueID AND the ClientID, then run some nested if statements to get the value. Here's what I did:

Static class:
        public static string ThemeDropDownUniqueID = String.Empty;
        public static string ThemeDropDownClientID = String.Empty;

On some aspx code behind page:
        if (ThemeProviderCustom.ThemeDropDownUniqueID.Length == 0)
            ThemeProviderCustom.ThemeDropDownUniqueID = themeDropDown.UniqueID;

        if (ThemeProviderCustom.ThemeDropDownClientID.Length == 0)
            ThemeProviderCustom.ThemeDropDownClientID = themeDropDown.ClientID;

On some other base page (need to do this in the PreOnInit because this changes MasterPage):
                if (Request.Form["__EVENTTARGET"] == ThemeProviderCustom.ThemeDropDownUniqueID)                   
                {
                    string clientState = Request.Form[
                        ThemeProviderCustom.ThemeDropDownClientID + "_ClientState"];

                    if (!clientState.IsNullOrEmpty())
                    {                       
                        Regex regex = new Regex(".+\"value\":\"");
                        clientState = regex.Replace(clientState, String.Empty);

                        regex = new Regex("\",\"text\".+");
                        clientState = regex.Replace(clientState, String.Empty);

                        Globals.SiteAdmin.Page.Theme.Layout = clientState;
                    }
                }

So I've encapsulated into a reusable method (just use string.IsNullOrEmpty instead of IsNullOrEmpty()):
        // Request.Form workaround to get value of RadComboBox 
        public static string GetRadComboBoxFormValue(string clientID) 
        { 
            string clientState = HttpContext.Current.Request.Form[ 
                clientID + "_ClientState"]; 
 
            if (!clientState.IsNullOrEmpty()) 
            { 
                Regex regex = new Regex(".+\"value\":\""); 
                clientState = regex.Replace(clientState, String.Empty); 
 
                regex = new Regex("\",\"text\".+"); 
                clientState = regex.Replace(clientState, String.Empty); 
            } 
 
            return clientState; 
        } 

So now I only have to do this: string ddlFormValue = Helpers.GetRadComboBoxFormValue(
                        ThemeProviderCustom.ThemeDropDownClientID);

Hope it alleviates the process a bit for someone as it did for me. Thanks Simon!
0
Simon
Telerik team
answered on 12 May 2008, 08:47 AM
Hi bemara57,

Recently, we received a few more questions related to this 'limitation' of RadComboBox. It appears that it would be useful if one could get the Value of the RadComboBox in a more straightforward and standard way.

So, we published a KB article which outlines how the limitation can be overcome in a rather simpler way. You can check out the article here.

I hope you find it useful.

Greetings,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jay
Top achievements
Rank 1
answered on 07 Nov 2008, 07:58 PM
FYI, the link to this article seems to no longer work.
0
fightclub777
Top achievements
Rank 1
answered on 07 Nov 2008, 08:03 PM
In the newest version of the controls (2008.3.1105.20), the Input control is now rendered with the same ID as the combo box's uniqueID.  So if you're doing a Request.Form to get the text value, simply drop the "_input" from the Request.Form ID, and it'll work just fine.
0
Jay
Top achievements
Rank 1
answered on 07 Nov 2008, 08:07 PM
Holy Ridiculous Response Time!

Sweet, thanks, didn't even realize a new version popped up.  I need to get my head out of this project and come up for air more often!
Tags
ComboBox
Asked by
fightclub777
Top achievements
Rank 1
Answers by
fightclub777
Top achievements
Rank 1
Simon
Telerik team
bemara57
Top achievements
Rank 1
Jay
Top achievements
Rank 1
Share this question
or