Aug 15, 2011, 6:15 PM
[CLOSED] Referencing page controls in JavaScript objects
What is the best way to get hold of a reference to a control object in case the ids are not set explicitly or known?
Let's say I have this JavaScript file referenced in an aspx:
I was thinking of using the AfterRender render event on the viewport and call: controller.ui = this;
Also, another question related to this. I am creating the ui using code behind. Sometimes I have to create JavaScript functions that need references to certain controls on the page (to disable or enable buttons for instance). What is the best way to get hold of the client ids of these objects or to set references to these objects?
Using the example above, let's say my controller class needs a reference to some buttons on the page, how would I inject those references into my controller JavaScript object?
C# code:
I posted another message related to ids, itemIds and refs: http://forums.ext.net/showthread.php...2425#post62425
After more thought, I find using refs a pain because one has to keep track of the level of depth of a control in order to make that control available at the top level panel. If you are using the Ext Designer, it alleviates this problem by handling the autoref property for you, but in the Ext.Net world I don't like it because you can invalidate the reference pretty quickly after moving the controls around.
So, I want to be in full control, I want to manually inject the references to control objects that I need to my own JavaScript objects, hence this post.
Thank you
Let's say I have this JavaScript file referenced in an aspx:
Ext.ns('MySpace');
MySpace.Controller = Ext.extend(Object, {
ui: <reference to an object in the page to be set later>
...
});
var controller = new MySpace.Controller();
Page:<body>
<ext:Viewport >
....
</ext:Viewport>
</body>
What events should I use to set the controller.ui member to the viewport object that gets created assuming that the ID of the viewport is not known (i.e. IDMode is not explicit and the ids can be random)?I was thinking of using the AfterRender render event on the viewport and call: controller.ui = this;
Also, another question related to this. I am creating the ui using code behind. Sometimes I have to create JavaScript functions that need references to certain controls on the page (to disable or enable buttons for instance). What is the best way to get hold of the client ids of these objects or to set references to these objects?
Using the example above, let's say my controller class needs a reference to some buttons on the page, how would I inject those references into my controller JavaScript object?
C# code:
private Toolbar CreateToolbar()
{
return new Ext.Net.Toolbar
{
Items =
{
new Ext.Net.Button
{
ID = "newButton"
Text = "New",
},
new Ext.Net.Button
{
ID = "editButton",
Text = "Edit",
},
},
};
}
In my JavaScript object I want controller.newButton to point to the newButton button and controller.editButton to point to the editButton. How would I achieve this?I posted another message related to ids, itemIds and refs: http://forums.ext.net/showthread.php...2425#post62425
After more thought, I find using refs a pain because one has to keep track of the level of depth of a control in order to make that control available at the top level panel. If you are using the Ext Designer, it alleviates this problem by handling the autoref property for you, but in the Ext.Net world I don't like it because you can invalidate the reference pretty quickly after moving the controls around.
So, I want to be in full control, I want to manually inject the references to control objects that I need to my own JavaScript objects, hence this post.
Thank you
Last edited by Daniil; Aug 17, 2011 at 9:44 AM.
Reason: [CLOSED]