Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > Trouble reading value of combobox item on client side
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Trouble reading value of combobox item on client side

Feed from this thread
  • Shira avatar

    Posted on May 13, 2011 (permalink)

    I am trying to get a button in the edit form of my RadGrid to cause the text of one control in that form to have text value from the selected item in a dropdown control in that form appended to it.  It's almost working, but the call to CustomTextToken.get_value() seems to get the text instead of the value from the dropdown.  My strategy is to use a RadTextBox and RadComboBox for the controls holding the text, so that I can set client side on load events and store the controls to Javascript when they are loaded onto the page (should be ok since I only have one edit form open at a time), and then onclick of a button in the edit form, to call a javascript function to do the concatenation.

    Also, I'm nervous about using this strategy, because the documentation says that the client side load events might not work if you have AJAX enabled, which I do: http://www.telerik.com/help/aspnet-ajax/combobox-onclientload.html .  There are also posts that recommend the strategy, but the documentation warning gives me pause - is there a better way?

    Here's the relevant javascript from my .aspx:
    var CustomText;
    var CustomTextToken;
    // Store the id of the control for the CustomText of the item currently being edited when an editform is expanded
    function OnCustomTextLoaded(sender) {
        CustomText = sender;
    }
    // Store the id of the control for the CustomText token of the item currently being edited when an editform is expanded
    function OnCustomTextTokenLoaded(sender) {
        CustomTextToken = sender;
    }
    // Use stored CustomText and CustomText token objects to add the token to the subject text
    function AddTokenToCustomText() {
        CustomText.set_value(CustomText.get_value() + CustomTextToken.get_value());
    }

    and the contents of the edit form that call the javascript:

        <td class="label">
            <asp:Label ID="lblSubsectionCustomText" runat="server"></asp:Label>
        </td>
        <td>
            <Telerik:RadTextBox ID="tbSubsectionCustomText" runat="server" Text='<%# Eval("CustomText") %>' Width="500px"  TextMode="MultiLine" Rows="5" ClientEvents-OnLoad="OnCustomTextLoaded"/>
        </td>
        <td>
               
        </td>
        <td>
            <div id="SubsectionCustomTextTokenDiv" runat="server" />
        </td>
        <td>
               
        </td>
        <td>
            <Telerik:RadComboBox ID="ddlSubsectionCustomTextToken" runat="server" OnClientLoad="OnCustomTextTokenLoaded" />
        </td>
    </tr>

    and the code-behind that populates the controls:

    // Set up Token button 
    System.Web.UI.HtmlControls.HtmlGenericControl divTag = editItem.FindControl("SubsectionCustomTextTokenDiv") as System.Web.UI.HtmlControls.HtmlGenericControl;
    divTag.InnerHtml = "<input id=\"btnAddTokenToCustomText\" type=\"button\" class=\"Button1\" " +
                        "onclick=\"AddTokenToCustomText() \" value=\"" + CoreWebTranslation.GetString(CoreWebUIResourceKeys.NOTIF_LBL_ADD_TOKEN) + "\" /> ";
    // Set up Token dropdown
    List<ListItem> items = new List<ListItem>();
    RadComboBox ddlSubsectionCustomTextToken = editItem.FindControl("ddlSubsectionCustomTextToken") as RadComboBox;
    string siteName = "Site Name Token";
    items.Add(new ListItem { Text = siteName, Value = "{{SiteNameToken}}" });
    string userName = "Triggering User Token";
    items.Add(new ListItem { Text = userName, Value = "{{TriggeringUserToken}}" });
    ddlSubsectionCustomTextToken.DataSource = items;
    ddlSubsectionCustomTextToken.DataBind();

    How to get the value instead?

    Thanks!

  • Helen Helen admin's avatar

    Posted on May 18, 2011 (permalink)

    Hi Shira,

    Could you please try to bind the RadComboBox like the following:

    // Set up Token dropdown
         DataTable table = new DataTable();
     
        table.Columns.Add("Text");
        table.Columns.Add("Value");
     
        table.Rows.Add(new string[] { "1", "1" });
        table.Rows.Add(new string[] { "11", "11"});
        table.Rows.Add(new string[] { "12", "12"});
        table.Rows.Add(new string[] { "13", "13"});
        ddlSubsectionCustomTextToken.DataSource = table;
        ddlSubsectionCustomTextToken.DataTextField = "Text";
        ddlSubsectionCustomTextToken.DataValueField = "Value";
        ddlSubsectionCustomTextToken.DataBind();
    }

    Regards,
    Helen
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  • Shawn Taylor avatar

    Posted on May 18, 2011 (permalink)

    Thanks!  That did it.  The key was assigning the DataTextField and DataValueField.  I didn't realize that even when it's a collection of ListItems, that still has to be explicitly specified.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > Trouble reading value of combobox item on client side