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

Execute treatment for each selected item (one item by one)

2 Answers 34 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Claude IMBERT
Top achievements
Rank 1
Claude IMBERT asked on 14 Nov 2008, 04:11 PM

Hello,
 i'm trying to execute a treatment for all selected line in a listview control (one by one)

this works fine but is it the right way to do that with telerik ? (OnResponseEnd + ajaxRequest)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Untitled Page</title> 
 
    <script type="text/javascript">  
    //for the number of the next listitem to run  
    var LiListNumber=0 
    ////////////////////////////////////////////  
    function OnRequestStart(ajaxPanel, eventArgs){  
      /**nothing to do**/  
     }  
    function OnResponseEnd(ajaxPanel, eventArgs){                  
      if(LiListNumber<document.getElementById('Listbox1').length)  
      { TraitementList(document.getElementById('Listbox1'));}                
         }  
    </script> 
 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="ScriptManager1" runat="server" EnableTheming="True">  
    </telerik:RadScriptManager> 
    <div> 
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
 
            <script type="text/javascript">  
                function TraitementList(list)  
                {                                    
                 var ajaxMng = $find("<%= RadAjaxManager1.ClientID %>");                                          
                 for (var i=LiListNumber; i < list.options.length ; i++)                   
                    //i'm searching for the next selected item                      
                    {if(list.options[i].selected){  
                        var svgtext=list.options[i].text   
                        list.options[i].text = "====>"+svgtext     
                        //for the next call                          
                        //i'm calling the treatment                                                                       
                        ajaxMng.ajaxRequest(svgtext);                                                
                        break  
                        // exit                        
                     }                       
                   }     
                   if(i<list.options.length)  
                        {LiListNumber=i+1}  
                   else  
                        {LiListNumber=0}  
                     
                   return false;                    
                }  
            </script> 
 
        </telerik:RadCodeBlock> 
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" OnAjaxRequest="RadAjaxManager1_AjaxRequest" 
            DefaultLoadingPanelID="RadAjaxLoadingPanel1">  
            <ClientEvents OnRequestStart="OnRequestStart" OnResponseEnd="OnResponseEnd" /> 
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadCodeBlock1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="Label1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="Button3">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="Label1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        <br /> 
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
        <br /> 
        <asp:ListBox ID="ListBox1" runat="server" Height="102px" SelectionMode="Multiple" 
            Width="504px">  
            <asp:ListItem Value="1">First</asp:ListItem> 
            <asp:ListItem Value="2">Second</asp:ListItem> 
            <asp:ListItem Value="3">Third</asp:ListItem> 
            <asp:ListItem Value="4">Fourth</asp:ListItem> 
            <asp:ListItem Value="5">Fith</asp:ListItem> 
        </asp:ListBox> 
        <asp:Button runat="server" ID="Button3" Text="Button3" OnClientClick="return TraitementList(ListBox1);" /> 
        <br /> 
    </div> 
    </form> 
</body> 
</html> 
 

 

using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Linq;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.HtmlControls;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Xml.Linq;  
 
 
    public partial class Default7:System.Web.UI.Page {  
      
        protected void Page_Load(object sender, EventArgs e)  
        {  
 
        }  
        
         
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) {  
            Label1.Text="End of"+e.Argument;  
            System.Threading.Thread.Sleep(3000);  
        }   
}  
 
 

thanks for all your work.

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 17 Nov 2008, 12:00 PM
Hi Claude,

The implementation you are using seems to be correct and should work as expected. However please note that adding RadCodeBlock into the RadAjaxManager settings is not supported scenario. What should be the functionality you required by adding this settihng?

All the best,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Claude IMBERT
Top achievements
Rank 1
answered on 17 Nov 2008, 03:21 PM
Hi Maria,

in a listbox, the user could select multiple item (filename).
For each filename selected, i make a treatment. Obviously , i could put a progress bar for the sum of all treatment (3 treatments if the user select 3 files) but each treatment could be long (2->5 seconds) and I would prefer an indicator that indicate wich file is being treated.

thanks for your help

Tags
Ajax
Asked by
Claude IMBERT
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Claude IMBERT
Top achievements
Rank 1
Share this question
or