DropDownList posted value

17 posts, 2 answers
  1. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 06 Mar 2015 Link to this post

    I have built a custom from on the server using Rad controls that include a DropDownList.  All the controls return a select value except for DropDownList.

    Each control returns a pair of values, the singular selected value and a second long dictionary type string with more information on the control and its selected value

    For example a Rad Input Text box will return two fields:

    key = "ctl00$MainContentMembers$tsupcontrol_0"
    value = "Mick"

    and
    key = "ctl00_MainContentMembers_tsupcontrol_0_ClientState"
    value = "{\"enabled\":true,\"emptyMessage\":\"Display Name\",\"validationText\":\"Mick\",\"valueAsString\":\"Mick\",\"lastSetTextBoxValue\":\"Mick\"}"

    Isn't it nice how the number zero can fall be take off the end of $tsupcontrol_ to get the control number.

    A DropDownList  only returns the second dictionary item and no single value with the selection.
    key = "ctl00_MainContentMembers_tsupcontrol_3_ClientState" 
    value = "{\"enabled\":true,\"logEntries\":[],\"selectedIndex\":3,\"selectedText\":\"Four%20is%20square\",\"selectedValue\":\"Four\"}"

    My post parsing looks for $tsupcontrol_ to find the values and gets to ignore the more complicated compound values.  Now I must complicate my code having to look for non $tsupcontrol_ values because DropDownList does not output a single return value which can be easily seen as "selectedValue" in the complicated string.  I have a Asp radio button list that gives the selected value just fine.

    Is this a bug I must work around or is there a way to make the control return its selected value properly like the other well behaved controls?  Since the control is constructed in server code I cannot use Javascript to reference it or reference it as a runat control on the server.

    George
  2. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 08 Mar 2015 in reply to George Link to this post

    The dropdown is only value that uses ClientState so I had to was required to write special code to look after this bug just to get the string.

    The work around this bug to get the actual value from the returned JSON string is...
    if (fieldType == FieldTypes.Dropdown) {
        if (Helper.IsEmpty(value)) {
             return;
        }
        JToken token = JObject.Parse(value);
        value = (string)token.SelectToken("selectedValue");
    }

    The empty value check is needed because of a second bug.  If the form has a validation error on any control then when the validation is fixed the dropdown returns an empty string for its JSON value. It does return the ClientState but empty.  I cannot think of a work around for this one, it is just a straight up bug my users will complain about until Telerik does something about it. Nice getting to play the blame game at least.

    It feels like the posting aspect of the drop down was simply not tested.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 11 Mar 2015 Link to this post

    Hello George,

    I would suggest using the RadDropDownList client-side or server-side API In order to retrieve the RadDropDownList selected value instead of parsing the client state.

    For example on the server you can access it as shown:
    //code behind
    RadDropDownList1.SelectedValue

    On the client-side:
    //JavaScript
    $find("ctl00_ContentPlaceholder1_RadDropDownProducts").get_selectedItem().get_value()


    Regards,
    Boyan Dimitrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 11 Mar 2015 in reply to Boyan Dimitrov Link to this post

    I take it that you do not consider it a bug for the dropdown list to not return data reliably and in a manner consistent with the other controls. Personally I think this is completely unacceptable for software that costs as much as it does.

    Your work around will not work for me. I am using an arbitrarily defined set of definitions to create a form in code, the dropdown is created in code resulting in no server-side ASP API being available (i.e. there is no runat the dropdown which is not registered with the form). Using a client side api would be more complicated than it is worth since the java script could not know the control name in advance or how many dropdowns there might be.  

    Using posted data is used many applications and is required for my application, the Rad dropdown does not behave properly in posted data. Pease admit is a bug and say it will be fixed in a future drop. If you cannot do this, then the solution would be to use a different control than Telerik's Rad dropdown.

    George
  6. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 16 Mar 2015 Link to this post

    Hello George,

    I am afraid that there is no generic way of generating the control's client state in order to be same for all controls. In general the client-state is intended to be used internally in order to recreate the control, but not for retrieving the selected value or etc. For such purposes we suggest using the control's API (server-side or client-side). 

    As a possible workaround you can create a JavaScript serializer object and deserialize the RadDopDownList client-state.  
    //code
    RadDropDownListClientState clientState = null;
     
    var serializer = new JavaScriptSerializer();
     
    try
    {
        clientState = serializer.Deserialize<RadDropDownListClientState>(clientStateValue);
        clientState.SelectedText = DecodeText(clientState.SelectedText);
        clientState.SelectedValue = DecodeText(clientState.SelectedValue);
    }

    In this case you can get the selected way much easier. 

    Regards,
    Boyan Dimitrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 16 Mar 2015 in reply to Boyan Dimitrov Link to this post

    My form could have some number of dropdowns, doing any work on the client is not very realistic.

    If the RadDropDownList cannot reliably return  a posted value I guess it is not a control I should be using.  I had thought reliable post data would be a priority for html controls. 
  8. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 19 Mar 2015 Link to this post

    Hello,

    In order to avoid any further confusions please note that the provided code in my last response should be executed on the server. 
    //code
    protected void Page_Load(object sender, EventArgs e)
        {
            string cs = Request.Form["RadDropDownList1_ClientState"];
            var serializer = new JavaScriptSerializer();
            RadDropDownListClientState clientState;
            try
            {
                clientState = serializer.Deserialize<RadDropDownListClientState>(cs);
                string SelectedText = clientState.SelectedText;
                string SelectedValue = clientState.SelectedValue;
            }
            catch (Exception)
            {
     
                throw;
            }
         }


    Regards,
    Boyan Dimitrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 26 Mar 2015 in reply to Boyan Dimitrov Link to this post

    The final answer from a ticket is that the RadDropDownList does not post data because of its implementation as bunch of divs.  That reminds me  of Kendo.  ClientState is an Telerik internal data item posted for the Telerik control.  ClientState cannot be relied upon because it only posts when the control is changed which messes up on validations.

    The solution to my problem is to instead use the asp dropdown which simply posts its selected value on every post.  And then worry about the style implications of Telerik styles verses Bootstrap.

    George
  10. Charles Wiebe
    Charles Wiebe avatar
    11 posts
    Member since:
    Feb 2010

    Posted 21 Nov Link to this post

    I just came across this same issue while integrating RadDropDownList and RadComboBox from the latest ASP.NET release.

    Boyan - what you say is correct IF and ONLY IF the postback is caused by the control, i.e. the RadDropDownList or RadComboBox.

    However, George is correct in saying that WHEN a postback is caused by a different control, such as a button, then the values for the RadDropDownList or RadComboBox cannot be found.

    This is important because if I am building a form which used RadDropDownList or RadComboBox with autopostback = false, then the correct values will not be available to the form.

    Unfortuately, the solution is to use vanilla ASP.NET DropDownList.

  11. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 24 Nov Link to this post

    Hello Charles,

    Does your scenario involve dynamically adding the RadDropDownList to the page or it is declared in the markup?

    Regards,
    Ivan Danchev
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
  12. Charles Wiebe
    Charles Wiebe avatar
    11 posts
    Member since:
    Feb 2010

    Posted 24 Nov in reply to Ivan Danchev Link to this post

    The code is added dynamically in code behind.
  13. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 25 Nov Link to this post

    Hello Charles,

    I was specifically referring to the DropDownList being created on the server or in the markup. In case it is the former then on every postback the DropDownList is created anew, thus no information about the selected item is kept. Whereas if the control is declared in the markup information about the selected item can be accessed on the server when the postback is initiated by another control (a Button for example). If the item selected has both Text and Value set:
    <telerik:DropDownListItem Text="ListItem2" Value="2"></telerik:DropDownListItem>
    the DropDownList's SelectedText and SelectedValue properties will return the corresponding values ("ListItem2" and "2").

    Regards,
    Ivan Danchev
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
  14. Charles Wiebe
    Charles Wiebe avatar
    11 posts
    Member since:
    Feb 2010

    Posted 25 Nov in reply to Ivan Danchev Link to this post

    The DropDownList is created in code behind.

    I do all of my coding in code behind. With much more complicated Telerik controls, they behave as expected on postback - i.e. providing the updated value.

    I am surprised that relatively simpler controls like DropDownList and RadComboBox do not provide the updated values when a form is posted to the server.

    As I noted, since the DropDownList does not provide updated values upon postback of a form, I use the ASP.NET DropDownList.

  15. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 25 Nov Link to this post

    Hello Charles,

    I tested the behavior of a dynamically added RadDropDownList and asp:DropDownList with version 2016.3.1027 of the controls and the RadDropDownList's SelectedValue property contained the expected value after a postback. Could you give the attached runnable sample page a try and elaborate more on the different behavior of both controls you have noticed. It would be helpful if you could modify the sample recreating the specific scenario the difference can be observed in.

    Regards,
    Ivan Danchev
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
  16. Charles Wiebe
    Charles Wiebe avatar
    11 posts
    Member since:
    Feb 2010

    Posted 25 Nov in reply to Ivan Danchev Link to this post

    Thank you for the ButtonPostbackTest.zip file. It does work. When converted to a Control in a page, it does work for this simple coding example.

    However, the FormValue for both above tests - in this case RadDDList1_ClientState is empty.

    I am expecting that the new selected value is present in the Context.Request.Form posted back values.

    It does not matter whether the selected value is '2' or the JSON for the RadDropDownList. It just needs to be present.

  17. Charles Wiebe
    Charles Wiebe avatar
    11 posts
    Member since:
    Feb 2010

    Posted 25 Nov Link to this post

    After hitting the post this reply, I realized that I do not need to get the value for the RadDropDownList from the form because it is already updated to the new value. Perfect!

    There is definitely a note required in the docs.telerik.com for this control to say that it works this way.

    Now I am thinking - what a great ASP.NET world it would be if every control worked that way!

    Thank you.

  18. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 5 days and 7 hours ago Link to this post

    Hello Charles,

    Thank you for getting back to us. Both the RadComboBox and RadDropDownList behave identically in this scenario and the SelectedValue property holds the new value after postback.

    Regards,
    Ivan Danchev
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017