Please see my comment to the question explaining how an ASP.NET application works with JavaScript. There is no "using", calls between server-side and JavaScript — one is on the server side, another — on the client side.
Now, I'll explain why first code fragment is not working and the second does. This is just JavaScript and jQuery. First of all,
TextBox.Text
gets hard-coded in the instance of JavaScript text as some text value at the moment. It makes no sense for JavaScript, as this is some arbitrary blah-blah, whatever the value is. It could be
var value =
// or some
var value = blah-blah
Yes, just so, even without quotation marks. I hope you can see it now. Not only it is gibberish to JavaScript, it may not even compile. JavaScript exceptions are usually hidden from the user, so you can imagine the result.
In second case, jQuery is used with
id selector. Actually,
TextBox1.ClientID
generates some HTML
id
used in HTML, like in
<input type=text id="someId" ... />
In your second sample, with the actual
id
value like in my example above, the JavaScript will read:
var value = $('#someId').val();
This is a valid way to get a jQuery wrapper over HTML DOM object (
$('#someId')
; an element is found by its unique
id
value), and call its method
.val()
, to get the current value.
See also:
http://api.jquery.com/category/selectors/[
^],
http://api.jquery.com/id-selector/[
^].
If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[
^],
http://jquery.com/[
^],
http://learn.jquery.com/[
^],
http://learn.jquery.com/using-jquery-core/[
^],
http://learn.jquery.com/about-jquery/how-jquery-works/[
^] (start from here).
—SA