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

ComboBox e.Value Incorrect

9 Answers 157 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 17 Jan 2011, 06:49 PM

I am using the Combo Box (latest version of ASP.NET AJAX components) and catching the control when the user selects a new item in the list.  I need the Value the user selected, NOT the Text, but the new Text appears to be the only I can capture.  When the user selects a new item, my code fires properly and I capture e.text, e.oldtext, e.value, and e.oldvalue.  When I do this, the e.text and e.oldtext accurately reflect the results, but the e.value and e.oldvalue are identical -- they are both the OLD value. 

I have attached a screen capture that shows the results, plus it also shows the contents of the Text/Value pairs that the combo box was loaded with.

The code for the .aspx file is:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LanguageSelector.ascx.cs" Inherits="HomesOnlineNetwork100.UserControls.LanguageSelector" %>
  
<telerik:RadComboBox ID="LanguageSelectorComboBox" runat="server" AutoPostBack="true"
    onselectedindexchanged="LanguageSelectorComboBox_SelectedIndexChanged" ></telerik:RadComboBox>
  
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="e.Text:"></asp:Label>   <asp:Label ID="etext" runat="server" Text="UserLanguageKey"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="e.OldText:"></asp:Label>   <asp:Label ID="eoldtext" runat="server" Text="UserLanguageKey"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="e.Value:"></asp:Label>   <asp:Label ID="evalue" runat="server" Text="UserLanguageKey"></asp:Label>
<br />
<asp:Label ID="Label4" runat="server" Text="e.OldValue:"></asp:Label>   <asp:Label ID="eoldvalue" runat="server" Text="UserLanguageKey"></asp:Label>
<br />
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Loaded Text/Values:"></asp:Label>
<br />
<asp:Label ID="Label6" runat="server" Text=""></asp:Label>

The applicable code for the SelectedIndexChanged is:

protected void LanguageSelectorComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    Session["a"] = e.Value;
    Session["b"] = e.OldValue;
    Session["c"] = e.Text;
    Session["d"] = e.OldText;

The applicable code for the Page_Load event is:

protected void Page_Load(object sender, EventArgs e)
{
        this.evalue.Text = Convert.ToString(Session["a"]);
        this.eoldvalue.Text = Convert.ToString(Session["b"]);
        this.etext.Text = Convert.ToString(Session["c"]);
        this.eoldtext.Text = Convert.ToString(Session["d"]);
}

Can anyone please tell me why this is happening?  I need the new VALUE that the user selected because that is the key to the related database record.  Why doesn't the new VALUE come through the event?

My thanks in advance!

Lynn

9 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 18 Jan 2011, 01:15 PM
Hello Lynn,

I've prepared a small example page, where you could directly get all the information you need and show it in the labels as it's in your scenario.

You don't need the Session object if it's not a required part of your scenario of course.

Greetings,
Dimitar Terziev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Lynn
Top achievements
Rank 2
answered on 18 Jan 2011, 02:26 PM
Dimitar,

Thank you for taking the time to respond to my question, but (and no offense intended) you kind of "changed the rules" to come up with an example that would work...Let me explain.

I have a database table that contains (among other fields) an "identity" key column and a name column.  I need to populate the combo box with the "Text" = the name column and the "Value" = the key column.  When the user selects an item in the combo box (by viewing the name), the code must then obtain the selected key column from the combo box and then read the database record to retrieve other pertinent information.  In this situation, the "Text" and the "Value" properties of each combo box item must be different.

In my example, the combo box correctly returned the newly selected "Text" and the old "Text", but erred and returned the old "Value" for the both the new and old settings.

In your example, you "changed these rules" and made the "Text" and "Value" properties the same.  Obviously when doing this, the combo box is going to operate fine.  You need to make the "Value" properties different from the "Text" values and show me how the combo box works.  Personally, I think I need to open a bug report, because that is what this is.

Thanks for your effort.

Lynn
0
Dimitar Terziev
Telerik team
answered on 18 Jan 2011, 03:06 PM
Hello Lynn,

Thank you for contacting us again.

There is no difference whether Text and Value are the same or not. I've prepared another example where the combobox is binded to a DataTable similar to the database you are using, showing you that the values in the labels are populated properly.
I hope this would help.

Best wishes,
Dimitar Terziev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
whui
Top achievements
Rank 1
answered on 17 Jul 2011, 12:54 PM
I have the same question. In the event of SelectedChanged, the e.Text is correct,the e.value is incrorrect; I think it's a bug .
0
Simon
Telerik team
answered on 18 Jul 2011, 01:33 PM
Hi Whui,

Which version of Telerik.Web.UI are you using? If you are not using the latest, can you please try with the latest trial to see if the issue exists and send us a sample markup, which reproduces the issue?

Regards,
Simon
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
whui
Top achievements
Rank 1
answered on 19 Jul 2011, 05:37 AM
            I'm using the latest version of 2011.7.12.There are serival usercontrols based on the RadCombox,none of them worked in the right way when I've updated  my project to the latest version. In the event of SelectedChanged,I get the old value form the e.Value,but the e.Text is  agree with the current selectedItem.  

          You can create serival selectItems whose value are diffrent with text. For example, value=1,Text="One".I think it's easy to find out the problem.

          Best wishes,  
          whui
0
Simon
Telerik team
answered on 21 Jul 2011, 11:17 AM
Hi Whui,

With the latest version of Telerik.Web.UI I loaded up a RadComboBox with the following xml and both the Text and Value properties in the event arguments of the SelectedIndexChanged event handler were correct:
<?xml version="1.0" encoding="utf-8" ?>
<Items>
  <Item Text="One" Value="1" />
  <Item Text="Two" Value="2" />
  <Item Text="Three" Value="3" />
  <Item Text="Four" Value="4" />
  <Item Text="Five" Value="5" />
</Items>

Please let me know if I am missing something and/or provide the markup of a RCB, which reproduces the issue.

Kind regards,
Simon
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
whui
Top achievements
Rank 1
answered on 06 Sep 2011, 11:46 AM
The problem was fixed in Telerik.Web.UI_2011_2_906_Dev_hotfix.zip
0
Lee
Top achievements
Rank 1
answered on 11 Jan 2012, 01:58 PM
Sorry, ignore this post!
Tags
ComboBox
Asked by
Lynn
Top achievements
Rank 2
Answers by
Dimitar Terziev
Telerik team
Lynn
Top achievements
Rank 2
whui
Top achievements
Rank 1
Simon
Telerik team
Lee
Top achievements
Rank 1
Share this question
or