Using JavaScript Along with ASP.NET
Bill Evjen
Reuters
February 2004
Applies to:
Microsoft® ASP.NET
Microsoft Visual Basic® .NET
Microsoft Visual C#® .NET
Summary: Learn how to apply JavaScript in ASP.NET applications. Also learn ways of doing control focus, button rollovers, alerts and placing text in the browser's status bar. (17 printed pages)
Contents
Introduction
Adding JavaScript to a Server Control
Performing a Simple Button-rollover
Setting Control Focus
Changing the Control Focus Dynamically
Using Larger JavaScript Functions
Keeping JavaScript in a Separate File (.js)
Summary
Introduction
Web developers have been working around the limitations of the browser for a long time by using a combination of server-side processing and client-side processing. Working logic and application processes on the client-side allows browser based applications to seem more responsive and to have more "snappiness" to them. For client-side development in the past, most developers turned to JavaScript and intermingled this programming language into their classic Microsoft® Active Server Pages along with their server-side Microsoft Visual Basic® Scripting Edition or Microsoft JScript® code. Now with Microsoft ASP.NET and the new models that it provides, Web developers often wonder how to properly work with their JavaScript functions in their ASP.NET pages.
This article will take a look at some of the ways past JavaScript functions can now be used. There is more than one way to accomplish this task and this article will take a look at many different possibilities. This article will also take a look at some of the more common uses of JavaScript in ASP.NET pages with some short examples.
Adding JavaScript to a Server Control
It is quite easy to add JavaScript to a specific server control that resides on an ASP.NET page. Let's take a look at the button server control as an example. If you drag and drop a Button HTML server control (HtmlInputButton Class) onto a page using either Microsoft Visual Studio® .NET or the ASP.NET Web Matrix and run it as a server control, it should have the following construction: