How do you combine asp.net and javascript?

  • Thread starter Thread starter WISEMANOFNARNIA
  • Start date Start date
W

WISEMANOFNARNIA

Suppose I want to put in custom javascript code in an asp.net page.
Do I just put in a script tag in the source view of the asp.net page
and then have 'onload' or some other attribute of a tag call it? Is
there a way to programatically insert javascript instead (from the
asp.net code-behind page?) What about controlling Silverlight and
Ajax? Do you have to write custom javascript code in the source of
the page?
Thanks,
-- Marv
 
WISEMANOFNARNIA said:
Suppose I want to put in custom javascript code in an asp.net page.
Do I just put in a script tag in the source view of the asp.net page
and then have 'onload' or some other attribute of a tag call it?

Yes. A script tag typically goes inside the head tag.
Is
there a way to programatically insert javascript instead (from the
asp.net code-behind page?)

Yes. The Page.ClientScript gives you access to the ClientScriptManager
object, that has methods like RegisterStartupScript and
RegisterClientScriptBlock.
What about controlling Silverlight and
Ajax? Do you have to write custom javascript code in the source of
the page?

You can use client script to interact with those, but for the most part
Silverlight is self contained and the AJAX controls are controlled by
it's properties and server code.
 
actually similar to flash, silverlight objects can be completly
controlled by javascript, and silverlight can raise javascript events.
in general this will have much faster page load times then using a .net
language which will require a vm to load, and a jit compile.

see the silverlight docs.

-- bruce (sqlwork.com)
 
Back
Top