Sie sind auf Seite 1von 18

ASP.

NET

.NET Framework:
.Net Framework primarily consists of two main components:
1. Common Language Runtime: This is a language-independent runtime
environment of .NET Framework that manages code at execution time.
Irrespective of what language chooses to develop your application, CLR manages
the code for all.
2. Framework Class Library: This is a repository of built-in classes and interfaces
that corresponds to a specific functionality.

CLR and FCL play key role in the development of client and server applications. The
tasks perform by CLR include memory management, code and thread execution, and type
safety enforcement, while FCL integrates with CLR to enable developers to use the built
in code managed and unmanaged code.
Managed code is what you generate from VB.NET and C# compilers. It is not the
machine code that runs directly, but the intermediate code that is stored in an assembly
and handles by CLR for execution. On the contrary, unmanaged code is the code that is
generated by older compilers, prior to Visual Studio .NET 2002. This code is the machine
executable code that executes directly without being manipulated by CLR. Managed code
has a big advantage over unmanaged code in terms of platform dependency. Managed
code is platform independent.

WHAT’S NEW IN .NET FRAMEWORK 2.0:


1. 64-Bit Support: .Net Framework 2.0 provides new support for the development
of 54-bit applications that run faster in comparison to 32-bit applications.

2. ACL Support: ACL, which stands for Access Control List, is a list containing
access permission for users to access the resources on a computer. .NET
Framework 2.0 has added several new classes, like AccessControlActions and
AccessControlModification that can be utilize by managed code to work with
ACL permissions.

3. New Features of ADO. NET: Several new features has been added to ADO
.NET like Asynchronous processing, Batch Processing, Connection pooling
control, Database mirroring in SQL Server 2005, DataRow enhancement, Schema
discovery, SQL Server UDT supports.

4. Authenticated Stream Class: .NET Framework 2.0 provide the new stream
classes, NegotiateStream class and SslStream that applications can use for
authentication.

1 of 18
5. FTP Support: Now with .NET Framework 2.0, applications can access the FTP
resources. This FTP access is achieved by using newly added classes
WebRequest, WebResponse, and WebClient.

6. The New Ping Class: The newly added Ping class provides functionality similar
to the ping command. You can use this class to verify connectivity with remote
computer. With the Send and SendAsync Methods of the Ping class, you can send
either synchronous or asynchronous calls to verify the network connectivity.

7. SMTP Support: Now, application can send e-mails to recipients by using classes
in the System.Net.Mail and System.Net.Mime namespace.

8. Generics: The concept of generics in .NET Framework 2.0 caters to the need of
something like Templates in C++. Namespace System.Collection.Generic, which
contain classes to support the concept of generics.

9. Serving HTTP Requests within Applications: With the HTTPListener class,


you can simulate a Web server to process the HTTP requests. The Web server is
active as long as the object of the HTTPListener class is alive.( This class will
works only in Windows – XP with Service Pack 2, or Windows Server 2003
environment, otherwise PlatformNotSupportedException.

10. Determining Changes in Network Connectivity: Newly introduced


NetworkChange class that enables application to determine the changes in the
network connectivity. If the IP address of the network card or an adapter is
changed due to any reason, which could be a network cable unplugged or a
hardware failure, NetworkChange class generates this notification by raising the
NetworkAddressChanged events.

Enhanced Control Set:


ASP .NET 2.0 improves the functionality of the existing controls and adds a bunch of
entirely new controls.
• The controls in ASP .NET 2.0 now come with the built-in support for themes and
skins to customize appearance.
• Data Control can now use the new data-binding model.
• All controls support adaptive rendering to render a Web application as per the
requesting web browser.
• The markup generated by the controls now caters to the XHTML 1.1 standard.
• ASP.NET 2.0 allows the Validator controls to be grouped so that a developer can
enabled validation for a specific set of controls.
• Validator controls can now be grouped that allows to selectively enabled
validation for controls.
• All controls support themes and skins that help you to customize appearance.

2 of 18
?Visual Web Developer 2005:
With ASP .NET 2.0, a brand new IDE for developing Web applications, Visual Web
Developer (VWD) 2005 has also been launched. A part of Visual Studio 2005, VWD
contains great enhancements over the previous IDEs and significantly changes the way
you develop your Web applications. It also allows a developer customize environment.
With VWD you can create HTTP, file system, or ftp based applications.

Features of VWD:
• Designing of web pages has been made easy through a drag-and-drop interface.
• The code editor is equipped with rich IntelliSence functionality that makes
writing code easier and faster.
• Integrated access to SQL Server makes it easy for developers to create data driven
websites.
• Multi-language support for developers with languages, such as VB.NET, C#, and
J#.
• Support for built-in starter kits, such as the Personal Web Starter Kit.
• Support for a built-in Web Server that runs ASP.NET web pages without Internet
Information Services (IIS).
• Support Dynamic Compilation model in which a web page can be compiled
individually instead of the previous approach in which the whole web site was
compiled together. This leads to significant productivity gains, as compile-time
errors in a page do not prevent other pages in the Web site from running.

The VWD IDE:


• Document Window (In the Tabbed Form).
• Property Window.
• Server Explorer.
• Solution Explorer.
• Toolbars.
• Toolbox.
• Task List.

/***************************** FirstPage.aspx *******************/

<%@ Page Language="VB" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Sub Page_Load()
lblServerTime.Text = DateTime.Now.ToString()
End Sub

3 of 18
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>First Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

Welcome to ASP.NET 2.0! The current date and time is:

<asp:Label
id="lblServerTime"
Runat="server" />

</div>
</form>
</body>
</html>

Understanding Framework class Library:


The .Net Framework contains thousand of classes that you can use when building an
application. Here are just a few examples of the classes in the framework:
• File Class: Enables you to represent a file on your hard drive. You can use the
File class to check whether a file exists, create new file, delete a file, and perform
many other file related tasks.
• Graphics Class: Enables you to work with different types of images such as GIF,
PNG, BMP and JPEG image. You can use graphics class to draw rectangles, arcs,
ellipsis, and other element of an image.
• Random Class: Enables you to generate a random number.
• SmtpClient Class: Enables you to send email. You can use the SmtpClient class
to send emails that contain attachments and HTML content.

The Microsoft .NET Framework includes 18,619 types; 12,909 classes; 4,01,759
public methods; 93,105 public properties; and 30,546 public events.

For Example, here is a partial list of the members of the SmtpClient class:
• Properties:
1. Host – The name or IP address of your email server.
2. Port – The number of the port to use, when sending an email message.

• Methods:
1. Send – Enables you to Send and email message synchronously.
2. SendAsync – Enables you to send an email message asynchronously.

• Events:

4 of 18
1. SendCompleted: Raised when an asynchronous send operations
completes.

Notes: The Send() method block further program execution until the send operation is
completed. The SendAsync() method sends mail asynchronously means it does not wait to
check whether the send operation was successful.

/***************************** SendMail.aspx *************************/

<%@ Page Language="VB" %>


<%@ Import Namespace="System.Net.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Sub Page_Load()
Dim client As New SmtpClient()
client.Host = "slerf"
client.Port = 25
client.Send(“a@b.com”,”kamesh@slerf.edu”,
"ASP Mail Testing!", "First Mail Sending From ASP.NET 2.0")
End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Send Mail</title>
</head>
<body>
<form id="form1" runat="server">
<div>

Email sent!

</div>
</form>
</body>
</html>

Understanding Namespaces:
There are almost 13,000 classes in the .NET Framework. This is an overwhelming
number. If Microsoft simply jumbled all the classes together, then you would never find
anything. Fortunately, Microsoft divided the classes in the Framework in to separate
namespaces.

A namespace is simply category. For example, all the classes related to working with the
file system are located in the System.IO namespace. All the classes working a Microsoft
SQL Server database are located in the System.Data.SqlClient namespace.

5 of 18
Before you can use a class in a page, you must indicate the namespace associated with
the class. There are multiple ways of doing this.

First, you can fully qualify a class name with its namespace. For example, because the
File class is contained in the System.IO namespace, you can use the following statement
to check whether a file exists:

System.IO.File.Exists(“SomeFile.txt”)

You can add an <%@ Import %> directive to a page to import a particular name space.

<%@ Import Namespace =”System.Net.Mail” %>

After you import a particular namespace, you can use all classes in that namespace
without qualifying the class names.

Finally, if you discover that you are using a namespace in multiple pages in your
application, then you can configure all the pages in your application to recognize the
namespace. If you add the web configuration file, then you do not need to import the
System.Net.Mail namespace in a page to use the classes from this namespace.

<?xml version=”1.0”?>
<configuration>
<system.web>
<pages>
<namespaces>
<add namespace=”System.Net.Mail”/>
</namespaces>
</pages>
</system.web>
</configuration>

About the Web.Config file: A Web configuration file is a special type of file that you
can add to your application to configure your application. Be aware that file is an XML
file and, therefore, all tags contained in the file are case sensitive.

Understanding Assemblies:
An assembly is the actual .dll file on your hard drive where the classes in the .NET
Framework are stored. For example, all the classes contained in the ASP.NET
Framework are located in an assembly named System.Web.dll.

More accurately, an assembly is the primary unit of deployment, security, and version
control in the .NET Framework. Because an assembly can span multiple files, an
assembly is often referred to as a “logical” dll.

6 of 18
The .NET framework 2.0 includes 51 assemblies.

About ASP.NET 2.0 Pages:


ASP.NET 2.0 web pages are text files with .aspx extension, which contains the code to
implement a Web application. These pages are stored on the IIS virtual directory. When a
client request is received by IIS, the requested page is looked up and information is sent
back to in a Response object to render the HTML markup on to the client browser. The
rendered HTML markup defines everything about web page, like its content, layout and
appearance.
When the request for a page is received for the first time, its corresponding .aspx file is
compiled to generate the class file. This class file is then used to process the request.
However, when a request for the same page is received subsequently, its class file is
referenced directly to process the request. This enhances the performance and reduces the
response time of processing a request.

<%@ Page Language="VB" AutoEventWireup="false"


CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >


<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Welcome to ASP.NET 2.0</h1>
</div>
</form>
</body>
</html>

7 of 18
Code Render Blocks:
Code render blocks are used to write inline code or inline expressions inside the .aspx
page. This inline code is executed at server and displays its output on the client browser
that requested the page. The use of code render block is to display information on the
client browser without having customarily call the Write method. The code render blocks
are represented on a page by <% %> symbols. Code present inside these symbols is
executed in top-down manner.

@ Page Language="VB" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

8 of 18
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Dim i As Integer
For i = 0 To 6 Step 1%>
<font size = " <%= i %> " >WelCome to ASP.NET 2.0</font><br />
<%Next%>
</div>
</form>
</body>
</html>

(1) Code-Behind Model:


• Place two Labels, One Text Box, One Button, and One DropdownList as shown
in the figure.
• Set the Test Property for all the controls.
• In the DropdownList’s Item property insert three items (1) Mr. (2) Mrs. (3) Miss.
• Write the following code in the Default.aspx.vb file.

Code for Default.aspx.vb file:

Partial Class _Default


Inherits System.Web.UI.Page

9 of 18
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Visible = False
Label2.Visible = False
TextBox1.Visible = False
DropDownList1.Visible = False
Button1.Visible = False
Response.Write("WelCome to my site <B> " & DropDownList1.Text &
" " & TextBox1.Text & " </B>")
End Sub
End Class

Code for Default.aspx file:

<%@ Page Language="VB" AutoEventWireup="false"


CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >


<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Select Title:"
Width="86px"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Mr.</asp:ListItem>
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Miss.</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label2" runat="server" Text="Enter Name:"
Width="116px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"
Width="166px"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" /></div>
</form>
</body>
</html>
• After Clicking on the Submitt button you can get the following out put.

10 of 18
(2) Inline Code Model:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs)
Label1.Visible = False
Label2.Visible = False
TextBox1.Visible = False
DropDownList1.Visible = False
Button1.Visible = False
Response.Write("WelCome to my site <B> " & DropDownList1.Text &
" " & TextBox1.Text & " </B>")
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >


<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Select Title:"
Width="120px"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Mr.</asp:ListItem>

11 of 18
<asp:ListItem>Mrs.</asp:ListItem>
<asp:ListItem>Miss.</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label2" runat="server" Text="Enter Name:"
Width="127px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Submit:" /></div>
</form>
</body>
</html>

ASP.NET 2.0 MODELS:


PROVIDER MODEL:
The provider model illustrates the position of providers in between ASP.NET
applications and data sources for providing ASP.NET services, such as membership and
profile. With these services, you can store the information, such as membership details
and end users profile corresponding to each ASP.NET web application.

As you can see in the Figure, providers act as communication channels that communicate
with data source. Providers can be of many types such as Membership and Role, based on
the type of the service they provide. The Membership provider stores the user name and
password, and the Role providers stores the user roles.

CODING MODEL:
ASP.NET coding models are the methodologies used for writing code in a Web
application. ASP.NET provides two types of coding models, inline and code-behind. The
inline coding models model was introduced prior to the code-behind model. In this
model, the code required to implement a web page is directly placed in the .aspx page of
an application. The major drawback of this coding model is that you need to write the
code to implement various functionalities of a Web application and the HTML code in a
common file. This way the code inside the .aspx file become quite complex and difficult
to manage, especially while building the large applications. To deal with this drawback of
the inline model, ASP.NET 1.0 introduced the code-behind model as a replacement to the
inline model. Compared to the inline code model, in the code-behind model, you need to
maintain separate code files for each for each web page. One file( filename.aspx.vb or
filename.aspx.cs ) stores the code to implement the functionalities of a web page written
in some script language like VB or C#. However, the other file ( filename.aspx ) stores
the HTML coding of the Web application.

COMPILATION MODEL:
A compilation model determines how a Web application is compiled. In ASP.NET 2.0,
there are three compilation models that you can use to compile an application. These are,

12 of 18
• Normal – It allows you to compile the code-behind files of an application into
assembly and store it in the /bin directory. In the normal mode, the .aspx files of
an application are compiled whenever a client requests them. This model is also
known as the ASP.NET 1.x model.
• Deployment Pre-Compilation – It allows you to perform the full compilation of
a project prior to its deployment. During full compilation, all files including the
code-behind files, the .aspx pages, HTML, graphic resources, and other resources
are compiled into one or more executable assemblies. This is the most effective
compilation model, as it does not allow you to perform any changes in the Web
site after deployment. Therefore, this compilation model is suitable for highly
secure Web sites but not suitable for a Web site that changes frequently.
• Full Runtime Compilation – It allows you to compile an entire application at
runtime. In this model, the un-compiled code-behind files and any other
associated code files are stored in the new \App_Code directory.

Code Sharing:
Code sharing is mechanism with common code is shared among different pages of a Web
application. Three methods are used to implement code sharing.

• Using the Code Directory: By default ASP.NET provides a unique directory


known as the App_Code to store the code files that are accessible to all the web
pages of an application. When you add something to App_code directory, such as
class or .wsdl files, it is automatically detected and compiled.
• Using the Bin directory: The code for a specific functionality in a Web
application can also be made accessible to all the web pages of Web application
by storing the sharable files in the bin directory. The ASP.NET 1.x version
supports this method for code sharing. The bin directory is similar to App_Code
directory except that it stores the precompiled assemblies of the code files that
are required by all pages of a Web application.
• Using the Global Assembly Cache: Another method of making the code for a
specific functionality available to all the web pages of Web application is by
using the global assembly cache. The .NET framework provides various
assemblies that ate stored in the global assembly cache. These assemblies can be
accessed by all the web pages of the Web application. To register or add the
required assemblies in the global assembly cache, you need to write the code in
web.config file.

Global.asax File:
The global.asax file resides in the root directory of an application and is called ASP.NET
application file. It contains the code that is executed when certain events, such as start of
an application or error in an application, are raised by ASP.NET Web application.
Events and states, such as sessions and application-state that are specified in the
global.asax file are applied to all the resources of the Web application. The code in the
global.asax file is written in the same way as Web forms. The only difference being that

13 of 18
the code written in global.asax file does not contain the HTML or ASP.NET tags. The
code in global.asax file contains methods with predefined names. The methods in
Global.asax are given below:

<%@ Application Language="VB" %>

<script runat="server">

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs on application startup
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs on application shutdown
End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs when an unhandled error occurs
End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs when a new session is started
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs when a session ends.
' Note: The Session_End event is raised only when the
sessionstate mode
' is set to InProc in the Web.config file. If session mode is
set to StateServer
' or SQLServer, the event is not raised.
End Sub

</script>

The Application-State:
The application state is used to store the data corresponding to the global variables in
ASP.NET Web application. The data in the application-state is stored once and read
many times. The application-state uses the HttpApplicationState class to store and
shared the data throughout the application. You can access the information stored in the
application-state by using the HttpApplication class property. The data stored in the
application-state is accessible to all the pages of an ASP.NET Web application and the
data is same for all the users accessing the Web application.

The Session-State:
Each client accessing a Web application maintains a distinct session with the Web server,
and there’s also specific information associated with each of these sessions. Sessions-
state is used to store this information. The session-state is defined in the <sessionState>

14 of 18
section of the web.config file and stores the data specific to a user session variables.
Different session variables are created for each user session. Also, the session variables
can be accessed from any page of Web application. When user access a Web page a
session ID is created. The session ID is transferred between the server and the client over
HTTP protocol using cookies.

Example:

GLOBAL.ASAX
<%@ Application Language="VB" %>

<script runat="server">

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs on application startup
Application("visits") = 0
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs on application shutdown
End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs when an unhandled error occurs

15 of 18
End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs when a new session is started
Session("myText") = "I am User!!!"
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)


' Code that runs when a session ends.
' Note: The Session_End event is raised only when the
sessionstate mode
' is set to InProc in the Web.config file. If session mode is
set to StateServer
' or SQLServer, the event is not raised.
End Sub

</script>

DEFAULT.ASPX
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >


<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Your Item
Name:" Width="179px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" /><br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"
Width="163px"></asp:Label><br />
<br />
Application State:<br />
<br />
No of Visits:<asp:Label ID="Label3" runat="server" Text="Label"
Width="45px"></asp:Label></div>
</form>
</body>
</html>

DEFAULT.ASPX.VB
Partial Class _Default
Inherits System.Web.UI.Page

16 of 18
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Application("visits") = Int(Application("visits") + 1)
Label2.Text = Session("mytext").ToString
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
Session("myText") = TextBox1.Text
Label2.Text = Session("myText").ToString
Label3.Text = Application("visits").ToString
End Sub
End Class

The View-State:
The view-state stores the page specific information, when a page is posted back to the
server. When a page is processed, the current state of the page and control is hashed into
a string and saved as a hidden field. Such a state of web page is called view-state and is
defined as a hidden field on a web page.
The view state property is used to save the view-state for each control, such as HTML
controls and Web controls used in a web page. If the ViewState property is not used, then
the values written in various controls, such as Textbox and CheckedBox in the web page
are not retained when the page is reloaded.

Example:
Create a web page having one button and a Label. Set Text property of the Label to “1”.

Default.aspx
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

17 of 18
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Label1.Text = (Val(Label1.Text) + 1).ToString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >


<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Add" />
<asp:Label ID="Label1" runat="server" Text="1"></asp:Label><br
/>
</div>
</form>
</body>
</html>

Click on the Button, On every click value of the Label will be incremented by 1. Now
select the label and set its “EnableViewState” property to false.

<asp:Label ID="Label1" runat="server" Text="1"


EnableViewState="False"></asp:Label><br />

Run and test the application.

18 of 18

Das könnte Ihnen auch gefallen