Home / Community & Support / Knowledge Base / RadControls for ASP.NET AJAX / FileExplorer / Pass all of the selected items' paths to the server

Pass all of the selected items' paths to the server

Article Info

Rating: 5

Article information

Article relates to

 RadFileExplorer

Created by

 Fiko, Telerik

Last modified

 August 16, 2009

Last modified by

 Fiko



HOW TO
Pass all of the selected items' paths to the server by clicking a button.

THE APPROACH
 
  1. Add the needed contols on the page
      - a Button that triggers the post back (ID="Button1")
      - a HiddenField that holds the selected items paths (ID=HiddenField1")
      - a Label - used for demonstration purposes to show the selected item's count. Its Text property is set on the    server.
  2. Attach a handler (sendItemsPathsToServer) to the OnClientClick event of the Button1. This function accepts a parameter - the button object.
  3. The handler :
    function sendItemsPathsToServer(clickedButton)  
    {  
        var oExplorer = $find("<%= RadFileExplorer1.ClientID %>"); // Find the Explorer ;  
        var selectedItems = oExplorer.get_selectedItems(); // Retrieve the selected items ;  
        var selectedItemsPaths = combinePathsInAString(selectedItems); // Get the paths as a string in specific format ;  
     
        var hiddenField = $get("<%= HiddenField1.ClientID %>"); // Find the hiddenField  
        hiddenField.value = selectedItemsPaths;  
        __doPostBack(clickedButton.name, ""); // Call the 'Button1_Click' function on the server ;  
  4. The combinePathsInAString function accepts an array of type Telerik.Web.UI.FileExplorerItem - the selected items, and returns a string that contains all of the items paths:
    function combinePathsInAString(arrayOfSelectedItems)  
    {  
        var itemPaths = new Array();  
        for (var i = 0; i < arrayOfSelectedItems.length; i++)  
        {  
            // Pass all the selected paths ;  
            itemPaths.push(arrayOfSelectedItems[i].get_path());  
        }  
     
        // Return a string that contains the paths ;  
        return itemPaths.join("{}");  
  5. The __doPostBack() function in the sendItemsPathsToServer one triggers the Button1_Click event on the server :

    C# :
    protected void Button1_Click(object sender, EventArgs e)  
    {  
        string serializedItems = HiddenField1.Value;// Get the paths ;  
     
        // Extract the paths of the selected items ;  
        string[] selectedItemsPaths = serializedItems.Split(new string[] { "{}" }, StringSplitOptions.RemoveEmptyEntries);  
     
        // Use the paths :   
        Label1.Text = "Selected item's count : " + selectedItemsPaths.Length;  


    VB.NET :
    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As EventArgs) Handles Button1.Click  
         Dim serializedItems As String = HiddenField1.Value  
         ' Get the paths ;  
     
         ' Extract the paths of the selected items ;  
           Dim selectedItemsPaths As String() = serializedItems.Split(New String() {"{}"}, StringSplitOptions.RemoveEmptyEntries)  
     
         ' Use the paths :   
           Label1.Text = "Selected item's count : " & selectedItemsPaths.Length  
    End Sub 

 

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.