RadListBox fires client events on load

7 posts, 0 answers
  1. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 12 Aug 2014 Link to this post

    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!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Aug 2014 in reply to David Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 13 Aug 2014 Link to this post

    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()
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2014 in reply to David Link to this post

    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.
  6. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 14 Aug 2014 in reply to Shinu Link to this post

    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>
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 15 Aug 2014 Link to this post

    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.

     
  8. David
    David avatar
    159 posts
    Member since:
    Mar 2014

    Posted 15 Aug 2014 in reply to Boyan Dimitrov Link to this post

    This limitation is a little surprising, but i can work around it. Thx
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017