Cover | Table of Contents | Colophon
@ symbol, followed by
attribute/value pairs, and are used to specify page-level settings,
such as the language used in the page or namespaces to be imported.
For example, the following code specifies the C# programming
language:
<%@ Page Language="C#" %>
<script>...</script>
tags, as follows:
<script language="C#" runat="server"> ' code goes here </script>
<script> blocks in ASP.NET. In classic ASP,
you can write executable code in a <script>
block without wrapping that code in a subroutine. In ASP.NET, only
variable declarations can be placed outside of a subroutine. Any
other executable code not contained in a subroutine will result in an
error.
<% int i; %> <H1><%=Heading%> </H1>
Page class
inherits all of its important events from the
System.Web.UI.Control class, which is the ultimate
parent of all server controls. This means that all events described
below also apply to both built-in and custom server controls because
all of these controls ultimately derive from
System.Web.UI.Control.
runat="server"
attribute/value pair. State
management can be enabled or disabled for individual controls or an
entire page by setting the MaintainState property to
True (its default value) or
False.
_VIEWSTATE
.) It exists solely to
store the properties of controls that are not transmitted between
client and server during postbacks. As the name itself implies,
ViewState preserves the state associated with a particular view of a
page. It is used by the noninput controls (such as Label and
DataGrid) to store their ambient state across requests. Thus, when a
page is posted back to the server, and the result of the postback is
rendered to the browser, controls such as textboxes and listboxes,
will automatically retain their state, unless the
control's EnableViewState property has been set to
False or the state of the control was modified
programmatically on the server.
@
Page or @ Control directive):
<%@ OutputCache Duration="20" VaryByParam="None" %>
name
parameter, when sent as part of the query string of a GET request
(for example,
http://localhost/aspnetian/OutCache.aspx?name=John).
The cache can be varied by form fields in a POST request as well, if
desired, by setting the value of the VaryByParam
attribute to the name of the form field to vary by.
http://www.aspfriends.com/aspfriends/aspngcache.asp
http://www.gotdotnet.com/QuickStart/aspplus/
http://www.w3.org/Protocols)http://www.w3.org/Protocols)http://www.w3.org/XML)http://www.w3.org/2000/xp)WebService
attribute. The
Common Language Runtime (CLR)
takes care of the rest -- from packaging and unpackaging SOAP
requests to automatically providing HTML documentation of the web
service -- if it is called from a web browser (rather than by a
SOAP request).
@ WebService directive and a class containing the
implementation for the methods you want to expose, and decorate the
methods to be exposed with the
WebMethod
attribute. The @
WebService
directive
supports the following attributes:
Class
CodeBehind
Debug
Language
Qotd_cb web service, you would
execute the following command (again, conveniently saved as a DOS
batch file) to generate a proxy class based on the web service:
wsdl /l:vb /out:Qotd_cb_proxy.vb http://localhost/ASPdotNET_iaN/Chapter _4/Qotd_cb.asmx?WSDL pause
/l parameter specifies that the proxy class
should be generated in Visual Basic .NET (the default is C#). The
/out parameter specifies the name and, optionally,
the path of the output file. This is important if you are compiling
your proxy class in the same directory as the code-behind class that
implements the web service. In this case, if you do not specify the
output filename, the file Qotd_cb.vb will be overwritten. Once the
proxy class has been generated, it should be compiled, and the
resulting assembly should be placed in the bin directory. This can be accomplished using
a command such as the one in the following snippet:
vbc /t:library /r:System.Web.dll,System.dll,System.Web.Services.dll, System.Xml.dll,System.Data.dll /out:bin\qotd_cb_proxy.dll qotd_cb_proxy.vb pause
http://www.aspfriends.com/aspfriends/aspngwebservices.asp
http://www.gotdotnet.com/QuickStart/aspplus/
http://www.learnXmlws.com/
runat="server". For
example:
<input type="text" id="txtName" runat="server">
id
attribute is very important for all
server controls if you plan to access your control programmatically,
since it defines the name by which the object will be referenced in
code.
runat="server". For
example:
<input type="text" id="txtName" runat="server">
id
attribute is very important for all
server controls if you plan to access your control programmatically,
since it defines the name by which the object will be referenced in
code.
<a>
<img>
<form>
<table>
<tr>
<th>
<td>
<select>
<textarea>
<button>
<input>
tagsrunat="server" attribute/value pair. However,
these controls are not supported; instead, unsupported HTML elements
are handled by a generic super HTML server control called
HtmlGenericControl. The HTML elements you might typically handle in
this way include ASP namespace prefix, sometimes using
self-closing tags as follows:
<asp:textbox id="txtName" text="Hello, World!" runat="server" />
<asp:textbox id="txtName" runat="server">
Hello, World!
</asp:textbox>
id attribute. For example, if you have an ASP.NET
Label control declared as follows:
<asp:label id="Message" runat="server"/>
<script runat="server">
Sub Page_Load( )
Message.Text = "Hello, World!"
End Sub
</script>
Dim Message As New Label( ) Message.Text = "Hello, World!" Page.Controls.Add(Message)
<script>
block or in a code-behind class.
<asp:textbox id="SingleTex