[thelist] Using multiple script languages in .NET

Van Eeckhout Nick Nick.VanEeckhout at infohos.be
Thu Nov 27 03:36:13 CST 2003


pouncyisdead wrote:

	Question:
	How do you include a script function that differs from your App's
base
	language in ASP.NET?
	
	Why:
	I am trying to escape a string of text in a VB.NET page, then
unescape that
	string using client-side JS.
	Urlencode and Htmlencode don't seem to mesh well with client-side
unescapes.
	I would also like to find out more about Multi-language scripting in
.NET.

There is a function in the .net framework which enables you to write script
functions on your page. These are
- Page.RegisterStartupScript Method (string key, string script)
- Page.RegisterClientScriptBlock (string key, string script)

A key is given to the scriptblock to identify itself from the other script
blocks. Or if a script block is used in custom controls which are put
multiple times on a page, then the page is only going to render the
scriptblock once.
Within the script parameter you must add the script tags (<script
language='javascript'>alert('test');</script>)
The difference between the 2 functions is the place where your scriptblock
is inserted in the page.

This is the info from msdn : 

Page.RegisterClientScriptBlock
The client-side script is emitted just after the opening tag of the Page
object's <form runat= server> element.The script block is emitted as the
object that renders the output is defined, so you must include both tags of
the <script> element.
By identifying the script with a key, multiple server control instances can
request the script block without it being emitted to the output stream
twice.
Any script blocks with the same key parameter values are considered
duplicates.
Note   Remember to include HTML comment tags around your script so that it
will not be rendered if a requesting browser does not support scripts.

Page.RegisterStartupScript
Similar to the RegisterClientScriptBlock method, this method emits the
script just before the closing tag of the Page object's <form runat= server>
element. The script block is emitted as the object that renders the page is
defined, so you must include both tags of the <script> element.
By identifying the script with the key, multiple server control instances
can request the script block without it being emitted to the output stream
twice.
Any script blocks with the same key parameter values are considered
duplicates.
Note   Remember to include HTML comment tags around your script so that it
will not be rendered if a requesting browser does not support scripts.

Nick.






More information about the thelist mailing list