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

Exposing Telerik Control client-side events in User Controls

4 Answers 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Albert Shenker asked on 21 Jul 2009, 03:12 PM
If one has a Rad Control in a User Control, is there a way of exposing the client-side evens of the RadControl, as client-side events of the user-control, and then handling these in the page that contains the user control. For instance, let's say I have a tree in a user control. Clicking on certain nodes performs one kind of client-side action (such as navigation), while clicking on others may do something else (like opening rad window dialogs) I can handle the rad tree click event in my container page (ie the page that holds the user control), however this is not a particularly good design, since then the container page must have knowledge of what the various tree nodes are and what should occur if they are clicked. A better design would be such that the tree node click is handled within the user control and then some sort of client-side event is raised within the user control which would be handled within the container page. So, in this scenario, the user control click handler decides which node does what and then raises one of two events... Navigate(sender, eventArgs) or OpenWindow(sender eventArgs). In both cases, the "sender" is the user control. In the first case, the eventArgs would have a property that specifies the url, and likely one that specifies the the target. In the second, the eventArgs would have a propety that specifies the url.

So my basic question is, how would one go about defining these client-side events within the user control that contains the Rad Control?

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Jul 2009, 07:58 AM
Hello Albert Shenker,

The easiest way would be to expose the client event properties of the control via its parent usercontrol:

public string OnClientNodeClicked
{
       get
       {
             return RadTreeView1.OnClientNodeClicked;
       }
       set
       {
             RadTreeView1.OnClientNodeClicked = value;
       }
}

If you want to implement custom client-side event you can check the ASP.NET Ajax client-side documentation.

Regards,
Atanas Korchev,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Albert Shenker
Top achievements
Rank 1
Veteran
answered on 23 Jul 2009, 04:54 AM
Thanks for the advice. The only issue with using the simple method you describe is that it still requires the container page to have knowledge of the user control's internal structure (ie the rad controls), because the handler will still have the same signature as the Rad Control client-side handler. I will look at your AJAX suggestion. Am I to understand that this isn't possible w/o AJAX?
0
Atanas Korchev
Telerik team
answered on 23 Jul 2009, 08:20 AM
Hello Albert Shenker,

As far as I know JavaScript does not support the notion of custom client-side events. It only supports DOM events - mouseover, click etc. That's why I recommended creating an ASP.NET Ajax component which supports custom events. The other possible solution is just to call some method when the event occurs and define that method in the parent control:

UserControl.ascx

function onClientNodeClicked(sender, args)
{
   //your event handling code

  if (typeof(NodeClickedHandler) != "undefined")
  {
        NodeClickedHandler(args.get_node())
  }
}

Page.aspx

function NodeClickedHandler(node)
{
}

However this approach will work for only one subscriber. If you need more you should check out the Ajax solution.

Regards,
Atanas Korchev,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Albert Shenker
Top achievements
Rank 1
Veteran
answered on 23 Jul 2009, 02:40 PM
Thanks for your suggestions. It would be nice if .NET supported custom client-side events in user controls as easily as they are supported in Server Controls (Obviously.. all of your server controls expose custom client-side events which are manifistations of mouse behaviors). I'm guessing there must be some way of doing this.. after all, aren't user controls and server controls both manifestations of the same Control Architecture? Maybe not.. Either way, it obviously wouldn't be as strightforward as exposing server-side events in the user control. Thanks again for your suggestions.
Tags
General Discussions
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Answers by
Atanas Korchev
Telerik team
Albert Shenker
Top achievements
Rank 1
Veteran
Share this question
or