ASP.NET Client-Side Script FAQ
(Various contributors)
We have a fair amount of forum questions here on Eggheadcafe.com that center around the area of client-side scripting with ASP.NET, and we thought it would be about time to start an FAQ article on the subject. We'll include all the basics of client - side script with ASP.NET here, drawn from reliable sources (and simplified!) along with our own "discoveries". We'll also insert links to other resources where appropriate. This is a community "work in progress" which we will add to on a regular basis, so please feel free to take advantage of the little "article discussion forum" at the bottom to post or answer questions and make requests, as well as to make repeat visits to see "what's new" on the page! All contributions are encouraged, either via the discussion at the bottom of this page, or via email.
Basic Concepts:
There are two important component parts of any ASP.NET "page" - the ".ASPX" portion, which is really a modified HTML page that holds the asp:control server tags, client script, and HTML elements, and the "Codebehind" or server-side portion of the page, which can be either inside tags in the ASPX portion (or with a src=
attribute), or it could be generated from server side processing, as we will soon see.
ASP.NET Intrinsic Client-Script Related Methods
ASP.NET has several built in methods of the Page class that were specifically designed to help with client-side scripting. Let's look at these first:
RegisterClientScriptBlock and RegisterStartupScript methods of the Page class.
These methods identify your script with a string key, so that multiple server control instances can request the script block without it being inserted in the output more than once. The IsClientScriptBlockRegistered and IsStartupScriptRegistered methods of the Page object are used to determine if the script has already been registered. Differences between RegisterClientScriptBlock and RegisterStartupScript The RegisterClientScriptBlock method inserts the client-side script immediately below the opening tag of the Page object's