This documentation is archived and is not being maintained.

Client Script in Web Forms Pages

If you know that the users of your Web Forms pages have uplevel browsers, you can add functionality to your pages by including client script that runs in the browser, apart from the server controls you are using.

Note   For information about uplevel and downlevel browsers, see ASP.NET Server Controls and Browser Capabilities.

Because client script runs in the browser, you can include it in the page for operations that manipulate the look of the page and require quick response time. Examples include enabling and disabling controls, performing mouseover operations, animating elements on the page, and so on.

As a rule, client script runs entirely separately from the server code that you create for your Web Forms page, and you can therefore create whatever script is required in your page. However, a few ASP.NET server controls depend on client script for their functionality. This does not prevent you from using client script when working with those controls, but you do need to understand the interaction of your client script with the client script that is produced by these controls.

The ASP.NET server controls that depend on being able to run client script include:

  • The LinkButton and HtmlButton server controls require script. (This is not true for the Button Web server control or the HtmlInputButton or HtmlInputImage controls.)
  • By default, the Calendar control implements month navigation and day selection using LinkButton controls. If you set control properties to allow users to select a day, week, or month, or if you allow users to navigate to other months, then the Calendar control will generate client script. If you use the Calendar control simply to display a single month with no selection or navigation, the control does not require client script.
  • Any Web server control whose AutoPostBack property is set to true; the client script is required so that the control will post the page.
  • The Web validation controls, which require client script to support client-side validation. If the client does not support script, validation will run on the server only.
    Note   For information on creating event handlers that run in both client script and in server code, see ASP.NET Server Control Event Model.

The client script required is automatically generated and sent as part of the page. It is compatible with all types of browsers that support at least ECMAScript (JScript, JavaScript) — that is, it does not depend on the advanced scripting capabilities of Dynamic HTML (DHTML).

Note   Some validation features can take advantage of DHTML if it is available in the browser, but DHMTL is not required.

Users sometimes disable script in a browser as a security measure. If they have, the functionality provided by client script is lost. This disables some controls, such as the LinkButton control, entirely, and disables the functionality of the AutoPostBack property. Validation is only partially affected; validation still functions, but users do not get the immediacy and performance of client-side validation.

See Also

ASP.NET Server Controls and Browser Capabilities | ASP.NET Server Control Event Model | Web Forms Validation