Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Toolbar > Client side OnClick Event don't working with Toolbar button!!!
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Client side OnClick Event don't working with Toolbar button!!!

Feed from this thread
  • Akhtar avatar

    Posted on Nov 17, 2008 (permalink)

    Hi,
    I am using Rad Toolbar in my ASP.NET Application. I want to catch client side OnClick event of a Toolbar button,
    I am using following code

    RadToolbarButton btnRemove = new RadToolbarButton();
    btnRemove.Attributes.Add("onClick", "return confirm('Are you sure you want to remove?')");

    Its working fine and firing the onClick Event, But issue is that it doesn't care the return value, It always postback the page regardless what onClick method returns.

    Can anyone please help me out.

    Thanks in Advance.

    Muhammad Akhtar Shiekh

  • Posted on Mar 9, 2009 (permalink)

    Hi Akhtar,

    Here is one alternate method to show the  confirm message on clicking a RadToolBarButton:
    aspx:

    <telerik:RadToolBar ID="RadToolBar1" Width="1000px" runat="server" OnButtonClick="RadToolBar1_ButtonClick"
            <Items> 
            <telerik:RadToolBarButton  Text="Remove" CommandName="Remove" ></telerik:RadToolBarButton> 
            </Items> 
    </telerik:RadToolBar> 

    js:
    <script type="text/javascript"
        function clientbuttonclick(sender, args) 
        { 
           
          var button = args.get_item(); 
                if (button.get_commandName() == "Remove") 
                { 
                    args.set_cancel(!confirm('Are you sure you want to remove?')); 
                } 
        }     
     </script> 

    cs:
     protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e) 
        { 
            
        } 

    Thanks
    shinu.

  • Mani PC avatar

    Posted on Aug 10, 2009 (permalink)

    I am creating toolbar buttons on the page load.
    I want to do on the server side - code behind page:
    Here is my code:

     

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  

    If Not Page.IsPostBack Then  

     

     

     

    'create xml button list  

     

    With

     

    SessionWrapper.ToolBarButtons

     

    .Clear()

    .Add(ToolBarButtons.ButtonText.Retrieve,

    True)

     

    .Add(ToolBarButtons.ButtonText.Delete,

    True)

     

    .Add(ToolBarButtons.ButtonText.Save,

    True)

     

    .Add(ToolBarButtons.ButtonText.Export,

    True)

     

    .Add(ToolBarButtons.ButtonText.Print)

    .Build()

     

    End With

     

     

     

     

     

     

     

     

     

     

     

     

     

    'build tool bar  

     

    rtbReasonCode.LoadXml(SessionWrapper.ToolBarButtons.XMLButtonList) 

    End If

     

     

     

    Dim btnbutton1 As New Telerik.Web.UI.RadToolBarButton

    btnbutton1 =

    CType(rtbReasonCode.FindControl("i2"), Telerik.Web.UI.RadToolBarButton)

     

    btnbutton1.Attributes.Add(

    "OnClick", "return confirm('Confirm Delete?');"

     

     

     

     

    Dim btnbutton As New Telerik.Web.UI.RadToolBarButton

     

    btnbutton =

    CType(rtbReasonCode.FindControl("i4"), Telerik.Web.UI.RadToolBarButton)

     

    btnbutton.Attributes.Add(

    "OnClick", "return confirm('Confirm Save?');"

     

     

     

     

    'display custom control  

     

    Master.DisplayCustomControl(_CustomCtrl) 

    End Sub

    -------------------------------------------------------

     

    Private

     

    Sub rtbReasonCode_ButtonClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadToolBarEventArgs) Handles rtbReasonCode.ButtonClick  

     

     

     

    Try 

     

     

    Dim [text] As String = e.Item().Text  

     

    Dim typeIS As Type = e.Item.GetType() 

     

     

     

     

    If TypeOf e.Item Is RadToolBarButton Then 

     

     

    'Call to business layer to save header  

     

    If [text] = "Retrieve" Then 

     

     

    GetReasonInfo() 

     

    ElseIf [text] = "Delete" Then 

     

     

    DeleteReason() 

     

    ElseIf [text] = "Save" Then 

     

     

    SaveReasonInfo() 

     

    ElseIf [text] = "Export" Then  

    'TODO: implement export to excel 

     

     

    'CallExport() 

     

    ElseIf [text] = "Print" Then 

    'TODO: implement print 

     

     

    'CallPrint()  

     

    End If 

     

     

    End If 

     

     

     

     

    Catch ex As Exception  

    Log.Fatal(ex)

     

     

    'Throw  

    End Try  

    End Sub

    --------------------------------------------

    the postback happens on hitting both OK/CANCEL, how to handle this scenario?

     

     

     

  • Stacy avatar

    Posted on Apr 19, 2011 (permalink)

    Where does the javascript get executed in this case?

  • Kate Kate admin's avatar

    Posted on Apr 21, 2011 (permalink)

    Hi Stacy,

    Please take a look at this forum post.

    All the best,
    Kate
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Toolbar > Client side OnClick Event don't working with Toolbar button!!!