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

Radbutton onClientClicked event

9 Answers 729 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
bharat veer
Top achievements
Rank 1
bharat veer asked on 13 May 2011, 08:06 PM
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.

 
 

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 May 2011, 12:47 PM
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.
0
bharat veer
Top achievements
Rank 1
answered on 17 May 2011, 03:03 PM
thanks brother.
0
bharat veer
Top achievements
Rank 1
answered on 17 May 2011, 03:06 PM
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.
0
Gimmik
Top achievements
Rank 1
answered on 17 May 2011, 05:49 PM
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
0
bharat veer
Top achievements
Rank 1
answered on 18 May 2011, 05:41 PM
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. 
                 
0
Shinu
Top achievements
Rank 2
answered on 19 May 2011, 05:01 AM
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.
0
bharat veer
Top achievements
Rank 1
answered on 19 May 2011, 07:25 PM
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;
           
        }
0
MTC
Top achievements
Rank 1
answered on 13 Feb 2013, 07:23 AM
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....
0
Slav
Telerik team
answered on 14 Feb 2013, 06:03 PM
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.
Tags
General Discussions
Asked by
bharat veer
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
bharat veer
Top achievements
Rank 1
Gimmik
Top achievements
Rank 1
MTC
Top achievements
Rank 1
Slav
Telerik team
Share this question
or