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

RadListBox fires client events on load

6 Answers 35 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Veteran
David asked on 12 Aug 2014, 04:32 PM
I want to have some javascript code on OnClientReordering. It works fine however code also fires on load or databind of the RadListBox.
Please help!

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 13 Aug 2014, 05:31 AM
Hi David,

Unfortunately I couldn't replicate the issue at my end. Please have a look into the sample code snippet which works fine at my end. Please provide your code if it doesn't help.

ASPX:
<telerik:RadListBox ID="rlistboxDemoItems" runat="server" EnableDragAndDrop="true"
    AllowReorder="true" OnClientReordering="reOrderList">
</telerik:RadListBox>
<asp:SqlDataSource ID="sqlOrders" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [OrderID], [CustomerID] FROM [Orders]"></asp:SqlDataSource>

JavaScript:
function reOrderList(sender, args) {
    alert("fired");
}

Thanks,
Shinu.
0
David
Top achievements
Rank 1
Veteran
answered on 13 Aug 2014, 12:38 PM
Hi Shinu,

   I don't use SqlDataSource in this case, but load listbox on SelectedIndexChanged event of another dropdown.
   Here are is the code. Thank you

   <telerik:RadListBox ID="ddlActivities" runat="server"
            Width="270px" Height="200px"
            style="text-align:left !important; margin-right:25px;"
            SelectionMode="Multiple" AllowTransfer="true" TransferToID="ddlSelectedActivities"             
            DataValueField="ActivityID" DataTextField="ActivityName2"
            Skin="WebBlue">              
        </telerik:RadListBox>

       -- code behind
       Dim strSQL As String = "SELECT *, ia.ActivityName & ' (' &  (SELECT count(*) " & _
                               "             FROM ImpactEvent WHERE ActivityID =  ia.ActivityID ) & ')' AS ActivityName2 " & _
                               "     FROM ImpactActivity AS ia " & _
                               "  WHERE  ia.ActivityID NOT IN (SELECT ActivityID FROM ImpactRunImpactActivity " & _
                               "                                  WHERE RunID=" & rcbScenarios.SelectedValue & ") " & _
                               " ORDER BY ia.ActivityName ASC"
        Dim dtImpactActivity As DataTable = AccessHelper.getAccessDatatable(strSQL, cn)
        ddlActivities.DataSource = dtImpactActivity.Select("", "OrderID ASC").CopyToDataTable()
        ddlActivities.DataBind()
0
Shinu
Top achievements
Rank 1
answered on 14 Aug 2014, 05:16 AM
Hi David,

From you code I have noticed You are not setting AllowReorder property for RadListBox. In order to fire OnClientReordering try to set the AllowReoreder property. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadDropDownList ID="rdroplistOrders" runat="server" DataSourceID="sqlOrders" DataTextField="OrderID" DataValueField="ShipCity" AutoPostBack="true" OnSelectedIndexChanged="rdroplistOrders_SelectedIndexChanged">
</telerik:RadDropDownList>
<telerik:RadListBox ID="rlistboxCustomerDetails" runat="server" EnableDragAndDrop="true"
    AllowReorder="true" OnClientReordering="reOrderList">
</telerik:RadListBox>

C#:
protected void rdroplistOrders_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
{
    string sql = "SELECT CustomerID,City from Customers where City='"+e.Value+"'";
    SqlDataAdapter adapter = new SqlDataAdapter(sql,ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    DataTable data = new DataTable();
    adapter.Fill(data);
    rlistboxCustomerDetails.DataSource = data;
    rlistboxCustomerDetails.DataTextField = "CustomerID";
    rlistboxCustomerDetails.DataValueField = "City";
    rlistboxCustomerDetails.DataBind();
}

JavaScript:
function reOrderList(sender, args) {
    alert("fired");
}

Thanks,
Shinu.
0
David
Top achievements
Rank 1
Veteran
answered on 14 Aug 2014, 12:34 PM
Hi Shinu,

   I didn't set AllowReorder because it was giving me trouble i described. I apologize for not adding it back for the example.
   Anyways, i found the source of an issue. Surprisingly 'updateAnalysisButtonToYellow(2)' function is getting called on every page load unless i remove parameter. So, OnClientReordering="updateAnalysisButtonToYellow" (without argument) is getting called only on reorder how it should. Any ideas?

<telerik:RadListBox ID="ddlActivities" runat="server"
            Width="270px" Height="200px"
            style="text-align:left !important; margin-right:25px;"
            SelectionMode="Multiple" AllowTransfer="true" TransferToID="ddlSelectedActivities"             
            DataValueField="ActivityID" DataTextField="ActivityName2"
            AllowReorder="true" OnClientReordering="updateAnalysisButtonToYellow(2)"
            Skin="WebBlue">              
        </telerik:RadListBox>
0
Boyan Dimitrov
Telerik team
answered on 15 Aug 2014, 01:04 PM
Hello,

The client event handler functions have some predefined parameters which are come out of the box when you set this function to be an event handler for a specific event. So I would suggest reviewing this help article and use the function without parameters.

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.

 
0
David
Top achievements
Rank 1
Veteran
answered on 15 Aug 2014, 07:53 PM
This limitation is a little surprising, but i can work around it. Thx
Tags
ListBox
Asked by
David
Top achievements
Rank 1
Veteran
Answers by
Shinu
Top achievements
Rank 1
David
Top achievements
Rank 1
Veteran
Boyan Dimitrov
Telerik team
Share this question
or