Client Side Custom Command - Running C# Code

4 posts, 1 answers
  1. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 01 Dec 2010 Link to this post

    Hi all,

    I have reviewed custom command help and I understand how to create a simple custom command -- e.g. something that would display an alert when the custom command is clicked.

    I would like to extend this to running non-javascript code. I have some C# which toggles a Microsoft Chart Control's legend and resizes the graph accordingly. I would like to have this be a custom command.

    Do I need to use regular AJAX for this? My basic thought process is this:

    - Assign a new Command to my Dock named ToggleLegend:
    <Commands>
      <telerik:DockCommand
        Text="Toggle Legend"
        OnClientCommand="ToggleLegend" />
    </Commands>

    - Create the corresponding JavaScript:
    <script type="text/javascript">
            function ToggleLegend(dock, args) {
    MyAjaxedClassHere.ToggleLegend(ToggleLegend_CallBack);
    }
     </script>

    - Over in my C# Class:
    [Ajax.AjaxMethod()]
    private void ToggleLegend()
    {
        //Code Here
    }

    I haven't tested this and I suspect it is an incorrect way of achieving my desired goal. Could someone confirm that this is the correct way of achieving this while using RAD Controls, or is there a nicer way?

    Regards,

    Sean Anderson
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 03 Dec 2010 Link to this post

    Hello Sean,

    If you want to run custom server code on a button click, I would suggest using the Command server-side event. The following demo shows an example of how the event is used: http://demos.telerik.com/aspnet-ajax/dock/examples/commands/defaultcs.aspx.

    Best wishes,
    Pero
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 03 Dec 2010 Link to this post

    Hey,

    Thanks for this. This will work, but is there any way to get a hook on what is being stored inside of a Dock?

    E.g.: I have graph1 inside of dock1 and graph2 inside of dock2. User clicks dock2's toggleLegend custom command. Currently, I just have hard-coded in that graph2 is inside of dock2, but this is not very dynamic. I flicked through the sender's properties, but didn't see anything immediately.

    Regards,

    Sean
  5. Answer
    Pero
    Admin
    Pero avatar
    1156 posts

    Posted 08 Dec 2010 Link to this post

    Hi Sean,

    RadDock's Tag property can be used for this purpose. For example if a user control is loaded within the dock, the path to the control can be set to the Tag property.
    This property cannot be accessed on the client, but with a simple code this can made possible. For your convenience I've created a sample project that demonstrates this.

    Regards,
    Pero
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top