How to reference Telerik Client-Side control from custom Ajax Client-Side Control?

3 posts, 0 answers
  1. Skywalker
    Skywalker avatar
    67 posts
    Member since:
    Sep 2007

    Posted 31 Jul 2008 Link to this post

    Here is the situation: I wrote a Clientside control, that is composed of the RadTabStrip control, using the ASP.NET AJAX client libraries .

    I want my client-side control class to be able to handle events from the client-side TabStrip, like tabSelected.

    This is easily done like this:

    1 initialize: function()   
    2     {  
    3         MyControls.WizardTabStrip.callBaseMethod(this'initialize');  
    4           
    5         // Add custom initialization here  
    6         this._tabSelectedHandler                =   Function.createDelegate(thisthis._onTabSelected);  
    7           
    8         // The next line fails, because the client-side TabStrip object is not yet created: it will be created after our custom client-side control is created  
    9         this.get_tabStrip().add_tabSelected(this._tabSelectedHandler);  
    10     },  
    11  
    12 get_tabStripID: function()  
    13     {  
    14         return this._tabStripID;  
    15     },  
    16     set_tabStripID: function(value)  
    17     {  
    18         this._tabStripID = value;  
    19     },  
    20  
    21 get_tabStrip: function()  
    22     {  
    23         return $find(this.get_tabStripID());  
    24     },  
    25  
    26 _onTabSelected : function(sender, args)  
    27     {  
    28         // Do things when a tab is selected  
    29     } 

    However, line 9 fails, because the RadTabStrip is a child control of my Composite Control (which implements IScriptControl) and my custom clientside control is $created before the RadTabStrip client-side control is $created.

    The easiest solution would be to attach the tabSelected eventhandler for the custom client control instance in the pageLoad() event, but isn't there are smarter way?


    Thanks.
  2. Skywalker
    Skywalker avatar
    67 posts
    Member since:
    Sep 2007

    Posted 31 Jul 2008 Link to this post

    I included the generated javascript after the page is rendered to the browser to illustrate my issue:

    1 Sys.Application.add_init(function() {  
    2     $create(MyControls.WizardTabStrip, {"nextStepButtonID":"ctl00_ctl00_ctl00_WorkspaceArea_WorkspaceArea_WorkspaceArea_courseEditor_ctl04_nextStep","previousStepButtonID":"ctl00_ctl00_ctl00_WorkspaceArea_WorkspaceArea_WorkspaceArea_courseEditor_ctl04_previousStep","tabStripID":"ctl00_ctl00_ctl00_WorkspaceArea_WorkspaceArea_WorkspaceArea_courseEditor_wizardTabStrip","validationGroup":null}, nullnull, $get("ctl00_ctl00_ctl00_WorkspaceArea_WorkspaceArea_WorkspaceArea_courseEditor_wizardTabStripContainer"));  
    3 });  
    4 Sys.Application.add_init(function() {  
    5     $create(Telerik.Web.UI.RadTabStrip, {"_selectedIndex":0,"_skin":"Telerik","attributes":{},"clientStateFieldID":"ctl00_ctl00_ctl00_WorkspaceArea_WorkspaceArea_WorkspaceArea_courseEditor_wizardTabStrip_ClientState","multiPageID":"ctl00_ctl00_ctl00_WorkspaceArea_WorkspaceArea_WorkspaceArea_courseEditor_wizardMultiPage","selectedIndexes":["0"],"tabData":[{},{},{}],"validationGroup":"Course"}, nullnull, $get("ctl00_ctl00_ctl00_WorkspaceArea_WorkspaceArea_WorkspaceArea_courseEditor_wizardTabStrip"));  
    6 }); 

    You see, the "MyControls.WizardTabStrip" client-side control references the "Telerik.Web.UI.RadTabStrip" client-side control in the initialize method.
    Of course, that control does not yet exist, as the $create(Telerik.Web.UI.RadTabStrip) method is invoked secondly.

    Is there a smart way to change this order?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Aug 2008 Link to this post

    Hi Sipke,

    Perhaps you can use the AddComponentProperty method.

    Kind regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top