Asp.Net Web Forms


As mentioned earlier, much of the functionality in ASP.NET is achieved using Web Forms. Before long you'll dive in and create a simple Web Form to give you a starting point to explore this technology. First, however, this section reviews some key points pertinent to Web Form design. It should be noted that some ASP.NET developers simply use a text editor such as Notepad to create files. I wouldn't advocate this myself, because the benefits you get via an IDE such as Visual Studio or Web Developer Express are substantial, but it's worth mentioning because it is a possibility. However, if you do take this route you have a great deal of flexibility as to which parts of a Web application you put where. This enables you, for example, to combine all your code in one file. You can achieve this by enclosing code in <script> elements, using two attributes on the opening <script> tag:

 <script language="c#" runat="server"> // Server-side code goes here. </script> 

The runat="server" attribute here is crucial, because it instructs the ASP.NET engine to execute this code on the server rather than sending it to the client, thus giving you access to the rich environment hinted at earlier. You can place your functions, event handlers, and so on, in server-side script blocks.

If you omit the runat="server" attribute, you are effectively providing client-side code, which will fail if it uses any of the server-side style coding that is discussed in this chapter. However, there might be times when you want to provide client-side code (indeed, ASP.NET generates some itself sometimes, depending on browser capabilities and what Web Form code is used). Unfortunately you can't use C# here; to do so would require the .NET Framework to be installed on the client, which might not always be the case. JavaScript is probably the next best option, because it is supported on the widest variety of client browsers. To change the language, you simply change the value of the language attribute as follows:

 <script language="JavaScript" type="text/JavaScript"> // Client-side code goes here; you can also use "vbscript". </script> 



Professional C# 2005
Pro Visual C++ 2005 for C# Developers
ISBN: 1590596080
EAN: 2147483647
Year: 2005
Pages: 351
Authors: Dean C. Wills

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net