Listbox.OnClientSelectionChanging and RadWindow popup

6 posts, 0 answers
  1. Manas
    Manas avatar
    5 posts
    Member since:
    Jun 2012

    Posted 13 Jan 2012 Link to this post

    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
  2. Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 16 Jan 2012 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Manas
    Manas avatar
    5 posts
    Member since:
    Jun 2012

    Posted 18 Jan 2012 Link to this post

    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
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jan 2012 Link to this post

    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.
  6. Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 19 Jan 2012 Link to this post

    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
  7. Manas
    Manas avatar
    5 posts
    Member since:
    Jun 2012

    Posted 19 Jan 2012 Link to this post

    Thank you Bozhidar and Princy for your help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017