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

I can not access with ClientID

3 Answers 91 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
caglar_ozkul
Top achievements
Rank 1
caglar_ozkul asked on 01 Aug 2008, 05:33 PM
Hi,

I am creating all rad controls dynamically. More technical: I have encapsulated rad controls. But there is a problem in my following code, that is working on rad controls for asp.net with no problem.

MyContentToolbar.cs
  protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
          (this.Page.Master as IWebMaster).MasterPageControl.RegisterClientScript("PRO_SetMasterToolbar(" + this.InstanceClientID+ ");");             
        }

scripts.js
function PRO_SetMasterToolbar(toolbar)
{
    alert(toolbar); // alerts me null
    MasterToolbar = toolbar;
}

it alerts 'Object' in Rad for asp.net but alerts 'null' with rad for asp.net Ajax.

Regards
Caglar Ozkul



3 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 04 Aug 2008, 10:57 AM
Hi caglar_ozkul,

I am not quite sure about your exact implementation, but I think that the following information will be helpful:

  1. The controls in the RadControls for ASP.NET AJAX suite are built upon the MS AJAX framework and the framework itself creates its controls in the Sys.Application.add_init() method.

    Here is how the client events are fired in the page life cycle:

    window.onload -> Sys.Application.init -> Sys.Application.load

    You can see that the client object representation of MS AJAX controls are created just as the last code on the page in the Sys.Application.init event, which is raised after the window.onload event.

    That is why when you call your code  by registering the client script, the control will still not be created on the page and you will get an error. To avoid this problem, you can either execute your code with a small timeout, or use the Sys.Application.add_load method.

  2. The proper way to obtain a reference by using the ClientID of the control is through the built-in ajax method $find("<%=control.ClientID%>").

    I also suggest to examine our online documentation for RadControls for ASP.NET AJAX because there are some significant differences between them and RadControls for ASP.NET, based upon the MS AJAX Framework.



Regards,
Svetlina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
caglar_ozkul
Top achievements
Rank 1
answered on 12 Aug 2008, 11:44 AM
Hi Svetlina,

I am sorry but i don't know how to implemet your suggestion. I am not familiar with asp.NET Ajax framework.
"To avoid this problem, you can either execute your code with a small timeout, or use the Sys.Application.add_load method."

Is it possible to write a simple and sample code for your solution? if possible please do it for both strategies. (small time out and Sys.Application.add_load)

Kind Regards,
Caglar Ozkul
0
Georgi Tunev
Telerik team
answered on 15 Aug 2008, 12:39 PM
Hello caglar_ozkul,

Here is how to set the timeout (500ms) and the Sys.Application.add_load() event:

(this.Page.Master as IWebMaster).MasterPageControl.RegisterClientScript("window.setTimeout(function(){PRO_SetMasterToolbar(" + this.InstanceClientID+ ");}, 500)");   

(this.Page.Master as IWebMaster).MasterPageControl.RegisterClientScript("Sys.Application.add_load(function(){PRO_SetMasterToolbar(" + this.InstanceClientID+ ");})");   


I hope this helps. More information on the load handler in ASP.NET AJAX is available in the ASP.NET AJAX documentation.



Kind regards,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
caglar_ozkul
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
caglar_ozkul
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or