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

Relational Combobox is loosing selected item in postback

4 Answers 110 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Thenmozhi
Top achievements
Rank 1
Thenmozhi asked on 03 Jan 2011, 05:25 PM
Hi,

I have 3 combobox in my form Radcombobox1,Radcombobox2,Radcombobox2..

And i have done the following in my design

<tr>
        <td><asp:RequiredFieldValidator id="RequiredFieldValidator1"  
  runat="server" ErrorMessage="*"
  ControlToValidate="RadComboBox1"  
  InitialValue="Select Country" ValidationGroup="valorg">
</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator id="RequiredFieldValidator7"  
  runat="server" ErrorMessage="*"
  ControlToValidate="RadComboBox1"  
  InitialValue="" ValidationGroup="valorg">
</asp:RequiredFieldValidator>

Country</td>
        <td>:</td>
        <td>
          
            <telerik:RadComboBox ID="RadComboBox1" Runat="server"
            OnClientSelectedIndexChanging="LoadStates"
                OnItemsRequested="RadComboBox1_ItemsRequested"
                 ShowMoreResultsBox="true" Skin="Windows7"
                
                 >
            </telerik:RadComboBox>
        </td>
        </tr>
        <tr>
        <td><asp:RequiredFieldValidator id="RequiredFieldValidator2"  
  runat="server" ErrorMessage="*"
  ControlToValidate="RadComboBox2"
  InitialValue="Select State"
   ValidationGroup="valorg">
</asp:RequiredFieldValidator><asp:RequiredFieldValidator id="RequiredFieldValidator10"  
  runat="server" ErrorMessage="*"
  ControlToValidate="RadComboBox2"
  InitialValue=""
   ValidationGroup="valorg">
</asp:RequiredFieldValidator>State</td>
        <td>:</td>
        <td>
          
            <telerik:RadComboBox ID="RadComboBox2" Runat="server"
             OnClientSelectedIndexChanging="LoadCities"
                OnClientItemsRequested="ItemsLoaded"
                OnItemsRequested="RadComboBox2_ItemsRequested" >
            </telerik:RadComboBox>

        </td>
        </tr>
        <tr>
        <td><asp:RequiredFieldValidator id="RequiredFieldValidator3"  
  runat="server" ErrorMessage="*"
  ControlToValidate="RadComboBox3"
  InitialValue="Select City" ValidationGroup="valorg">
</asp:RequiredFieldValidator><asp:RequiredFieldValidator id="RequiredFieldValidator11"  
  runat="server" ErrorMessage="*"
  ControlToValidate="RadComboBox3"
  InitialValue="" ValidationGroup="valorg">
</asp:RequiredFieldValidator>City</td>
        <td>:</td>
        <td>:<telerik:RadComboBox ID="RadComboBox3" Runat="server"
        
        OnClientItemsRequested="ItemsLoaded"
                OnItemsRequested="RadComboBox3_ItemsRequested"
        >
            </telerik:RadComboBox>
            </td>
        <td>
          
        </td>
        </tr>
Added below script in Body

<script type="text/javascript">
    //global variables for the countries and cities comboboxes
    var countriesCombo;
    var citiesCombo;

    function pageLoad() {
        // initialize the global variables
        // in this event all client objects
        // are already created and initialized
        countriesCombo = $find("<%= RadComboBox2.ClientID %>");
        citiesCombo = $find("<%= RadComboBox3.ClientID %>");
       
    }

    function LoadStates(combo, eventArqs) {
        var item = eventArqs.get_item();
        countriesCombo.set_text("Loading...");
        citiesCombo.clearSelection();

        // if a continent is selected
        if (item.get_index() > 0) {
            // this will fire the ItemsRequested event of the
            // countries combobox passing the continentID as a parameter
            countriesCombo.requestItems(item.get_value(), false);
        }
        else {
            // the -Select a continent- item was chosen
            countriesCombo.set_text(" ");
            countriesCombo.clearItems();

            citiesCombo.set_text(" ");
            citiesCombo.clearItems();
        }
    }

    function LoadCities(combo, eventArqs) {
        var item = eventArqs.get_item();

        citiesCombo.set_text("Loading...");
        // this will fire the ItemsRequested event of the
        // cities combobox passing the countryID as a parameter
        citiesCombo.requestItems(item.get_value(), false);
    }

    function ItemsLoaded(combo, eventArqs) {
        if (combo.get_items().get_count() > 0) {
            // pre-select the first item
            combo.set_text(combo.get_items().getItem(0).get_text());
            combo.get_items().getItem(0).highlight();
        }
        combo.showDropDown();
    }


        </script>

In Code Behind i have coded as below


 # region "Page Load"
    protected void Page_Load(object sender, EventArgs e)
    {

       // fn_createlandingpageforclient("Esthetic Smile Dental Clinic", "jks@jks.com", "drdsatish@gmail.com");

        try
        {
            Label1.Text = string.Empty;
            if (!IsPostBack)
            {
                //loadcountry(ddlcountry);
                loadcountry(RadComboBox1);
                //loadstate(ddlstate, ddlcountry.SelectedItem.Text);
                //loadstate(RadComboBox2, RadComboBox1.SelectedItem.Text);
                //loadcity(ddlcity, ddlcountry.SelectedItem.Text, ddlstate.SelectedItem.Text);
                //loadcity(RadComboBox3 , RadComboBox1.SelectedItem.Text, RadComboBox2.SelectedItem.Text);
            }
        }
        catch (Exception ex)
        {
            DAL.UnknownError objUnknownError = new UnknownError();
            objUnknownError.ReturnError(ex.Message);
        }


    }
    # endregion
 # region "Rad Combo box Itemrequested"
    protected void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {

        //loadstate(RadComboBox2, e.Text);
        
    }

    protected void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {
        // e.Text is the first parameter of the requestItems method
        // invoked in LoadCountries method
        //loadcountry(RadComboBox1);
        Session["country"] = e.Text;
        loadstate(RadComboBox2, e.Text);
        
    }

    protected void RadComboBox3_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {
        // e.Text is the first parameter of the requestItems method
        // invoked in LoadCities method
        //LoadCities(e.Text);
        loadcity(RadComboBox3,Convert.ToString(Session["country"]), e.Text);

    }
    # endregion

I have a radcaptcha with custom httphandler to avoid the image change in postbacks..

While i am saving the Radcombobox2 and Radcombobox3 are loosing the items..

As it is very urgent issue..Please suggest me the solution..


Thanks
Thenmozhi.R

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 04 Jan 2011, 08:43 AM
Hello Thenmozhi,

Please set EnableLoadOnDemand property of the comboboxes to "true" and let us know how it goes.

Regards,
Yana
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
Thenmozhi
Top achievements
Rank 1
answered on 04 Jan 2011, 11:22 AM
It is not solved my issue.

While clicking save button the rad captcha is validated and even the validation controls are passing as valid.

but in code if i check the combo box.selected item.text is is returning null.

Then i debugged in my code i found the first combo box is loosing selected item..

So the related combo's are loosing the items..

Don't get any idea where it is missing the selected item.. if it is missing before the validation controls will not allow to come to button click code.

Please suggest me how to proceed...
0
Yana
Telerik team
answered on 07 Jan 2011, 12:43 PM
Hello Thenmozhi,

We cannot reproduce this issue with the provided code. Please send us runnable example which we can easily test. Thanks

Regards,
Yana
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
Cori
Top achievements
Rank 2
answered on 07 Jan 2011, 02:37 PM
Hello Thenmozhi,

I don't believe your able to access the SelectedItem property when using LoadOnDemand. I always use SelectedValue or Text when using LoadOnDemand, to get the item that was selected.

I hope that helps.
Tags
ComboBox
Asked by
Thenmozhi
Top achievements
Rank 1
Answers by
Yana
Telerik team
Thenmozhi
Top achievements
Rank 1
Cori
Top achievements
Rank 2
Share this question
or