Hi All,
Can anybody help me understand the difference between $find and $get methods in AJAX.NET framework.
I was surfing through the samples of AJAX Toolkit Samples.
Hi,
$get is used to get a reference to a DOM element. It is an alias for Sys.UI.DomElement.getElementById:
<span id="myLabel"></span>
var myLabel = $get('myLabel');
$find is an alias for Sys.Application.findComponent() and it's used to get a reference to a particular component, given its id.
Hi Garbin,
In the sample application for AJAX Toolkit we have an example for Accordion. I am extracting the following code snippet from file -
function toggleFade() { var behavior = $find('ctl00_ContentPlaceHolder1_MyAccordion_AccordionExtender'); if (behavior) { behavior.set_FadeTransitions(!behavior.get_FadeTransitions()); } } function changeAutoSize() { var behavior = $find('ctl00_ContentPlaceHolder1_MyAccordion_AccordionExtender'); var ctrl = $get('autosize'); if (behavior) { var size = 'None'; switch (ctrl.selectedIndex) { case 0 : behavior.get_element().style.height = 'auto'; size = AjaxControlToolkit.AutoSize.None; break; case 1 : behavior.get_element().style.height = '400px'; size = AjaxControlToolkit.AutoSize.Fill; break; case 2 : behavior.get_element().style.height = '400px'; size = AjaxControlToolkit.AutoSize.Limit; break; } behavior.set_AutoSize(size); } if (document.focus) { document.focus(); } }
Here I think 'ctl00_ContentPlaceHolder1_MyAccordion_AccordionExtender' is used as client Id for the MyAccorion control inside the Content Place Holder.
If I do the same without a content place holder and in different file I get a null reference.
I entered the server side Id for the $find method.
The answer is as always in C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\ScriptLibrary\Debug\MicrosoftAjax.js and thedocs (vaguely).
$get wraps document.getByElementId ++
$find is like FindControl (I think). It seems to walk up containers to find aSys.Component
Docs on $find (findComponent)
Docs on $get (getElementById)
Great, I could get the meaning of it
Thanks a LotChristopher and Gabriel
No comments:
Post a Comment