Radbutton onClientClicked event

10 posts, 0 answers
  1. bharat veer
    bharat veer avatar
    41 posts
    Member since:
    Dec 2009

    Posted 13 May 2011 Link to this post

    Hi,
    Good evening all,
    Below  the java script method is defined that is called on the rad button onClientClicked event.

      function rbReturnToData_Clicked(button, args)
       {                        
       if (window.confirm("You have pending filter changes.  Apply them?"))
              {                        
               button.set_autoPostBack(true);
               }               
         else
            {                             
            button.set_autoPostBack(true);                       
            }
        }

    my question is that is there any way to send extra parameter to the server
    with 
    button.set_autoPostBack(true);. and how it cab be accessed at server side.

     
     

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 May 2011 Link to this post

    Hello Bharat,

    One approach is to set the CommandArgument from client side and access it from server side. Here is the sample code.
    aspx:
    <telerik:RadButton ID="RadBtn1" runat="server"  OnClientClicked="OnClientClicked" AutoPostBack="false" onclick="RadBtn1_Click">
    </telerik:RadButton>

    Javascript:
    function OnClientClicked(button, args)
         {
            button.set_autoPostBack(true);
            button.set_commandArgument("NewValue")//passing the extra parameter as command argument.
         }

    C#:
    protected void RadBtn1_Click(object sender, EventArgs e)
        {
            Response.Write("Fired");
            Response.Write(RadBtn1.CommandArgument);
        }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. bharat veer
    bharat veer avatar
    41 posts
    Member since:
    Dec 2009

    Posted 17 May 2011 Link to this post

    thanks brother.
  5. bharat veer
    bharat veer avatar
    41 posts
    Member since:
    Dec 2009

    Posted 17 May 2011 Link to this post

    i want one more help,
    how below written code can be written with Rad Confirm message box.
    right now i have used Window.Confirm box.
     function rbReturnToData_Clicked(button, args) {
                debugger;                 
                var pending = document.getElementById("<%= lblChangesPending.ClientID %>");
                var lblTitleFilter = document.getElementById("<%= lblTitleFilter.ClientID %>");
                var rfGridFilter = document.getElementById("<%= rfGridFilter.ClientID %>");

                if (pending != null) {
                  if (pending.innerHTML != "") {
                      if (window.confirm("You have pending filter changes.  Apply them?")) {
                         
                          button.set_commandName('Apply')                                                            
                          button.set_autoPostBack(true);
                        }
                        else {                       
                            button.set_commandName('Cancel')    
                            button.set_autoPostBack(true);                        
                        }
                    }
                    else
                        CollapseToolsPane();
                }
                else {
                    CollapseToolsPane();
                }            
            }

    it will be so grattitude to help me out in this case.
    thanks brother.
  6. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 17 May 2011 Link to this post

    Hi bharat,

    That looks fairly simple. Here's the document I used:
    http://www.telerik.com/help/aspnet-ajax/window-dialogs-confirm.html

     I'll try updating your JavaScript, let me know if it works.
    function rbReturnToData_Confim(arg) {
     
        var button = document.getElementById("<%= RadBtn1.ClientID %>");
     
        if (arg) {
     
            button.set_commandName('Apply')
            button.set_autoPostBack(true);
        }
        else {
            button.set_commandName('Cancel')
            button.set_autoPostBack(true);
        }
    }
     
    function rbReturnToData_Clicked(button, args) {
        debugger;
        var pending = document.getElementById("<%= lblChangesPending.ClientID %>");
        var lblTitleFilter = document.getElementById("<%= lblTitleFilter.ClientID %>");
        var rfGridFilter = document.getElementById("<%= rfGridFilter.ClientID %>");
     
        if (pending != null && pending.innerHTML != "") {
     
            radconfirm("You have pending filter changes.  Apply them?", rbReturnToData_Confim);
        }
     
        else {
            CollapseToolsPane();
        }
    }

    Just a word of warning - I haven't tried running this code, but it should give you the basic idea.

    Hope this helps!
    -Gimmik
  7. bharat veer
    bharat veer avatar
    41 posts
    Member since:
    Dec 2009

    Posted 18 May 2011 Link to this post

    First of all thanks very much Brother.
    It works with some modifications in code.
    But main problem is every time when Rad Button is clicked server side code is fired.
    My rad button is like this
     <telerik:RadButton ID="rbReturnToData" runat="server"  Text="Return To Data"                  
                        OnClientClicked="rbReturnToData_Clicked"  OnClick="rbReturnToData_Click"    /> 

     
         var Button=null;
            function rbReturnToData_Confim(arg) {        
                var button = document.getElementById("<%= rbReturnToData.ClientID %>");
              // with "button" object below property "set_commandName" not works
              // then i made a global variable Button=null above this method as u can see
             // and this Button object refrenced with the Radbutton object in below mentioned method

                if (arg)
               {
                    Button.set_commandName('Apply')             
                    Button.click();               
                }
                else
                  {
                    Button.set_commandName('Cancel')               
                    Button.click();                
                }
            }     


    //below mentioned method
     function rbReturnToData_Clicked(button, args) {                      
                var pending = document.getElementById("<%= lblChangesPending.ClientID %>");
             //Here below code of line Button variable that is declared above method rbReturnToData_Confim Top Globally
            // is  set with the reference of the Radbutton control that is at top is defined with telerik tab
            // with this reference "set_commandName" works in above method
                Button = button;
                if (pending != null)
                 {
                    if (pending.innerHTML != "")
                       {
                           radconfirm("You have pending filter changes.  Apply them?", rbReturnToData_Confim);
                           //return false;             
                       }
                    
                }
                else
                {
                    CollapseToolsPane();
                }            
            }    

    Main problem is that every time when i clicked at the rad button server side event is fired.
    I want this event get fired only when user click  "Ok"  and "Cancel" in confirmation box. 
                     
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 May 2011 Link to this post

    Hello Bharat,

    You can check out the following code library which explains the how to allow the radconfirm window to simulate the blocking of the execution thread while waiting for user's confirmation.
    Block the execution thread with radconfirm.

    And the correct method of accessing the RadControl from client side is by $find('<%=rbReturnToData.ClientID%>') not
    document.getElementById("<%= rbReturnToData.ClientID %>");

    Hope it helps.

    Thanks,
    Shinu.
  9. bharat veer
    bharat veer avatar
    41 posts
    Member since:
    Dec 2009

    Posted 19 May 2011 Link to this post

    actually with your help
    i almost done my work.
    also i gone though your suggested link, but my requirement is little bit different.

        function rbReturnToData_Confim(arg)
             {               
               var button= $find('<%=rbReturnToData.ClientID%>')
               if (arg)
                {
                    button.set_commandName('Apply')
                    button.set_autoPostBack(true);
                    button.click();
                  //Server side event is fired here  (at most below server side code  you can see)                
                }
                else
                {
                    button.set_commandName('Cancel')
                    button.set_autoPostBack(true);
                    button.click();
                //Server side event is fired here   (at most below server side code  you can see)                           
                }           
            }    
            function rbReturnToData_Clicked(button, args) {            
                var pending = document.getElementById("<%= lblChangesPending.ClientID %>");
                Button = button;
                if (pending != null)
                 {
                    if (pending.innerHTML != "")
                       {
                        radconfirm("You have pending filter changes.  Apply them?", rbReturnToData_Confim);                                 
                       }               
                 }
                else
                {
                    CollapseToolsPane();
                }           
             }
    my actual problem is that when i click  "OK" or "Cancel" from confirmation box
    and it fires server side code but when return to page confirmation box is not closed.
    it remains open. I just want it get closed after firing server side code.


    server side code is here that is fired
     protected void rbReturnToData_Click(object sender, EventArgs e)
            {
                if (((RadButton)sender).CommandName == "Apply")
                {
                    rfGridFilter.FireApplyCommand();
                    rgModuleGrid.Rebind();

                    lblRowCount.Text = Res.Get<iTrackerResources>().FilterRowCountMessage +
                    "&nbsp;&nbsp;&nbsp;" + rgModuleGrid.MasterTableView.VirtualItemCount.ToString().Trim();
                    rbRevertToLast.Enabled = false;
                    lblChangesPending.Visible = false;
                    Session[hfUnique.Value.ToString() + "_Filter"] = rfGridFilter.SaveSettings();
                    checkApply = true;
                }
                else if (((RadButton)sender).CommandName == "Cancel")
                {
                    rfGridFilter.RootGroup.Expressions.Clear();
                    lblChangesPending.Visible = false;
                    lblTitleFilter.Text = string.Empty;
                    rfGridFilter.FireApplyCommand();
                    rgModuleGrid.Rebind();
                    lblRowCount.Text = Res.Get<iTrackerResources>().FilterRowCountMessage +
                    "&nbsp;&nbsp;&nbsp;" + rgModuleGrid.MasterTableView.VirtualItemCount.ToString().Trim();

                }
                ((RadButton)sender).CommandName = string.Empty;
                ((RadButton)sender).AutoPostBack = false;
               
            }
  10. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 13 Feb 2013 Link to this post

    Hi
    I have a simple requirement to create a record in Data Base. for this i have some fields on my webpage after filling that fields user can create a record.
    for this i am using RadAjaxPanel,RadScriptBlock,Rad Button,RadAjaxManager and RadAjaxLoadingPanel.
    the flow for creating r record would be:
    -> On button click first i want to call a JavaScript for validation( not asp validation) it returns true for successful validation else false..
    ->if it is true loading panel should appear on the screen and server side code should run.
    -> if it is false then loading panel should not appear JavaScript error message should display..

    Please help....
  11. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 14 Feb 2013 Link to this post

    Hi Shweta,

    Please check this forum thread for additional information on the case. I noticed that you have already reported the same problem there. I would suggest using a single thread for this purpose as the information on the described scenario will be much easier to track if it is gathered in one place. Let us continue our discussion in the linked thread.

    Kind regards,
    Slav
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017