Friday 26 June 2009

Different Ways of Selecting a Control in ASP.NET using JavaScript

Accessing an HTML control:

var myHtmlControl = document.getElementById('htmlTextBox');
var myHtmlControl = $('#htmlTextBox');

Accessing an ASP.NET Server control:

var myServerControl = document.getElementById('serverTextBox');
var myServerControl = document.getElementById("< % = serverTextBox.ClientID % > ");
var myServerControl = $('# < % = serverTextBox.ClientID % > '); // JQuery
var myServerControl = < % = serverTextBox.ClientID % >;
var myServerControl = eval("serverTextBox.ClientID");
var myServerControl = $get("serverTextBox.ClientID"); // ASP.NET AJAX Library
...

No comments: