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

Alert on selectionchanged

2 Answers 68 Views
MultiColumnComboBox
This is a migrated thread and some comments may be shown as answers.
sarthkee
Top achievements
Rank 1
Veteran
sarthkee asked on 04 Feb 2021, 09:15 AM

Hello, I am using MultiColumnComboBox so for that i have to popup javascript alert and enable disable another MultiColumnComboBox depends on first ( on selectionindexchanged from server side).

Following is my code that i have done. but it doesn't work for me.

protected void multiColumCombobox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadMultiColumnComboBoxSelectedIndexChangedEventArgs e)
    {        
        if (multiColumCombobox1.Value=="1")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('HI');", true);

            multiColumCombobox1.Enable = true;

        }
        else
        {
               ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Bye');", true);   

               multiColumCombobox1.Enable = False;

        }
    }

 

Regards,

Sarthkee

2 Answers, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 09 Feb 2021, 07:02 AM

Hi Sarthkee,

The provided code seems fine. Please ensure that a postback to the server is performed and the event is actually fired. You can try setting the AutoPostBack property of the combo to true, or trigger a postback with another control after the selection in the multi-column Combobox has changed.

Here is the code I have used for testing:

<telerik:RadMultiColumnComboBox ID="RadMultiColumnComboBox1" runat="server" OnSelectedIndexChanged="RadMultiColumnComboBox1_SelectedIndexChanged" AutoPostBack="true"
    OnDataBinding="RadMultiColumnComboBox1_DataBinding"
    DataTextField="Name"
    DataValueField="ID">
</telerik:RadMultiColumnComboBox>

<telerik:RadMultiColumnComboBox ID="RadMultiColumnComboBox2" runat="server" Enable="false"
    OnDataBinding="RadMultiColumnComboBox2_DataBinding"
    DataTextField="Country"
    DataValueField="CountryID">
</telerik:RadMultiColumnComboBox>

C# code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        RadMultiColumnComboBox1.DataBind();
        RadMultiColumnComboBox2.DataBind();
    }
}

protected void RadMultiColumnComboBox1_DataBinding(object sender, EventArgs e)
{
    (sender as RadMultiColumnComboBox).DataSource = Enumerable.Range(1, 10).Select(x => new { ID = x, Name = "Name " + x });
}

protected void RadMultiColumnComboBox2_DataBinding(object sender, EventArgs e)
{
    (sender as RadMultiColumnComboBox).DataSource = new List<object> {
        new {CountryID = 0, Country = "USA"},
        new {CountryID = 1, Country = "Germany"},
        new {CountryID = 2, Country = "UK"},
        new {CountryID = 3, Country = "Brazil"},
    };
}

protected void RadMultiColumnComboBox1_SelectedIndexChanged(object sender, RadMultiColumnComboBoxSelectedIndexChangedEventArgs e)
{
    if (int.Parse(RadMultiColumnComboBox1.Value) % 2 == 0)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('HI');", true);
        RadMultiColumnComboBox2.Enable = true;
    }
    else
    {
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Bye');", true);
        RadMultiColumnComboBox2.Enable = false;
    }
}

Alternatively, you can use a completely client-side approach:

<script>
    function OnChange(sender, args) {
        var combo1 = sender;
        var combo2 = $find('<%= RadMultiColumnComboBox2.ClientID %>');
        if (combo1.get_value() == "1")
            combo2.set_enabled(true);
        else
            combo2.set_enabled(false);
    }
</script>

<telerik:RadMultiColumnComboBox ID="RadMultiColumnComboBox1" runat="server" AutoPostBack="false"
    OnDataBinding="RadMultiColumnComboBox1_DataBinding"
    DataTextField="Name"
    DataValueField="ID">
    <ClientEvents OnChange="OnChange" />
</telerik:RadMultiColumnComboBox>

<telerik:RadMultiColumnComboBox ID="RadMultiColumnComboBox2" runat="server" Enable="false"
    OnDataBinding="RadMultiColumnComboBox2_DataBinding"
    DataTextField="Country"
    DataValueField="CountryID">
</telerik:RadMultiColumnComboBox>

I hope this will help. Please give it a try and let me know how it goes.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
sarthkee
Top achievements
Rank 1
Veteran
answered on 09 Feb 2021, 09:57 AM
Thank you doncho..
Tags
MultiColumnComboBox
Asked by
sarthkee
Top achievements
Rank 1
Veteran
Answers by
Doncho
Telerik team
sarthkee
Top achievements
Rank 1
Veteran
Share this question
or