Registering javascript via the Page object, why?

G

Guest

This is not really a problem I'm having it's more of a general question

if you had an html page with embedded javascript script and you sent it to
the
browser if the script wasn't buggy, it would instantly work because
javascript is interpreted

I have created buttons on the fly (say in the editmode of a 1.x datagrid)
and I added the function as an attribute of that button, using
Attributes.add() etc...
but why does ASP.Net require you to Register Javascript, using some of the
Page's methods (Register, RegisteratStartup etc..), surely it's all text and
when it arrives at the browser, the browser will just tie it all together and
interpret the javascript on the fly, no?


thanks in advance and Regards,
CharlesA
 
B

Brock Allen

The Page APIs for registering javascript is to ensure only one copy of the
block of javascript in the page. Perhaps a custom control requires 100 lines
of javascript. Well what if the page uses 5 of these custom controls? If
they didn't 'coordinate' then you'd end up with a lot of bloat. Using the
Page APIs ensures this coordination.
 
G

Guest

Thanks Brock,
That's an interesting answer...
however why wouldn't you be able to just add that Javascript yourself at the
top of the page (in HTML design view), or as a .js file, and then it wouldn't
matter how many things referred to it, it would only be there once...

Regards,
CharlesA
 
M

Marina Levit [MVP]

The idea is that the custom control knows how to emit its own javascript.
So that the developer doesn't have to.

If you are using a 3rd party control, you have no idea what it does behind
the scenes and what javascript it emits - you just know that it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top