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

Listbox.OnClientSelectionChanging and RadWindow popup

5 Answers 77 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Manas
Top achievements
Rank 1
Manas asked on 13 Jan 2012, 10:33 PM
Hello there,
I have a listbox inside a RadToolBar as below I want to do something only if the user confirms to do it, otherwise I want to just cancel.

What I need (Is there an example for this?):
1. Ideally I would like to use a RadWindow.Confirm to get a response and process based on Confirm or Cancel (popup using client script only).
2. I don't want a postback to happen if the user selects cancel on the popup.

(with the below code the postback happens even if args.set_cancel(result) and result is the Cancel response from the window.confirm) Is it because one of the container of the listbox is causing the postback?

Can you please help?

        <telerik:RadToolBar runat="server" ID="RadToolBar1" Width="100%" Skin="Windows7">
            <Items>
                <telerik:RadToolBarDropDown ImageUrl="~/app_themes/default/images/Check.png">
                    <Buttons>
                        <telerik:RadToolBarButton>
                            <ItemTemplate>
                                <telerik:RadListBox runat="server" ID="lbDoSomething" Skin="Windows7" SelectionMode="Single"
                                    OnClientSelectedIndexChanging="ConfirmDo" OnSelectedIndexChanged="lbDoSomething_OnSelectedIndexChanged"
                                    AutoPostBack="True" />
                            </ItemTemplate>
                        </telerik:RadToolBarButton>
                    </Buttons>
                </telerik:RadToolBarDropDown>
            </Items>
        </telerik:RadToolBar>
 
 
 <script type="text/javascript">
....
        function ConfirmOverride(sender, args) {
            var msg = "Are you sure you want to do something?";
            var result = !window.confirm(msg);
            args.set_cancel(result);
 
        }
</script>

Thank you,
Manas

5 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 16 Jan 2012, 05:39 PM
Hello manas,

I've prepared a sample page showing the basic idea of how you can achieve the functionality you describe. In the sample there is a listbox and a button. When you click the button, a prompt dialog appears, asking you to type a name. If you click ok, a new item with that name is added to the listbox. If you click cancel, nothing happens. All this is entirely done on the client. 

To see more about the capabilities of RadWindow, you can refer to this online demo.
 
Kind regards,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Manas
Top achievements
Rank 1
answered on 18 Jan 2012, 07:07 PM
Thank you Bozhidar for your reply,
But can you please look at the code I put in my initial post there I want to show the confirmation message in the OnClientSelectedIndexChanging event handler and if the the user Cancels then do nothing (not even a postback) but if clicks OK then fo ahead with the OnSelectedIndexChanged server side event.

The radconfirm works fine with the button the way you have in the demo link referred but it does not work with the OnClientSelectedIndexChanging event.

The original code I posted does not work when when I changed to OnClientSelectedIndexChanging as below.

OnClientSelectedIndexChanging="radconfirm('Are you sure you want to do something?', confirmCallBackFn, 330, 100, null,'Confirm To Do something'); return false;"

Thanks,
Manas
0
Princy
Top achievements
Rank 2
answered on 19 Jan 2012, 07:06 AM
Hello,

Try the following code snippet.
JS:
<script type="text/javascript">
    var oConfirm = null;
  function OnClientSelectedIndexChanging(sender, args)
   {
        oConfirm = radconfirm("sure?", callbackFn);
   }
  function callbackFn(arg)
   {
      if (arg == true)
      {
            var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
            ajaxManager.ajaxRequestWithTarget('<%= RadListBox1.UniqueID %>', '');
      }
   }
</script>
C#:
protected void RadListBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
    //your code
  }

Thanks,
Princy.
0
Bozhidar
Telerik team
answered on 19 Jan 2012, 04:02 PM
Hi Manas,

I've attached another page, implementing the functionality you want to achieve.
 
Regards,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Manas
Top achievements
Rank 1
answered on 19 Jan 2012, 11:14 PM
Thank you Bozhidar and Princy for your help.
Tags
ListBox
Asked by
Manas
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Manas
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or