PDA

View Full Version : [CLOSED] Ext.onReady and Resource Manager DocumentReady



Kev
Apr 15, 2013, 9:11 AM
Hi,
I'm a bit confused at the following after doing a little housekeeping and looking at which technique to use with Ext.onReady.

If I declare inline Ext.onReady in the head of a page, I cannot access a control, whereas if I used the Resource Manager DocumentReady listener, it works fine. A little confusing seeing as they both do the same thing surely?

Out of curiosity. If you cut and paste the inline script I've written below and put it after the closing HTML tag, it finds the control using both techniques. Confusing! An explanation would be very much appreciated. See code below:



<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
Ext.onReady(function () {

var textbox = Ext.getCmp('txtSample');
//control is undefined - uncomment below to show control is not found
//console.log('Inline onready found: ' + textbox.id);
});

function ExtReady() {

var textbox = Ext.getCmp('txtSample');
console.log('Resource Manager onready call found: ' + textbox.id);
}
</script>

</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server">
<Listeners>
<DocumentReady Handler="ExtReady()" />
</Listeners>
</ext:ResourceManager>
<form id="form1" runat="server">
<ext:TextField runat="server" ID="txtSample" ClientIDMode="Static" Text="Hello world" Width="300"></ext:TextField>
</form>
</body>
</html>

Daniil
Apr 15, 2013, 11:50 AM
Hi @Kev,

Yes, a DocumentReady listener produces an Ext.onReady handler, but put it after an Ext.NET initialization script.

Actually, an Ext.NET initialization script is an Ext.onReady listener as well, which creates Ext.NET components which you defined in markup/code behind.

So, you can get access to those components only after executing of an Ext.NET initialization script.

If you explicitly put your custom Ext.onReady handler after an Ext.NET initialization script, it will behave the same way.

Example

<ext:ResourcePlaceHolder runat="server" Mode="Script" />

<script>
Ext.onReady(yourHandler);
</script>

You might need to investigate Page Sources to understand better what I am talking about.

Kev
Apr 15, 2013, 12:56 PM
Hi @Kev,

Yes, a DocumentReady listener produces an Ext.onReady handler, but put it after an Ext.NET initialization script.

Actually, an Ext.NET initialization script is an Ext.onReady listener as well, which creates Ext.NET components which you defined in markup/code behind.

So, you can get access to those components only after executing of an Ext.NET initialization script.

If you explicitly put your custom Ext.onReady handler after an Ext.NET initialization script, it will behave the same way.

Example

<ext:ResourcePlaceHolder runat="server" Mode="Script" />

<script>
Ext.onReady(yourHandler);
</script>

You might need to investigate Page Sources to understand better what I am talking about.

Thanks Daniil. Yes, I've examined the source code after what you suggested and can see what you mean. I can see that the init function, the creation of the controls and self executing function which contains my ExtReady function are now above my Ext.onReady declaration. Makes complete sense. Thank you for your explanation.

equiman
Dec 26, 2013, 7:12 PM
Two years using Ext... and Finally knows the true about that.

Thanks @Daniil and @Kev

Daniil
Dec 27, 2013, 3:54 AM
Hi @equiman,

Nice that it helped you:)