How to write javascript code on asp.net page such as (input box) to get value in a better manner .... or another controls message boxes (alert,confirm,...... (please if you can, give me an example? )
-
the best option is to put all the javascript functions in a separate .js file and while deloying the application minify the .js and use it.Aravind– Aravind2011-03-21 09:50:25 +00:00Commented Mar 21, 2011 at 9:50
-
@Aravind: minifying is sometimes just too overrated... at least you've got the browser cache :) if you'd really like to optimize, you'd better create one big file to minimize the requests!user57508– user575082011-03-21 15:14:26 +00:00Commented Mar 21, 2011 at 15:14
-
@Andreas one cannot generalise it and have to deal with it on a case to case basis.Aravind– Aravind2011-03-22 06:54:48 +00:00Commented Mar 22, 2011 at 6:54
-
@Aravind: neither you can... so throwing "MINIMIZE!" in is as stupid as my suggestion :)user57508– user575082011-03-22 08:47:55 +00:00Commented Mar 22, 2011 at 8:47
Add a comment
|
2 Answers
as you would on a "normal" html page :)
you can enhance your scripts - no, sometimes you MUST - with eg.
<%= this.inputBox.ClientID %>
i would recommend jQuery for such enhancements ... its feature rich, easy to learn, ...
you could do eg.
var $inputBox = $('#<%= this.inputBox.ClientID %>');
$inputBox.hide();
var oldValue = $inputBox.val();
$inputBox.val('now it has no value');
.. and many more!
there are many tutorials on the net... to give a very rough overview, try this
Comments
You can use the ClientID property. Example
<img src="images\cal.gif"
onclick="openCalendar(<% = txtDate.ClientID %>, 150, -150);return false;" />