I Don't Get $get

So I like the shorcut $get, but wouldn't it be nice if it worked on ASP controls? Unless I am missing something, I always have to do this:

var serverText= $get('<%= ServerTextBox.ClientID %>');

David


David McCarter
Microsoft MVP
dotNetTips.com
http://www.codeplex.com/dotNetTips
0
sddavidm
3/11/2008 7:20:21 PM
asp.net.ajax-ui 9760 articles. 0 followers. Follow

4 Replies
907 Views

Similar Articles

[PageSpeed] 9
Get it on Google Play
Get it on Apple App Store

Hi sddavidm,

$get is a shortcut to a function inside client-side AJAX core that work similar to document.getElementById. (http://www.w3schools.com/htmldom/met_doc_getelementbyid.asp)

It returns reference to a DOM element. DOM element is an object inside browser.

for example the following are markups for DOM elements:

<span id="span1"></span>

<div id="div1"></div>

so using function $get you can get a reference to that object:

var myDiv = $get("div1");

// do something with div

myDiv.innerHTML = "hello";

 

TextBox is a server control. When it is rendered and returned to a browser, the following control

<asp:TextBox runat="server" ID="tb1" Text="Hello"></asp:TextBox>

is rendered to a following markup:

<input type="text" value="Hello" id="c001_tb1" name="c001$tb1" />

and therefore you can get reference to it:

vat myTextBox = $get("c001_tb1");

BUT myTextBox is not a text inside that object - it is a reference to object tb1, It containc a lot of DOM attributes(aka properties). To get a text do the following:

//alerts text inside textbox:

alert(myTextBox.value);

//alerts name of a textbox:

alert(myTextBox.name);

//alerts top position if exists:

if(myTextBox.style.top) { alert(myTextBox.style.top); }

 

naming "gotcha" inside ASP.NET is that when you have server controls inside UserControls, that are in turn inside another user controls or page, the id for TextBox with ID="tb1" can look in final page like this:

c001_c004_c_009_tb1

And javascript knows nothing about tb1! It understands and can find only c001_c004_c_009_tb1 .

Its because tb1.ClientID on the server returns c001_c004_c_009_tb1  - the id that will be generated in the client browser.

 

Hope this helps.


My blog: http://blog.devarchive.net
My samples: http://devarchive.net
0
kirchi
3/11/2008 7:42:28 PM

 $get is nothing more than a shortcut to getElementById.  It will not magically resolve control IDs in multiple nested NamingContainer scenarios.




Please remember to "mark as answered" posts that have helped you.

-----
http://lsudotnet.blogspot.com
0
LSU
3/11/2008 7:47:36 PM

I know, but a programmer can dream can't he? Big Smile


David McCarter
Microsoft MVP
dotNetTips.com
http://www.codeplex.com/dotNetTips
0
sddavidm
3/11/2008 7:52:06 PM

what error you are facing

var serverText= $get('<%= ServerTextBox.ClientID %>');

is the right syntax, you will get object inside serverText that represent ServerTextBox


Chetan Sarode
Software Engineer,
Approva Systems Pvt Ltd,
Pune, India.
0
chetan
3/12/2008 3:36:47 AM
Reply:

Similar Artilces:

Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I?
Name: Ed Leech Email: ELCraftatzoominternetdotnet Product: Thunderbird Summary: Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I? Comments: I am getting frusted with all the emails coming in that I do not want, I am using the tools to get thme out but they keep coming. They just use different names or whatever. I have been thinking of just switching to something else but my business intrusts know this email and it is tooo confusing to change. Every time I go out of town on bu...

I can't get no cache, I can't get no cache. 'Cause I try and I try and I try and, I can't get no, I can't get no cache.
I have fiddled out for days tinkering with the setting in about:config trying to get FireFox 12 to use the disk cache. I have NOT found the trick. This One Trick Pony ain't doing it like it used to up until recently. Pray tell anyone, What information can I share that will point a knowledgeable person to aid me in getting FF to disk.cache? I have also tried restarting FF with add-ons disabled, (There were NOT too many to do this to, so it was quick and easy) Here is my stab at trying to convey the information that MIGHT govern matters Using about:cache Informatio...

Re: I can't get no cache, I can't get no cache. ' Cause I try and I try and I try and, I can't get no, I can't get no cache.
<div>please com e see me about htis<br /> <br /> ------- Original Message f= rom the Global Relay Archive -------<br /> From: Hp &lt;ferd@farkel.net&gt;= <br /> To: "support-firefox@lists.mozilla.org" &lt;support-firefox@lists.mo= zilla.org&gt;<br /> Sent: Sun, 27 May 2012 18:30:18 -0700<br /> Subject: I = can't get no cache, I can't get no cache. 'Cause I try and I try and I try = and, I can't get no, I can't get no cache.<br /> <br /></div> <pre class=3D"gr-maex-body-pre&qu...

When exiting a video playing with .wmv, you click the upper right "x" and you don't get back to the web homepage, you get stuck with a white, empty page. Explorer doesn't do that. It's an irritant f
Name: David Morgan Email: Dave_at_NewsCarsonCity.com Product: Firefox Summary: When exiting a video playing with .wmv, you click the upper right "x" and you don't get back to the web homepage, you get stuck with a white, empty page. Explorer doesn't do that. It's an irritant for those of us who want to use Mozilla, period. Comments: See summary. Browser Details: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ...

superreview granted: [Bug 264442] plugin finder can't find anything for windows media. : [Attachment 162212] Don't assume we don't have a plugin before getting a responce from the network.
Boris Zbarsky <bzbarsky@mit.edu> has granted Johnny Stenback <jst@mozilla.jstenback.com>'s request for superreview: Bug 264442: plugin finder can't find anything for windows media. https://bugzilla.mozilla.org/show_bug.cgi?id=264442 Attachment 162212: Don't assume we don't have a plugin before getting a responce from the network. https://bugzilla.mozilla.org/attachment.cgi?id=162212&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> r+sr=bzbarsky, I guess.. Is ther a reason mIsBrokenPlugin is write-only? ...

superreview requested: [Bug 264442] plugin finder can't find anything for windows media. : [Attachment 162212] Don't assume we don't have a plugin before getting a responce from the network.
Johnny Stenback <jst@mozilla.jstenback.com> has asked Boris Zbarsky <bzbarsky@mit.edu> for superreview: Bug 264442: plugin finder can't find anything for windows media. https://bugzilla.mozilla.org/show_bug.cgi?id=264442 Attachment 162212: Don't assume we don't have a plugin before getting a responce from the network. https://bugzilla.mozilla.org/attachment.cgi?id=162212&action=edit ...

Maybe this is bug in ajax,i couldn't understand, i have get the response,but the ajax script couldn't run!
the all script is :  function   onSucceeded(response)//debug here ,i could  get all the dataset result,                {                     if   (response.value   !=   null)//but  the debug point   go here , response.value is always equal null, i could not understand,if i quote this !                  &nb...

Can't get it to work. Can't get help.
Name: Tony Clarke Email: minionataondotat Product: Thunderbird Summary: Can't get it to work. Can't get help. Comments: Installed T'bird. Had to change defunct server that T'bird selected by default. Kept asking for passwords associated with previous email (Outlook Express ), when passwords entered then got error messages saying aon responded with 're-authentification failure'. Searched your knowledge base & help forums to no avail. Found them very user-unfriendly & ended up more confused than before. Would like to try T'bird, but I think ...

I don't get it...(VB.Net)
Throughout all my years of programming, I've usually just understood the flow of things, and why stuff works as it does. But coming to asp.net, I've ran into an example that boggles my mind, I know it works, but I don't understand exactly why, so I'm hoping someone here can explain it. My example comes from the ItemDataBound event of the Datagrid, though I don't really believe it matters, as it's more the concept, not the code Dim lblLink As WebControls.Label = CType(e.Item.Cells(0).FindControl("lblLink"), WebControls.Label) lblLink.Text = fNext.Name This code declares...

AJAX and refresh
Hey there,I'm puzzled about this situation and am wondering if someone can shed some light on it.I like to try a chat application and thought about using AJAX to pull the data from an XML file. I can get the page to refresh automatically at 3 second intervals using setinterval but the data itself is not refreshed. It still displays the data from the orginal request. If I open the page in another instance of IE that instance has the new data (entered after the first browser was opened) and then the orginal browser also updates. Clearly, however I want the orginal browser to show the new data ...

update fails, can't get out of it and now can't get my email
Name: martha Email: mjhartleyatchampmaildotcom Product: Thunderbird Summary: update fails, can't get out of it and now can't get my email Comments: The directions about bugging aren't helpful to me because I don't know what you're talking about. You offered an update, I tried it, now it is in an endless loop of trying to install, failing, and trying again. It is very frustrating because I can't even get into my old email files to get addresses, photos, etc. I have turned off my firewall and have rebooted the computer, per some of the suggestions in the...

Messages don't always get sent if computer's date isn't right
I've found that if my computer's date is off by more than some unknown amount, when I send a message it doesn't always really get sent. Yet I don't get an error indication, and the message appears in my Sent folder right along with the rest of my sent messages. Anyone know how much my computer's date can differ from true time before this problem appears? Some of my messages to newsgroups had their dates off by two years, but still got posted. A few minutes ago, I sent two eamils to myself, one with my computer set to September 28, 2009 (one month error)...

superreview requested: [Bug 252984] Cannot type in any of the fields
Aaron Leventhal <aaronleventhal@moonset.net> has asked Boris Zbarsky <bzbarsky@mit.edu> for superreview: Bug 252984: Cannot type in any of the fields - forms don't get focus on left-click http://bugzilla.mozilla.org/show_bug.cgi?id=252984 Attachment 154483: We actually don't need either nsIFrame::FocusableAncestor() or nsGenericHTMLElement::HandleDOMEvent() anymore http://bugzilla.mozilla.org/attachment.cgi?id=154483&action=edit ...

superreview granted: [Bug 252984] Cannot type in any of the fields
Boris Zbarsky <bzbarsky@mit.edu> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 252984: Cannot type in any of the fields - forms don't get focus on left-click http://bugzilla.mozilla.org/show_bug.cgi?id=252984 Attachment 154483: We actually don't need either nsIFrame::FocusableAncestor() or nsGenericHTMLElement::HandleDOMEvent() anymore http://bugzilla.mozilla.org/attachment.cgi?id=154483&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> If things still work right and someone who...

Web resources about - I Don't Get $get - asp.net.ajax-ui

Resources last updated: 12/8/2015 10:39:03 PM