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

Client Side Custom Command - Running C# Code

3 Answers 83 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 02 Dec 2010, 01:27 AM
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

3 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 03 Dec 2010, 02:01 PM
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.
0
Sean
Top achievements
Rank 2
answered on 03 Dec 2010, 07:26 PM
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
0
Accepted
Pero
Telerik team
answered on 08 Dec 2010, 09:55 AM
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.
Tags
Dock
Asked by
Sean
Top achievements
Rank 2
Answers by
Pero
Telerik team
Sean
Top achievements
Rank 2
Share this question
or