(Bashiry) ASP - Net Complete Reference
(Bashiry) ASP - Net Complete Reference
ASP.NET
ASP.NET
ASP.NET
ASP.NET
:
.
www.iranasp.net
:
:
[email protected]
[email protected]
[email protected]
:
http://Bashiry.persiangig.com/Ebook
1384/3/17
3
ASP.NET
9 .................................................................................................................................... ASP.NET
10 ....................................................................................................................................... Microsoft.NET
ASP.NET 13..................................................................................................................................................................
ASP.NET 17 ................................................................................................................................................
19 ..................................................................................................................................... ASP.NET
22 ............................................................................................................... ASP.NET
25 .....................................................................................................................................................
30 .........................................................................................................................................................................
33...................................................................................................................................... .NET
35 ................................................................................................................................................................................. CLR
41 ............................................................................................................................ Client server
49................................................................................................................................. ASP.NET
52 .........................................................................................................................
ASP.NET 61......................................................................................................
Cashing 73 ................................................................................................................................................. ASP.NET
78 ........................................................................................................... ASP.NET
82.............................................................................................................................................. ASP.NET
84 ..................................................................................................................................................... ASP.NET
Smart Navigation88......................................................................................................................................
91...................................................................................................................................................... ASP.NET
4
ASP.NET
Codebehind94.......................................................................................................................................................
Namespace98.......................................................................................................................................................
Upload 106.............................................................................................................. ASP.NET
Cashing 111 ................................................................................................................................................. ASP.NET
117 .....................................................................................................................................
ASP.NET 121 ........................................................................................................................
127.................................................................................................................. ASP.NET
144 ............................................................................................................................. .NET Framework 1.1
10 148..........................................................................Visual Studio .NET 2003
Thread 151 ...............................................................................................................................................ASP.NET
163 ............................................................................................................................................ ASP.NET
XML 170 ............................................................................................................................ ASP.NET
XML 173..............................................................................................................................................
176...........................................................................................................................................................ASP.NET
180 ...............................................................................................................ASP.NET
4 )2003 183 ......................................... (...
197 ................................................................................................................................... ASP.NET Whidbey
Session State 202 ................................................................................................................................ASP.NET
206...................................................................................................................................... ASP.NET
209 ................................................................................................................ ASP.NET
Web.config 214 ................................................................................................................................
5
ASP.NET
ASP.NET
404 ..................................................................................................................................................
405 ....................................................................................................................................................................... HTML
408 ............................................................................................................................................... ASP.NET
412.............................................................................................................. ASP.NET
Label 417 ........................................................................................................................................................
ListBox 420.................................................................................................................. ArrayList
Hyperlink 422 .................................................................................................................................................
424..................................................................................................................................................................
429 ....................................................................................................... ASP.NET
432 ....................................................................................................................................................
435 ...........................................................................................................................................
442 ..............................................................................................................................................................
446 ............................................................................................................................................. DataGrid
450 ............................................................................................................................................AdRotator
453 .............................................................................................................................ASP.NET
ViewState ) ( 457 ...................................................................................................
ViewState ) ( 459..................................................................................................
464 ........................................................................................................... ListBox
ListBox 471.............................................................................................................. ASP.NET
JavaScript 479 ........................................................................................................................................... ASP.NET
488 ................................................................................................................................................. DataList
7
ASP.NET
490........................................................................................... ASP.NET
497.............................................................................................................................................. DataGrid
501 ......................................................................................................................... DataGrid
DataSet 508......................................................................................
- 514 ....................................................................................................................................................
- 519 ...................................................................................................................................................
:ASP.NET 2.0 Master Page 526 .........................................
:ASP.NET 2.0 Master Page 535 ................
UserControl 540......................................................................................
544 .................................................................................................................................................................................
ASP.NET
ASP.NET
ASP.NET
Microsoft.NET
.NET
NET .NET .
.NET . .NET .NET :
.
.NET
.NET 3400 .
.
XML .
.NET
.NET
namespace .
System.IO .
. File System.IO
System.IO.File . ASP.NET
. System.Web . HTML
1 iranasp.net
10
ASP.NET
11
ASP.NET
MSIL IL . MSIL .
. ASP.NET
MSIL . MSIL JIT
. ASP.NET MSIL
.
.
ASP.NET C#
C++ .
MSIL .
.NET
. C#
.
12
ASP.NET
ASP.NET
ASP.NET ASP
Active Server Pages ASP .
.
ASP.NET
.
. ASP.NET .
ASP.NET .
ASP.NET
.
ASP.NET .
ASP.NET .
ASP.NET .
DataGrid .
ASP.NET .NET.
1 iranasp.net
13
ASP.NET
ASP.NET
ASP.NET
TextBox ListBox . ASP.NET
. ASP.NET :
ListBox RadioButton TextBoxButton.
.
.
.
Visual Studio.NET
. Notepad
.
ASP.NET
ASP.NET ASP.NET .NET
.
.NET Framework
15
ASP.NET
msdn .microsoft.com/downloads/default.asp@url=_2fcode_2fsample.asp@url=_2f
msdn -files_2f027_2f000_2f976_2fmsdncompositedoc.xml
Windows ( Professional Server ) Windows 2000 ASP.NET
. XP
16
ASP.NET
ASP.NET
ASP.NET
ASP.NET : .
.
HTML .
ASP.NET .
.
>"<Script Runat="Server
Sub Page_Load
)(myLabel.Text = DateTime.Now
End Sub
></Script
><html
><head><title>Simple.aspx</title></head
><body
<asp:Label
"ID="myLabel
>Runat="Server" /
></body
></html
1 iranasp.net
17
ASP.NET
1 >" <Script Runat="Server
> <Script/ . Page-Load
. Text Label
.
.
HTML . Label
ASP.NET HTML .
Label :
><asp:Label ID="myLabel" Runat="Server"/
HTML .
18
ASP.NET
ASP.NET
ASP.NET Init
Load...
ASP.NET :
:Init .
:Load .
: PreRender .
: Unload .
: Disposed .
.
Load :
>"<Script Runat="Server
Sub Page_Load
' Place any code that you want to execute here
End Sub
></Script
1 iranasp.net
19
ASP.NET
Page_Load Load
. Init Load PreRender Unload Disposed
Page_Init Page_Load Page_PreRender Page_Unload Page_Disposed
.
Load .
.
DataGrid .
Load PreRender Load
. .
Page_Load Button_Click Page_PreRender .
Page_Load Button_Click Page_PreRender .
>"<Script Runat="Server
Sub Page_Load
) "Response.Write( "<li> Page_Load
End Sub
) Sub Button_Click( s As Object, e As EventArgs
) "Response.Write( "<li> Button_Click
End Sub
20
Sub Page_PreRender
Response.Write( "<li> Page_PreRender" )
End Sub
</Script>
<html>
<head><title>EventOrder.aspx</title></head>
<body>
<form runat="Server">
<asp:Button
Text="Click Here!"
OnClick="Button_Click"
Runat="Server" />
</form>
</body>
</html>
21
ASP.NET
ASP.NET
ASP.NET
ASP.NET .
www.iranasp.net/download/shahoo01.zip :
. ASP.NET .
1 .
><html><body
>You are using <% =Request.Browser.Type %
></body></html
IE 5 :
You are using IE5
Request.Browser.Type 1 .
HTTPBrowserCapabilities
Browser Request HTTPBrowserCapabilities
System.Web . ASP.NET
. Request
1
22
ASP.NET
MSWC. BrowserCapabilities
ASP .
HTTPBrowserCapabilities :
:ActiveXControls .
:AOL AOL .
:Cookies
.
:Crawler .
:Browser .
:Frames Frame .
:MajorVersion IE5 5
.
:MinorVersion )( IE5.1 1.
.
:Type ..
:VBScript VBScript .
23
ASP.NET
. :Version
.
<%@ page language="VB" %>
<%@ Import Namespace="System.Web" %>
<html>
<body>
<head><title>HTTPBrowserCapabilities Demo</title></head>
<%
Dim browserObj As HTTPBrowserCapabilities
browserObj = Request.Browser
%>
<font face="verdana, arial" size=2>
<p>Your browser supports ActiveX controls: <%=browserObj.ActiveXControls %>
</p>
<p>Your browser type: <%=browserObj.Type %> </p>
<p>Your browser version: <%=browserObj.Version%> </p>
... Add any other property that you would like to display
</font>
</body>
</html>
24
ASP.NET
.
.
.
8
.
COM . 1970
Unix .
. -.NET
.NET .
Client .
NET .
. 1995 Client Server
. COM +COM
6 . 1999 50
1
25
ASP.NET
.
.
ASP Active Server Page .
. 6 Internet
Application Web Class
.
DNA
Distributed interNet Application
n-tier COM . DNA .
Presentation tire .
Internet Browser Win 32 GUI .
Win32 GUI
DLL Hell .
... .
. Java Applet ActiveX
ActiveX
IE .
Middle tier .
.
26
ASP.NET
DNA . COM
ADO ADSI .
.
Data tier .
SQL Server Oracle .
COM
DNA COM .
COM ) : NET .
(
:DLL Hell COM
. COM
GUID COM .
COM
.
.
: COM C++
COM .
27
ASP.NET
DNA
- 1 Client
ASP . ASP
.
.
- 2
textbox . Win32 GUI
textbox .
ASP refresh . Request
Response ASP.
- 3 Event Handler
Win32 GUI Event .
ActiveX
95 .
API
28
ASP.NET
API 1 .
. API
. 98 95 .
.
API . CE
.
Professional VB.NETWrox
29
ASP.NET
. 1998 6
.NET 2000 PDC
. % 80 .NET .
SOAP Simple Object Access Protocol .
Web Service .
.NET
: Win32 GUI
Win32 GUI .NET .
:
Win32 GUI.
: .NET
.
1
30
ASP.NET
: .NET
++C . Cobol.NET Pascal.NET
. .
!
Platform : .NET
Unix Linux Mobile PDA .
.NET .
.
.NET
.NET Framework
.
. .NET NET Framework.
.
.NET .
www.geocities.com/hamedbanaei/netframe.htm
CLR .NET
NET Framework. CLR Common Language Runtime . CLR
MSIL Microsoft Intermediate
31
ASP.NET
Language . IL just-in-time
. .NET .
.NET IL IL NET
Framework. . just-in-time
IL . CLR
.NET object
object . CLR Garbage
Collection . CLR .
NET Framework.
ADO.NET ADO XML .NET
Threading . thread
ASP.NET Windows Forms
client
.
Professional VB.NETWrox
32
ASP.NET
.NET
:
.
.NET Assemblies :
Modules . Types .NET (Deployment).
property
.
manifest XML HTML.
Manifest :
text .
....
.
Optional : RequiredDenied.
.
1
33
ASP.NET
.
DLL ) EXE Windows PE (Portable Executable
Meta Data IL manifest . manifest
manifest manifest . CLR
IL install-time JIT
just-in-time method by method .
. JIT . Meta Data
IL.
Value Reference . method property field .
.
Professional VB.NETWrox
34
ASP.NET
CLR
CLR
CLR Common Language Runtime NET platform. .
CLR runtime . 6
Runtime
. CLR runtime
.NET .
6 COM COM
. COM
ProgID . Word.Application
Word.Application.9. CLR GAC
Global Assemblies Cache . GAC . CLR
GAC :
:Side-by-side versioning
.
1
35
ASP.NET
. .
. .NET
. NET Framework. .
xcopy !
.NET
.
CLR VB .
: Garbage Collection
Runtime Garbage Collection .
runtime 6 .
36
ASP.NET
LOG Scripting.Stream
Scripting.FileSystemObject .
runtime . runtime
.
:Cyclical References
runtime VB
Cyclical Reference
. A reference B BA.
COM .
AddRef Release IUnKnown interface
.
COM Release .
runtime VB 6
runtime .
.
'Class : CCyclicalRef
Dim m_objRef as Object
37
ASP.NET
38
ASP.NET
nothing . .
terminate .
Garbage Collector: CLR
Garbage Collector CLR VB 6 Runtime . CLR
GC nothing
GC .
COM GC
.
:Finalize
GC Object.Finilize .
. .NET nothing Dispose Close
.
virtual memory
heap . CLR Managed Heap
Heap CLR
.
39
ASP.NET
.
Heap
. CLR heap
. .
www.geocities.com/hamedbanaei/memorialoc.htm
CLR B A C Heap . B
D
C . . CLR heap
.
CLR GC . GC B
heap heap .
Professional VB.NETWrox
40
ASP.NET
Client Server
Client/Server
80
Client/Server .
) (
Server Client )
(.
.
Client Server
.
. .
.
:
): Presentation ( )
( .
.
1
41
ASP.NET
ASP.NET
Database Engine
.
. ) ) One Tire
.
.
Reza ) (
.
.
Database Engine
) ( Conflict
) .( Record Locking
Two Tire
One-tire .
One
Tire Database Engine .
.
) Application(Logic Database Service SQL . (
43
ASP.NET
. SQL
) (
. Presentation
Busines Logic . ) (
.
.
.
DataBase Engines One-Tire
) Jet Engine ( Two Tire
Oracle , IBM DB2 , Sybase SQL Sever .
Three Tire
.
Business Logic .
Business Application Server
. Application Server DataBase Engine
. .
Application Server
.
Application Server ) .
44
ASP.NET
Application Server
Application Server
(. Application Server Database Server
.
Presentation
Application Server .
Amazon.com
.
Application Server . ) ) Three Tire
.
N Tire
. Three Tire N-
Tire . Application Server
.
. MiddleWare Business Logic
Application Server .
Bussines Logic Application Server
45
ASP.NET
.
.
) ( Application
.
.
Presentation
.
Application
.
Presentation
. .
Presentation .
Application
Presentation
Presentation .
Presentation . Logic
46
ASP.NET
Presentation
. Thin Client .
Logic Fat Client . Thin Client
.
Client Server
.
) ( .
Server Client .
One Tire Two-Tire Three Tire N-Tire
) ( Server
) (Client .
.
.
.
i
) (Reusable Code
47
ASP.NET
. Three Tire
N-Tire .
48
ASP.NET
Email ASP.NET
Email ASP.NET .
www.iranasp.net/download/shahoo04.zip :
Email ASP.NET SmtpMail
System.Web.Mail Send .
Email Send MailMessage . MailMessage
System.Web.Email Email .
MailMessage CDONTS ) CDONTS
Email ASP (.
:
Body Priority Subject BodyFormat Bcc Cc From To.
Email MailMessage
:
- 1 MailMessage :
Dim ObjMM As New MailMessage
- 2 email :
1
49
ASP.NET
ObjMM.To="[email protected]"
email: - 3
ObjMM.From="[email protected]"
: Bcc Cc - 4
ObjMM.Cc="[email protected]"
ObjMM.Bcc="[email protected]"
: html text email BodyFormat - 5
Obj.MM.BodyFormat=MailFormat.Text
High Security Priority - 6
: Low Normal
ObjMM.Priority=MailPriority.Normal
: Subject - 7
ObjMM.Subject="Hello there"
:( ) Email Body - 8
ObjMM.Body = "This is body!"
: ASP.NET System.Web.Mail
50
ASP.NET
51
ASP.NET
.
:
.
)(
.
.
: .
.
.
.
. .
Program = Logic(Code) + Data
1
52
ASP.NET
.
:
MainFrame Architecture
: Host
. )(Logic
) (Data Host
) ( .
) (Host .
File Server Architecture
Server Client .
.
Server ) (File Server
Client . .
Client Server . )
(
. ) ( Client
.
Client Server Architecture
53
ASP.NET
.
Server Client . ) (
.
.
.
.
Two Tire Architecture
) ( . DataBase
Engine
.
.
) (Tires.
Three Tire Architecture
) (
.
54
ASP.NET
.
.
: ) )
) ( . ) (
N-Tire .
.
)(
.
.
.
Component Object Model COM .
COM
) ( .
55
ASP.NET
) (
.
COM
COM
. Object Linking & Embedding OLE 1991
. ) (Documents .
. OLE 2 1995
COM .
.
.
95 NT 1996
Distributed COM DCOM . 1997
+COM .
Three Tire
.
56
ASP.NET
ASP.NET
.
.
Three Tire :
Single Server
Business Server
Transaction Server
Web Server
Single Server
.
) (Data Services .
User Service
. Business Services
User
Services )
( . User Services
.
58
ASP.NET
ASP.NET
.
.
.
.
.
.
.
.
.
.
.
.
.
60
ASP.NET
ASP.NET
ASP.NET
ASP.NET .
ASP . ASP
.
.
ASP.NET ASP
HTML .
ASP . ASP.NET
.
) (Static ) (Dynamic
ASP.NET .
.
""
Html Htm Html .
1
61
ASP.NET
.
) (
.
.
- 1 Html Htm Html
.
- 2 .
.
- 3 Htm .
- 4 Html .
- 5 Html .
.
Html )
Html
!(.
62
ASP.NET
.
Html
. Html
. )
!(.
Html .
.
. Html
. Html
. :
:
(Client Side Dynamic Web Page).
:
). ( Server Side Dynamic Web Page
.
.
IIS . Apache .
63
ASP.NET
ASP.NET
.
- 4 Html
.
- 5 Html Html
.
- 6 Html .
. VBScript ActiveX
.
)(JavaScript
. Html
.
. LiveScript .
NetScape 2.0 . Sun
.
)
C ( .
65
ASP.NET
. : )
( . .
:
. Jscript
IE 3.0 .
VBScript
IE 3.0 VBScript
.
.
) (Case Sensitive .
) (IE .
Plug-In .
VBScript .
. VBScript Script
Engine
. VB.NET VBScript .
ActiveX
66
ASP.NET
++C
.
Timer Bar Chart .
> <Object .
. Plug-in
.
.
IE .
Java Applet
Platform .
. . ><Applet
.
) (JVM .
: > <Object <Applet>.
DownLoad
) (JVM .
67
ASP.NET
Download .
. Drop-Down Menu
.
Html
Html
.
: Server-Side
- 1 Html
.
- 2
.
- 3 .
- 4 Html .
- 5 .
- 6 Html .
68
ASP.NET
. Client-Side :
Html .
. ASP ASP.NET .
.
.
CGICommon Gateway Interface
. CGI .
ASP
. CGI )
(Perl . Perl C
C++ .
Platform .
ASPActive Server Page
69
ASP.NET
ASP.NET ASP
.
VBScript . ASP
(ASP.dll).
.
.
ASP.NET .
JSPJava Server Page
Html Xml . ASP
) (IIS
. JSP ASP
. JSP Java2
JavaBeans Java2 Libraries .
ColdFusion
.
.
.
ColdFusion . IIS
70
ASP.NET
. Html-Like
) ASP.NET ( .
!
PHP
Personal Home Page PHP Hypertext
Preprocessor .
ASP.NET Cross-Platform NT
. C Perl .
.
ASP.NET
ASP.NET
. ASP.NET (aspnetIsapi.dll).
. ASP.NET )
( :
ASP.NET Server Side
.
71
ASP.NET
ASP VBScript
) VBScript (. ASP.NET .
. Jscript.NET C# VB.NET
Python Perl ASP.NET .
72
ASP.NET
Caching ASP.NET
Caching ASP.NET
Caching -1 ASP
Caching ASP
.
Caching ASP
) (Client )
HTML (.
ASP
Caching
Caching .
Caching . ASP
. ASP.NET Caching
ASP ASP.NET .
- 2 Caching ASP.NET
ASP.NET ASP . :
><%@ OutputCache Duration = "..." VaryByParam = "..." %
1
73
ASP.NET
74
ASP.NET
Caching ASP.NET
Caching ASP.NET
VaryByParam Caching
HTML .
Caching :
><%@ OutputCache Duration = "120" VaryByParam = "name" %
Label .
name . Label
21:22:10 . Caching
.
VaryByParam none Cache .
name
Caching . 30 :
http://www.iranasp.net/myexample.aspx?name=mahmoud
ASP.NET
name . Label 21:22:40 Label
name mahmoud .
15 .
75
ASP.NET
21:22:40 . Caching .
5 21:23:00 :
http://www.iranasp.net/myexample.aspx?name=mahmoud&student_no=80622121
. VaryByParam
ASP.NET .
OR .
.
120
. Caching
VaryByParam Caching )
(.
ASP.NET .
* VaryByParam
.
. none
.
- Caching 3
76
ASP.NET
Caching ASP.NET
Caching . UserControl
) ascx( . Caching UserContol
. ASP.NET Caching
UserControl Caching :
><%@ OutputCache Duration = "30" VaryByParam = "none" %
UserControl Label .
Label . Page_Load
UserControl Label .
Label .
30 Label Label
UserControl . 30
. Label .
UserControl Caching
. Caching
UserControl VaryByParam
Caching . ASP Caching
) ( . Caching
ASP.NET .
77
ASP.NET
ASP.NET
ASP.NET .
ASP.NET
.
. MSDN .
msdn.microsoft.com/library/default.asp@url=_2flibrary_2fenus_2fcpguide_2fhtml_2fcpcondevelopinghigh-performanceaspnetapplications.asp
:
Session State .
Session State .
Session Page False
.
Session web.config .
.
1 iranasp.net
78
ASP.NET
.
round trip .
.
.
.
HTML .
Page.IsPostback .
Page.IsPostback ) (round trip .
.
View State .
View State Session State
. .
.
" Strict="true .
79
ASP.NET
80
ASP.NET
81
ASP.NET
ASP.NET
ASP.NET
.
.
.
( ( .
.
ASPASP.NET
ASP.NET ASP . ASP
IIS ASP.NET
.
ASP.NET
1
82
ASP.NET
:Authentication
) ( .
.
Authentication.
:Authorization
.
:Impersonation
.
)(Impersonated . Impersonation (Server
)Process ) (Client .
83
ASP.NET
ASP.NET
ASP.NET Email
.
www. iranasp.net/download/pourshahid02.zip :
email .
System.Web.Mail
.
><%@ Import Namespace="System.Web.Mail" %
Instance .
Dim mail As New MailMessage
:
:mail.From email
:mail.To email
:mail.Subject
:mail.Body email HTML
1
84
ASP.NET
:mail.BodyFormat
( Local) :SmtpMail.SmtpServer
:SmtpMail.Send(mail)
Submit
.
Label
.
<%@ Page Language="VB" EnableSessionState="False"
EnableViewState="False" Trace="False" Debug="False" Strict="True" %>
<%@ Import Namespace="System.Web.Mail" %>
<script language="VB" runat=server>
Sub Page_load(Sender as Object, E as EventArgs)
If request.form("EmailAddress") = "" Then
dim strResponse as string = "<h2>Send Email using ASP.NET formatted in
HTML</h2>"
lblMessage.Text = strResponse
Else
dim strResponse as string = "You just sent an email message formatted in HTML
to:<br><h2>" &request("EmailAddress") & "</h2>"
lblMessage.Text = strResponse
End If
85
ASP.NET
End Sub
Sub btn_Click(sender as Object, e as System.EventArgs)
If request.form("EmailAddress") <> ""
Dim mail As New MailMessage
mail.From = [email protected]
mail.To = request.form("EmailAddress")
mail.Subject = "Message sent using ASP.NET and CDONTS"
mail.Body = "HTML Message sent from Iranasp.net using ASP.NET and
Cdonts<br>Wonder how this is done?<br><br>Wonder How to setup CDONTS?"
mail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "LocalServerName"
SmtpMail.Send(mail)
End If
End Sub
</script>
<html>
<head>
</head>
<body>
<h1 align="center">Sending Email via ASP.NET and CDONTS..</h1>
<b>How do I setup my server to use CDONTS?</b>
<br/>
<br/>
<br/>
<br/>
86
ASP.NET
87
ASP.NET
Smart Navigation
) smart navigation !(
.
Smart Navigation
Smart Navigation ASP.NET .
.
HTTP .
.
scrolling
.
.
)
listbox . (.
1
88
ASP.NET
Smart Navigation
! IE 5
. Smart Navigation
. Smart
Navigation . ASP.NET Smart Navigation
.
Smart Navigation :
.
Scroll .
.
) (History .
(!) Postback
.
- .
.
89
ASP.NET
90
ASP.NET
ASP.NET
. ASP. NET
ASP.NET .
ASP.NET .
.asax
Global.asax .
ASP.NET .
ASP.NET .
.ascx
ASP.NET (User Control).
ASP.NET ) (
. ASP.NET
.
.
.asmx
1
91
ASP.NET
XML .
.NET.
.
.aspx
ASP.NET ASP.NET
.
.axd
tracing ASP.NET ASP.NET
HTTP .
.vsdisco
XML .
VSDISCO .
.htm
HTML .
.xml
92
ASP.NET
www.nashreoloom.com/showbooks.aspx@id=110
93
ASP.NET
codebehind
codebehind
codebehind )
(ASP.NET . ASPX ) ASMX
(ASCX aspx.cs- ) C# VB.NET ( aspx.vb
. HTML .
:
HTML .
) VS.NET (
VS.NET >" <Script runar="server
codebehind .
1
94
ASP.NET
codebehind
ASP.NET object . ASP.NET ASPX
System.Web.UI.Page .
)( ASP.NET
cache .
ASPX
.
System.Web.UI.Page .
codebehind
ASPX System.Web.UI.Page
:
><%@ Page Inherits="YourNamespace.NewPage" %
NewPage
System.Web.UI.Page . ASP.NET \bin
cache ) (Global Assembly Cache NewPage
.
.
(www.angrycoder.com/default.htm) angryCoder .
codebehind .
95
ASP.NET
codebehind ASP.NET .
ASP.NET ( codebehind
dll \bin( . Src
:
><%@ Page Src="NewPage.aspx.cs" Inherits="YourNamespace.NewPage" %
VS.NET codebehind
:
"<%@ Page Codebehind="NewPage.aspx.cs" Inherits="YourNamespace.NewPage
>%
VS.NET codebehind dll
\bin . Src
Codebehind Page Src
codebehind .
codebehind .
dll \bin codebehind Inherits
. Src codebehind .
ASP.NET JIT codebehind .
96
ASP.NET
VS.NET Codebehind .
VS.NET .
97
ASP.NET
Namespace
Namespace namespace
.
NET Framework.
)namespace ( .
.
.
NET Framework.
ASP.NET .
. :
Public Class NewClass
][Procedures and Functions
End Class
Public Class NewClass
][Procedures and Functions
End Class
1
98
ASP.NET
.
.
:
Namespace One
Public Class NewClass
][Procedures and Functions
End Class
End Namespace
Namespace Two
Public Class NewClass
][Procedures and Functions
End Class
End Namespace
NewClass
. One.NewClass
Two.NewClass .
.
.
99
ASP.NET
) ( .
.
.
ASP.NET .
ASP.NET
. .
ASP.NET . System Microsoft .
.
System
System ASP.NET NET
Framework. . System
. System
9 . ) System 8 )
ASP.NET :
System
System.ComponentModel.Design
System.Data
System.Drawing
System.Web.SessionState
100
ASP.NET
System.Web
System.Web.UI
System.Web.UI.WebControls
System.Web.UI.HTMLControls
) ) System Visual Studio.NET VS.NET
ASP.NET . .
:System.ComponentModel.Design
NET Framework. .
:System.Data
ADO.NET .
: System.Drawing
System.Drawing
System.Drawing.Drawing2D System.Drawing.Imaging
.
: System.Web /
. ) HTTPRequest
HTTP( ) HTTPResponse
( .
101
ASP.NET
: System.Web.SessionState
: System.Web.UI
ASP.NET
. Page
. Active Server Page Page :
Server Request Response ApplicationSession.
: System.Web.UI.HTMLControls HTML
.
HTML " runat="server
"id="controlname .
: System.Web.UI.HTMLControls
HTML
.
.
: System.IO
.
102
ASP.NET
: System.Data.OleDb
ADO .
: System.Data.SqlClient
: System.Web.Security
ASP.NET .
.
: System.XML XML
.
Microsoft
System .NET
.
.
: Microsoft.VisualBasic CLR Visual Basic.NET .
Visual Basic.NET .
.
: Microsoft.CSharp
#C .
103
ASP.NET
: Microsoft.JScript
JScript .
: Microsoft.Win32 hive
.
ASP.NET
. .
ASP.NET
ASP.NET . ) (Directive
@Import ASPX Imports codebehind
C# using .
System.Web.UI.WebControls ASP.NET .
><%@ Import namespace = "System.Web.UI.WebControls" %
codebehind .
)Imports System.Web.UI.WebControls (vb.net
)using System.Web.UI.WebControls; (C#
) Import Imports (
104
ASP.NET
ASP.NET codebehind
. System.Web.UI.HTMLControls
Imports
System.Web.UI.HTMLControls . .Imports System
VS.NET .
.NET
. Intellisense . ASP.NET
:
><%@ Import namespace = "System.Web.UI.WebControls" %
><%@ Import namespace = "System.Web.UI.HTMLControls" %
><%@ Import namespace = "namespace name" %
...
codebehind :
Imports System.Web.UI.WebControls
Imports System.Web.UI.HTMLControls
Imports namespace
) ASP.NET (
www.nashreoloom.com/showbooks.aspx@id=110
105
ASP.NET
upload ASP.NET
upload ASP.NET .
Upload .
HTML .
ASP.NET .
. ASP
component ASP.NET .
Upload.aspx:
><HTML
><HEAD
><TITLE>Uploading File...</TITLE
>"<Script language="vb" runat="server
)sub page_load(s as object,e as EventArgs
If Not (MyInputFile.PostedFile Is Nothing) Then
)"MyInputFile.PostedFile.SaveAs("c:\filename.ext
)"Response.write("Your File was saved on the server...
End If
end sub
></script
></HEAD
><BODY
1
106
ASP.NET
ASP.NET
ASP.NET
(C:\images\personal\myface.jpg
upload stream : InputStream
.
109
ASP.NET
request 4096 ) 4 kb
( . 4 kb .
web.config machine.config > <system.web
><httpRuntime maxRequestLength="1000000"/
maxRequestLength .
. ) ( 1 MGB .
web.config :
Configuration file : web.config
>? "<?xml version="1.0" encoding="utf-8
> <configuration
><system.web
><httpRuntime maxRequestLength="1000000" /
></system.web
></configuration
110
ASP.NET
Caching ASP.NET
Output Caching-2
Output Caching
1 iranasp.net
111
ASP.NET
Output Caching
cache .
cache .
Output Caching
CPU .
Output Caching
.
Output Caching .aspx asmx. ascx.
.
@OutputCache
Output Caching :
><%@ OutputCache Duration="600" Location="Any" VaryByParm="none" %
:
][C#
;))Response.Cache.SetExpires(DateTime.Now.AddSeconds(600
;)Response.Cache.SetCacheability(HttpCacheability.Public
OutputCaching
:Duration cache .
.
112
ASP.NET
:Location cache .
Server cache .
Downstream cache proxy server .
Client cache .
Any cache .
None cache .
:VaryByParam cache
QueryString Form .
><%@ OutputCache Duration="10" VaryByParam="location;count" %
:VaryByHeader cache
HTTP header .
><%@ OutputCache Duration="60" VaryByHeader="Accept-Language" %
.
HttpApplication.GetVaryByCustomString
Global.asax .
113
ASP.NET
Fragment Caching-3
o
cache
User
Control .
o
@OutputCache
.
o
VaryByParam
VaryByControl.
o
cache Location
cache .
:VaryByControl @Outputcache
. .
cache ) (properties .
][*.ascx
><%@ Language="C#" %
"<%@ OutputCache Duration="10" VaryByControl="State;Country
>VaryByParam="*"%
><script runat=server
114
ASP.NET
cache .
cache .
.
cache
. exception .
.
Data Caching-4
data cache DataSet
cache:
Cache ("counter") = mycount.text
Application
.
115
ASP.NET
cache
cache .
Public Function GetProductData() As DataSet
If (IsNothing(Cache("ProductData")) Then
)(Cache("ProductData") = LoadDataSet
End If
)"Return Cache("ProductData
End Function
cache .
cache Cache.Insert
Cache.Add .
Cache.Remove cache .
116
ASP.NET
ASP.NET Context
.
ASP.NET .
Session Application QueryString
. Context
Server.Transfer . Context Session
:
;)"Context.Items.Add("NameOfVariable","ValueOfVariable
;)"Server.Transfer("WebForm2.aspx
:
;)(Label1.Text=Context.Items["NameOfVariable"].ToString
object
Cast .
Session
. .
1
117
ASP.NET
Imports System.Collections
Public Class StaticContainer
Private Shared thing As Hashtable
Public Shared Sub InitThing()
thing = New Hashtable()
End Sub
Public Shared Sub KillThing()
thing.Clear()
thing = Nothing
End Sub
Public Shared Sub AddContainer(ByVal key As Object)
thing.Add(key, New ArrayList())
End Sub
Public Shared Sub RemoveContainer(ByVal key As Object)
thing.Remove(key)
End Sub
Public Shared Sub AddToContainer(ByVal newname As String, ByVal index As
Integer,
ByVal stuff As String, ByVal key As Object)
Dim temp As ArrayList = thing.Item(key)
thing.Remove(key)
Dim t As New triple()
t.name = newname
t.ID = index
t.data = stuff
temp.Add(t)
118
ASP.NET
thing.Add(key, temp)
End Sub
Public Shared Function GetEntry(ByVal x As Integer, ByVal key As Object) As triple
Dim temp As ArrayList = thing.Item(key)
Dim result As triple
If temp.Count > x And x >= 0 Then
result = CType(temp(x), triple)
End If
Return result
End Function
End Class
Public Structure triple
Public name As String
Public ID As Integer
Public data As String
End Structure
: Global.asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
StaticContainer.InitThing()
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Session.Add("key", DateTime.Now.Ticks.ToString("x"))
StaticContainer.AddContainer(Session.Item("key"))
119
ASP.NET
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
StaticContainer.RemoveContainer(Session.Item("key"))
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
StaticContainer.KillThing()
End Sub
. Session Container ID
Session Hashtable
: .
StaticContainer.AddToContainer(TextBox1.Text, Integer.Parse(TextBox2.Text),
TextBox3.Text, Session.Item("key"))
Dim t As triple = StaticContainer.GetEntry(Integer.Parse(TextBox4.Text),
Session.Item("key"))
ListBox1.Items.Add(t.name)
ListBox1.Items.Add(t.ID.ToString())
ListBox1.Items.Add(t.data)
. triple
http ://www.dotnetjunkies.com/tutorials.aspx?tutorialid=600:
120
ASP.NET
ASP.NET
ASP.NET .CDOSYS
IranASP.NET
E-mail
ASP.NET .
ASP.NET .
:
][C#
;)(MailMessage objMM = new MailMessage
;"objMM.From = "[email protected]
;"objMM.To = "[email protected]
;"!objMM.Subject = "Welcome
;"objMM.Body = "Welcome to IranASP.NET
;)SmtpMail.Send(objMM
.
Exception :
The "SendUsing" configuration value is invalid.
1
121
ASP.NET
.
: Service Pack 3 Microsoft Exchange Server
! host . .
.
SMTP Server IIS .
.
.
. CDOSYS .CDONTS
2000 NT . CDOEX Exchange
.
CDOSYS
CDONTS . :
SMTP Server : .
: 25 .
username password SMTP Authentication.
122
ASP.NET
. :
.
. :
! IranASP.NET
.
IranASP.NET
:
[C#]
int cdoSendUsingPickup = 1;
string cdoSendUsingMethod = "http://schemas.microsoft.com/
cdo/configuration/sendusing";
string cdoSMTPServerPickUpDirecory = "http://schemas.microsoft.com/
cdo/configuration/smtpserverpickupdirectory";
// You can uncomment each line when you need it!
//string cdoSMTPServer = "http://schemas.microsoft.com/
cdo/configuration/smtpserver";
//string cdoSMTPServerPort = "http://schemas.microsoft.com/
cdo/configuration/smtpserverport";
//string cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/
cdo/configuration/smtpconnectiontimeout";
//string cdoSMTPAuthenticate = "http://schemas.microsoft.com/
123
ASP.NET
cdo/configuration/smtpauthenticate";
//string cdoSendUserName = "http://schemas.microsoft.com/
cdo/configuration/sendusername";
//string cdoSendPassword = "http://schemas.microsoft.com/
cdo/configuration/sendpassword";
//For CDOSYS, the pickup directory is located at
c:\inetpub\mailroot\pickup
string strPickup = "c:\\inetpub\\mailroot\\pickup";
CDO.Message objMM = new CDO.Message ();
ADODB.Fields Flds = objMM.Configuration.Fields;
Flds[ cdoSendUsingMethod ].Value = cdoSendUsingPickup;
Flds[ cdoSMTPServerPickUpDirecory ].Value = strPickup;
Flds.Update ();
objMM.HTMLBodyPart.Charset = "utf-8";
objMM.MimeFormatted = true;
objMM.From = "[email protected]";
objMM.To = "[email protected]";
objMM.Subject = "Welcome!";
objMM.HTMLBody = "<HTML><HEAD></HEAD><BODY><b>Welcome to
IranASP.NET!</b></BODY></HTML>";
124
ASP.NET
objMM.Send ();
. HTMLBody utf-8
GAC bin DLL
:( bin )
adodb.dll
Interop.CDO.dll
. 2000
. Visual Studio .NET References
:
1.
msdn.microsoft.com/library/default.asp@url=_2flibrary_2fenus_2fcdosys_2fhtml_2f_cdosys_about_cdo_for_windows_2000.asp
2.
msdn.microsoft.com/library/default.asp@url=_2flibrary_2fenus_2fcdosys_2fhtml_2f_cdosys_messaging_configuration.asp
3.
ASP.NET
msdn.microsoft.com/library/default.asp@url=_2flibrary_2fenus_2fcdosys_2fhtml_2f_cdosys_configuring_the_message_object.asp
4.
msdn.microsoft.com/library/default.asp@url=_2flibrary_2fenus_2fcdosys_2fhtml_2f_cdosys_messaging_examples_creating_and_sending_a_mes
sage.asp
5.
6.
www.asp101.com/articles/john/cdosmtprelay/default.asp
126
ASP.NET
ASP.NET
) (template .
) (...
.
. .
.
.
) Main Part (
. ) (
) (Main Part
.
.
Main Part ) formsbuttons datagrid
.(...
1
127
ASP.NET
.
.
.
)(Frame
HTML
. HTML
)(DOM JavaScript .
.
. (Main
)Part .
.
Address bar
refresh navigating
!
ASP.NET
User controls .
.
128
ASP.NET
.
. code behind
.
User Control
user
control .
. :
)(1
)(2
3 Main Part .
3 1 2
) User Control UC (
. )(Panel . 1 ) :
(Panel_logo.ascx
---Panel_logo.ascx file---
129
ASP.NET
ASP.NET
</tr>
</table>
.
Codebehind runat=server < td>
.
property .
: Codebehind .
---Panel_right.ascx.vb file--Protected WithEvents td1 As System.Web.UI.HtmlControls.HtmlTableCell
Protected WithEvents td2 As System.Web.UI.HtmlControls.HtmlTableCell
Protected WithEvents td3 As System.Web.UI.HtmlControls.HtmlTableCell
: property . td1,td2,td3
Public WriteOnly Property current_page() As Integer
Set(ByVal Value as Integer)
Select Case Value
Case 1
td1.InnerHtml = "Home Page"
Case 2
td2.InnerHtml = "Searching"
Case 3
td3.InnerHtml = "About Us"
131
ASP.NET
End Select
End Set
End Property
searching 2 current_page
searching
.
.
: template.aspx
---template.aspx--<%@ Register TagPrefix="Mysite" TagName="Panel_right" Src="Panel_right.ascx"
%>
<%@ Register TagPrefix="Mysite" TagName="Panel_logo" Src="Panel_logo.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="template.aspx.vb"
Inherits="site.template"%>
<HTML>
<head> My site </head>
<body>
<table>
<tr>
<td colspan="2">
<mysite:panel_logo id="panel_logo1" runat="server"></mysite:panel_logo>
</td>
</tr>
132
ASP.NET
ASP.NET
><tr
>"<td colspan="2
><mysite:panel_logo id="panel_logo1" runat="server"></mysite:panel_logo
></td
></tr
><td ... : 1-...2-...
></td
><td
"<mysite:panel_right id="panel_right1" current_page="3
>runat="server"></mysite:panel_right
></td
><tr
></tr
></table
></body
></HTML
directive Page "
)" (Main Part current_page
panel_right 3 .
.
. 200
. panel_logo :
134
ASP.NET
135
ASP.NET
.
. .
.
HTML . HTML
HTML
.
.
.
... .
:
HTML
.
.
. :
) (Main Part .
136
ASP.NET
... IranASP.NET
. ) (Main Part .
.
)(Main Part . Main
Part .
" "
.
.
.
. . HTML
Main Part :
"<%@ Register TagPrefix="Mysite" TagName="Panel_right" Src="Panel_right.ascx
>%
><%@ Register TagPrefix="Mysite" TagName="Panel_logo" Src="Panel_logo.ascx" %
>Inherits="site.template"%
><HTML
><head> My site </head
><body
><table
><tr
>"<td colspan="2
137
ASP.NET
: HTML
</td>
<td>
<mysite:panel_right id="panel_right1" runat="server"></mysite:panel_right>
</td>
<tr>
</tr>
</table>
</body>
</HTML>
.
: (segment_top.ascx)
---segment_top.ascx--<%@ Register TagPrefix="Mysite" TagName="Panel_logo" Src="Panel_logo.ascx" %>
<%@ Control Language="vb" AutoEventWireup="false"
138
ASP.NET
ASP.NET
></td
><tr
></tr
></table
></body
></HTML
directive . HTML
) well formed(
. .
VS.NET
.
. .
) (
. panel_right codebehind
.
---segment_down.ascx.vb--Protected WithEvents Panel_right1 As Panel_right
:
140
ASP.NET
141
ASP.NET
142
ASP.NET
aspx . .
HTML aspx
. .
aspx
.
.
www.hudhud-dubai.com
) www.irantbc.com( .
143
ASP.NET
1.1
.
1,1
.
PDA
NET Framework 1.0.
Microsoft Mobile Internet Toolkit
.
1,1
Visual Studio .NET 2003 .
:
Side-by-Side 1,1
)(Component
(Version Control).
1
144
ASP.NET
.
. .
.
msdn.microsoft.com/netframework/productinfo/versioncomparison/default.asp
Windows Forms
1,1 (Assembly DLL( Windows Forms
. Microsoft Windows Forms
) (Web based Windows Forms
.
ASP.NET
" " Code Access
Security ASP.NET ) (Web Services
.
" " CLR
.
ISP .
ODBCORACLE
145
ASP.NET
ASP.NET
1.1 6
IPv6 .
.
) (scalibility
)(performance 1,1 .
) ) Secure Code
.
: What's New in the .NET Framework 1.1
msdn.microsoft.com/netframework/productinfo/overview/whatsnew.asp
147
ASP.NET
1
148
ASP.NET
149
ASP.NET
Help online
.
- 10 ) (IDE
VS. NET 2003
.
150
ASP.NET
Thread ASP.NET
Threading ASP.NET
Application Domain .
Visual Studio.NET
.
Threading . System Threading
. Help VS.NET
Thread Safety
.
Thread .
.
Thread ) (Process
.
.
) VS.NET MS Access
WinAmp !). Windows
1
151
ASP.NET
152
ASP.NET
Thread
Thread Thread
) ) .
Thread .
) (.
Processes Windows Task Manager .
View Select Columns . Thread Count
OK . Processes
Threads . .
IExplore.exe . Processes Windows Task
Manager . IExplore.exe
.
. Thread.
Explorer.exe . Threads .
Thread . Windows
Explorer ) Start ( Explore.
Explore.exe !
153
ASP.NET
Threads Explore.exe .
) Windows Explorer ( .
.
Windows Explorer
Explorer.exe Thread .
Thread Thread .
.
. Thread Thread
. .
Thread .
.
Thread . Thread 120
. Thread Thread
Thread .
Thread Thread .
154
ASP.NET
Thread ASP.NET
Thread
ASP_wp.exe INETinfo.exe
ASP.NET . Application Domain
ASP.NET .
Application Domain
ASP.NET
Thread
Thread . 1000
.
IIS Restart
.
.
IIS Restart Thread Restart
Thread
. Thread
Restart )( .
155
ASP.NET
Application Domain
. Application Domain .
Application Domain ASP.NET .NET .
Application Domain . Application Domain
. Application Domain
. . Application Domain .
Restart.
Application Domain Thread
.
Application Domain Thread
. :
Application Domains
Threads
Thread ASP.NET
.
156
ASP.NET
ASP_wp.exe Thread .
Machine.Config processModel
. 25 .
Thread Debugger
NET Framework SDK. .
Debugger .
QuickStart ASP .NET .
:
samples.gotdotnet.com/quickstart/aspplus/doc/debugcomsdk.aspx
.:
DbgCLR.exe
ASP.NET Code Behind )
( ) index.aspx.vb default.aspx.vb ( ...
ASP.NET Debugger .
ASPNET_wp.exe INETinfo.exe.
Debugger Tools | Debug Processes
Attach . INETinfo.exe
157
ASP.NET
158
ASP.NET
...
Thread
Thread . F5
Debugger . Thread
. Thread .
.
) ( .
Debugger .
Thread Threads . ) F11 (F10
) (
Page_Load !! ... . Threads.
Thread .
CLR .
) F11 (F10 . Thread
. Threads
Thread . Thread
Thread . Thread
Thread .
Thread .
:
159
ASP.NET
Thread .
Thread . Thread .
.
.
.
Thread .
.
.
.
) ( . CLR
.
.
.
. . ASP.NET
) Multi-Threading
Thread ( .
MultiThreading .
160
ASP.NET
. Application
Cache
.
.
Thread-Safety
NET Framework.
. :
" ) static shared (VB.NET MultiThreaded
" .
. insert Thread-Safe
Thread delete )
( .
MultiThreaded )
Debugger Thread
(.
Thread-Safe .
161
ASP.NET
.
.
)
!!(.
) (NET Framework Developer's Guide:
Threads and Threading
Threading
Thread Synchronization
MultiThreaded Applications
Application Domains and Threads
Professional ASP.NET 1.0 Wrox Press.
162
ASP.NET
ASP.NET
ASP.NET .
ASP.NET .
:
- 1
- 2
- 3ASP.NET
- 4
- 5
- 6 Include
- 7 HTML
- 1
aspx ascx
. > <% @%
) (.
1
163
ASP.NET
164
ASP.NET
ASP.NET
166
ASP.NET
ASP.NET
ASP.NET .
.
- 6 Include
ASP.NET .
:
><!-- #include file | virtual = filename --
File Virtual . File
Include .
Virtual .
MyDir wwwroot :
><!-- #include virtual="/mydir/includefile.aspx" --
Include
.
- 7 HTML
ASP.NET HTML .
HTML . HTML ASP.NET
168
ASP.NET
. HTML LiteralControl .
Text HTML ASP.NET .
169
ASP.NET
XML ASP.NET
XML
.
xml dataset XMLDocument
.
XMLTextReader . XMLTextReader
) (ForwardOnly non-cached
.
:
)(Read DataReader .
)(ReadElementString .
Item Attribute .
HasAttributes Attribute .
:
XML :
1
170
ASP.NET
ASP.NET
End If
End While
)(xrdr.Close
XML
. .
172
ASP.NET
XML
XML
XML .
Access . XML
Load :
)(Dim DS As New DataSet
Dim strConnect As New
))"OleDbConnection(ConfigurationSettings.AppSettings("datasource
Dim objSQLAdapter As New OleDbDataAdapter("SELECT * from blog order by id
)DESC", strConnect
)"objSQLAdapter.Fill(DS, "blog
)Dim doc As XmlDataDocument = New XmlDataDocument(DS
Dim writer As XmlTextWriter = New XmlTextWriter("D:\www\weblog\weblog.xml",
)Nothnig
writer.Formatting = Formatting.Indented
)doc.Save(writer
DataSet
XML weblog.xml . XML
XML .
1
173
ASP.NET
XML . XML
.
XML ) (RSS . ASPX
Design HTML .
><asp:DataList id="theDataList" runat="server" Width="100%" dir=rtl CssClass=text
><ItemTemplate
>:<%# DataBinder.Eval(Container.DataItem, "news_date") %><br
>: <%# DataBinder.Eval(Container.DataItem, news_title") %><br><br
><%# DataBinder.Eval(Container.DataItem, "news_body") %><br
><hr
></ItemTemplate
></asp:DataList
><br
DataList . Load
:
)(Dim ds As New DataSet
)ds.ReadXml("d:\www\weblog\weblog.xml", XmlReadMode.Auto
theDataList.DataSource = ds
)(theDataList.DataBind
XML ASP.NET .
XML
174
ASP.NET
.
:
)(Dim ds As New DataSet
)ds.ReadXml("http://www.website.com/weblog.xml",XmlReadMode.Auto
theDataList.DataSource = ds
theDataList.DataBind
175
ASP.NET
ASP.NET
ASP.NET
System.Drawing System.Drawing.2D
Bitmap Graphics :
)Dim bmp As New Bitmap (400, 400
)Dim g As Graphics = Graphics.FromImage (bmp
)g.Clear(Color. White
Graphics .
Draw Fill . Draw
Pen Fill Brush :
)Dim bru As New Solid Brush (Color.Red
)Dim ps As New Pen (Color. Blue
))g.FillRectangle (b, New Rectangle (-10, -10, 320, 220
)Dim rec As New Rectangle (-100, -75, 200, 100
)g.DrawPie (ps, rec, 0, 180
Response.contenttype
. Dispose Bitmap
Graphics :
1
176
ASP.NET
"response.contenttype="image/jpeg
'Send the image to the viewer
(bmp.save (response.outputstream, imageformat.jpeg
)( bmp.dispose
)( g.dispose
.
Y :
Matrix
) (100 . Y 1
-1 Translate .
Graphics :
)Dim mt As Matrix = New Matrix (1, 0, 0, -1, 0, 0
)mt.Translate (150, 100
g.Transform = m
Graphics .
177
ASP.NET
.
:
Dim pf(5) As PointF
' --------------pf(0) = New PointF(120, 120)
pf(1) = New PointF(180, 120)
pf(2) = New PointF(150, 90)
Pf(3) = New PointF(120, 90)
pf(4) = New PointF(120, 120)
g.FillPolygon (bru, pf)
' --------------bru.Color = Color.BlueViolet
pf(0) = New PointF(150, 90)
pf(1) = New PointF(180, 120)
pf(2) = New PointF(180, 180)
pf(3) = New PointF(150, 210)
pf(4) = New PointF(150, 90)
g.FillPolygon(bru, pf)
' ----------------bru.Color = Color.SteelBlue
pf(0) = New PointF(90, 90)
pf(1) = New PointF(150, 90)
pf(2) = New PointF(150, 210)
pf(3) = New PointF(90, 210)
178
179
ASP.NET
ASP.NET
ASP.NET
ASP.NET
IIS ASP.NET .
ASP.NET IIS .NET Framework
) (Authentication
) (Authorization .
IIS ASP.NET
:
-1 HTTP SSL
.
IIS -2 NTLM) Integrated (Kerberos
DigestBasic Certificate . IIS
anonymous ) ( .
IIS
1
180
ASP.NET
anonymous ) anonymous
" "User-Machine ( .
IIS -3 .
NTFS ACL .
IIS IP .
IIS -4 ) anonymous( ASP.NET
.
ASP.NET -5 . ASP.NET
Windows ASP.NET
Forms HTML
SQL Server Active Directory
. ASP.NET Passport
Passport .
ASP.NET -6 .
) UrlAuthorization Module HTTP (
) web.config > (<authorization .
) FileAuthorization Module .
(HTTP ACL
181
ASP.NET
. .NET
web.config .
-7
ASP.NET ASP.NET
.
.
Authorization, and ,Building Secure ASP.NET Applications: Authentication :
Secure Communication
msdn .microsoft.com/library/default.asp@url=_2flibrary_2fenus_2fdnnetsec_2fhtml_2fsecnetlpmsdn.asp
182
ASP.NET
4 2003
][VB.NET
Dim x As Integer
Public x As Integer = 10
][J#.NET
;int x
;int x = 10
][C+ + .NET
;int x
;int x = 10
][C#.NET
;int x
;int x = 10
1
183
[VB.NET]
comment '
x = 1 ' comment
Rem comment
[J#.NET]
comment //
multiline */
/* comment
**/
Class Documentation
/*
[C+ + .NET]
comment //
multiline */
/* comment
[C#.NET]
comment //
multiline */
184
ASP.NET
ASP.NET
/* comment
[VB.NET]
nVal = 7
[J#.NET]
nVal = 7;
[C+ + .NET]
nVal = 7;
[C#.NET]
nVal = 7;
[VB.NET]
If nCnt <= nMax Then
nTotal += nCnt ' Same as nTotal = nTotal + nCnt.
nCnt += 1 ' Same as nCnt = nCnt + 1.
Else
nTotal += nCnt
nCnt -= 1
End If
185
[J#.NET]
if (nCnt <= nMax){
nTotal += nCnt;
nCnt++;
}
[C+ + .NET]
if(nCnt < nMax) {
nTotal += nCnt;
nCnt++;
}
else {
nTotal += nCnt;
nCnt--;
};
[C#.NET]
if (nCnt <= nMax)
{
nTotal += nCnt;
nCnt++;
}
else
{
nTotal +=nCnt;
nCnt--;
186
ASP.NET
ASP.NET
[VB.NET]
Select Case n
Case 0
MsgBox ("Zero")
'VB.NET exits the Select at the end of a Case
Case 1
MsgBox ("One")
Case 2
MsgBox ("Two")
Case Else
MsgBox ("Default")
End Select
[J#.NET]
switch(n) {
case 0:
System.out.println("Zero\n");
break;
case 1:
System.out.println("One\n");
break;
default:
System.out.println("?\n");
187
[C+ + .NET]
switch(n) {
case 0:
printf("Zero\n");
break;
case 1:
printf("One\n");
break;
case 2:
printf("Two\n");
break;
default:
printf("?\n");}
[C#.NET]
switch(n)
{
case 0:
Console.WriteLine("Zero");
break;
case 1:
Console.WriteLine("One");
break;
case 2:
188
ASP.NET
ASP.NET
Console.WriteLine("Two");
break;
default:
Console.WriteLine("?");
}
For
[VB.NET]
For n = 1 To 10
MsgBox("The number is " & n)
Next
For Each prop In obj
prop = 42
Next prop
[J#.NET]
for(n=1; n<11;n++)
System.out.println("The number is " + n);
[C+ + .NET]
for(int n=1; n<11; n++)
printf("%d\n",n);
[C#.NET]
for (int i = 1; i <= 10; i++)
189
ASP.NET
[VB.NET]
While n < 100 ' Test at start of loop.
n += 1 ' Same as n = n + 1.
End While
[J#.NET]
while (n < 100)
n++;
[C+ + .NET]
while(int n < 100)
n++;
[C#.NET]
while (n < 100)
n++;
190
ASP.NET
][VB.NET
)Public Sub ABC(ByVal y As Long
...
End Sub
)ABC(x
))ABC((x
y . ABC y
x .
.
)( .
][J#.NET
.
][C+ + .NET
;)MyMethod(i,j
][C#.NET
)( .
:
)void ABC(int x
{
191
ASP.NET
...
}
:
)ABC(i
][VB.NET
)Public Sub ABC(ByRef y As Long
End Sub
)ABC(x
y ) ByRef ( . ABC y x
.
][J#.NET
][C+ + .NET
ABC .
)int ABC(long *py
)ABC(&VAR
ABC .
192
ASP.NET
[C#.NET]
: . C++ C#
void ABC(ref int x)
{
...
}
ABC(ref i);
[VB.NET]
Try
If x = 0 Then
Throw New Exception("x equals zero")
Else
Throw New Exception("x does not equal zero")
End If
Catch err As System.Exception
MsgBox("Error: " & Err.Description)
Finally
MsgBox("Executing finally block.")
End Try
193
[J#.NET]
try{
if (x == 0)
throw new Exception ("x equals zero");
else
throw new Exception ("x does not equal zero");
}
catch (Exception err){
if (err.getMessage() == "x equals zero")
System.out.println(err.getMessage());
//Handle Error Here
}
[C+ + .NET]
__try{
if (x == 0)
throw new Exception ("x equals zero");
else
throw new Exception ("x does not equal zero");
}
__catch(Exception e)
{
Console.WriteLine("Caught Exception");
}
__finally
{
194
ASP.NET
ASP.NET
[C#.NET]
// try-catch-finally
try
{
if (x == 0)
throw new System.Exception ("x equals zero");
else
throw new System.Exception ("x does not equal zero");
}
catch (System.Exception err)
{
System.Console.WriteLine(err.Message);
}
finally
{
System.Console.WriteLine("executing finally block");
}
[VB.NET]
o = Nothing
[J#.NET]
195
stringVar = null;
[C+ + .NET]
[C#.NET]
o = null;
196
ASP.NET
ASP.NET
ASP.NET Whidbey
ASP.NET Whidbey
Microsoft ASP.NET .
DELL Marrill Lynch NASDAQ JetBlue USAToday
.
ASP.NET 170
ASP.NET .
.
"ASP.NET "Whidbey
ASP.NET - Whidbey
ASP.NET .
.
Whidbey :
1 iranasp.net
197
ASP.NET
Whidbey
.
. Whidbey
ASP.NET . Whidbey .
)(username/ password
)(personalization
Master Pages
) (site navigation
(site
)counter
)(theme
ASP.NET Web Part )(portal
Whidbey 45 ) (server control .
treeview ... .
198
ASP.NET
Whidbey ) (administrators ASP.NET
.
ASP.NET . Whidbey API
Web.config
Machine.config . XML
) (configuration .
199
ASP.NET
Whidbey
- ) (pre-compile aspx.
aspx. ascx.
.
ASP.NET
Whidbey .
Whidbey 64
64 . 32
64 Whidbey JIT
64 .
Whidbey cache .
cache
output cache
ASP.NET.
200
ASP.NET
Whidbey -
ASP.NET .
. Whidbey .
http://www.asp.net/whidbey .
Visual Studio .NET Whidbey
http://www.asp.net/whidbey/whitepapers/VSWhidbeyOverview.aspx .
201
ASP.NET
Session ASP.NET .
ASP.NET Session ASP .
Web.Config .
Global.asax
Session .
Session
Session State > <SessionState Web.Config
. Web.Config
:
<sessionState
"mode="Off|InProc|StateServer|SqlServer
"stateConnectionString="tcpip=127.0.0.1:42424
"=sqlConnectionString="data source= 127.0.0.1;userid=sa;password
"cookieless="true|false
"timeout="20
>/
1
202
ASP.NET
mode
) (Session State .
) Off : ( ) Inproc ( -
)StateServer ( ) SqlServer (.
stateConnectionString .
mode SqlServer.
sqlConnectionString
.
mode SqlServer.
cookieless
Boolean
Session State ASP.NET
.
timeout
. 20
.
Session
Global.asax .
Session_Start Session_End .
. Session_Start
203
ASP.NET
Session_End .
Global.asax :
>"<script language="VB" runat="server
)Sub Session_Start(sender As Object, e As EventArgs
End Sub
)Sub Session_End(sender As Object, e As EventArgs
End Sub
></script
Session
Session Page HttpSessionState
System.Web.SessionState . Session
) (Collection . Session Page_Load
.
Session .
><%@ Page Language="VB" %
204
205
ASP.NET
ASP.NET
ASP.NET
.
. . .
. . .
.
:
- 1 : Nedstat Sitemitter . . .
- 2
Firewall
) ( .
.
.
1
206
ASP.NET
ASP.NET
.
.( String )
IP (
ClientName = Request.UserHostName
ClientIP = Request.UserHostAddress
.(
REFERER = Request.ServerVariables.Item("HTTP_REFERER")
(Client)(
LANGUAGE = Request.ServerVariables.Item("HTTP_ACCEPT_LANGUAGE")
AGENT = Request.ServerVariables.Item("HTTP_USER_AGENT")
Platform = Request.Browser.Platform()
QUERY STRING (
QUERY STRING = Request.ServerVariables.Item("QUERY_STRING")
Browser (
Browser = Request.Browser.Browser()
Browser_Type = Request.Browser.Type()
Browser_Version = Request.Browser.Version()
207
ASP.NET
(
Dim MyDateTime As New DateTime
)(MyDateTime = Now
)"Dim MyDate As String = MyDateTime.ToString("MM/dd/yyyy
)"Dim MyTime As String = MyDateTime.ToString("hh:mm:ss
Session_Start ) Global.asax (.
. . . .
208
ASP.NET
ASP.NET
.
ASP.NET string .
.
ASP.NET .
String
.
.
( )(mid
mid :
)Mid(A, B, C
=A
=B
1
209
ASP.NET
C=
(
: Substring
.Substring(A, B)
A=
B=
210
ASP.NET
String.Concat
.
Dim myString As String
Dim aString(10) As String
Dim t As Integer
For t = 0 To 9
aString(t) = CStr(t)
Next t
myString = String.Concat(aString) ' Returns "0123456789"
Response.Write(myString)
(
String.Join
.
Dim shoppingItem(2) As String
Dim shoppingList As String
shoppingItem(0) = "Milk"
shoppingItem(1) = "Eggs"
shoppingItem(2) = "Bread"
shoppingList = String.Join(",", shoppingItem) 'Returns "Milk,Eggs,Bread"
Response.Write(shoppingList)
211
ASP.NET
( )(Insert
Insert :
).Insert(A, B
=A
=B
(
String.Join " "
. :
"Dim shoppingList As String = "Milk,Eggs,Bread
Dim shoppingItem(2) As String
)shoppingItem = shoppingList.Split(","c
Dim s As String
For Each s In shoppingItem
212
ASP.NET
(Replace)(
Replace
:
Dim myString As String = "Shopping List"
Dim aString As String
aString = Replace(myString, "o", "i") ' Returns "Shipping List".
Response.Write(aString)
213
ASP.NET
Web.Config
Setup .
ASP.NET
XML Web.Config .
Setup
. Web
.
ASP.NET
... XML Web.Config
XML ) Tag ) HTML
(Case Sensitive).
.
Web .
.
1
214
ASP.NET
Web.Config
Web ASP.NET Web.Config
Visual Studio .NET Web
Application .
XML
.
Web.Config
. Web.Config
. Web.Config
Web .
main Sub1 Sub2
Web.Config Web.Config
Web.Config
Sub1 Sub2 Web.Config main
main .
Web.Config
.
215
ASP.NET
Web.Config
Web.Config ><configuration
><configuration/ .
Web.Config :
><configuration
><!--Some Configurations--
></configuration
Web.Config : .
><configsectons > <configsections/
.
Web.Config > <configuration > <configsections .
> <configsectons/ .
Web.Config
.
Location
Web.Config
Web.Config
216
ASP.NET
requestencoding ) .( Unicode
:responseencoding .
Web.Config
. > <authentication ><authentication/
><authorization
><authorization/ Web.Config
ASP. NET
.
217
ASP.NET
218
ASP.NET
:Off
:Inproc In-process .
:StateServer Out-Of-Process .
timeout
219
ASP.NET
> <compilation
:
:defaultlanguage )
(Dynamic .
220
ASP.NET
IrMail ) ASP.NET (
.
... .
IrMail ASP.NET
.
:1 " "IrMail (IrMail
) Component .
:2 IrMail ) NET 1.1. ( . .NET 1.0
.
.
) (web applications
.
:
1
221
ASP.NET
" "
Password
ASP.NET ASP
CDONTS ASP
ASP .
) (host .
.
NET Framework. . :
) (Dll Registry
222
ASP.NET
.NET .
ASP
.
.
.NET
ASP.NET
.
http://www.asp.net/ControlGallery/default.aspx?tabindex=2
.
.NET
.NET
.NET SmtpMail
wrapper ) Collaboration Data Objects for Windows 2000 (CDOSYS .
223
ASP.NET
. SMTP
)(Authentication SmtpMail .
charset HTML . SmtpMail
. CDOSYS
.
: NET Framework. .
.
.
www.iranasp.net/articles/showarticle.aspx@articleid=111.htm
1 .
.
IrMail
.
.
.
www.iranasp.net 1
224
ASP.NET
) .NET
(.
""
.
.
. :
) !(
.
.
.
.
225
ASP.NET
) (... .
.
!
.
.
.
) !( .
.
.
IrMail
.
) NET 1.1.). .NET )
( . .
226
ASP.NET
IrMail .
. .
IrMail .
227
ASP.NET
IrMail ) ASP.NET (
.
... .
IrMail ASP.NET
.
.
.
.
.
IrMail .
.
IrMail
Authentication
.NET ) Authentication(
. SMTP )(login
1
228
ASP.NET
Authenticate . IrMail .
username password Authentication .
.
UTF8AnyWhere UTF8
.
.
.
. Encoding
Encoding UTF8 .
Hotmail Yahoo
. True property
.
SMTP
SMTP Server
. . SMTP )
(
.
229
ASP.NET
.
.
" "
!
IrMail .
SMTP ( SMTP
( . SMTP
Server .
.
:
- 1 XML . .NET
Linux . XML
.
- 2
. SMTP Server
(Not thread-safe).
.NET )
Thread ASP.NET ( . DBMS
.
230
ASP.NET
IrMail
( Password Username
(... .
IrMail.Mail ) (Constructor
. )
VB.NET (.
Public Class MySmtpMail
Inherits IrMail.Mail
)(Public Sub New
) )""(MyBase.New(HttpContext.Current.Server.MapPath
IrMail.Mail
. .
) DB
fpdb (.
"Me.SMTPserver = "YourSMTPServer
"Me.PickUpDirectory = "c:\inetpub\mailroot\pickup
) (PickUpDirectory SMTP Server .
231
ASP.NET
"Me.UserName = "YourUsername
"Me.Password = "YourPassword
Authentication . Authentication
.
Me.UTF8AnyWhere = True
.
false . false.
)Me.LoadSharedObject4WebApplication(HttpContext.Current
.
.
End Sub
End Class
. :
)( Dim ObjMailer As New MySmtpMail
"ObjMailer.From = "[email protected]
"ObjMailer.To= "[email protected]
"ObjMailer.Subject = "New Email Object
232
ASP.NET
.
233
ASP.NET
.
opensource . .
.NET Exe Dll !
.
debugger .
http://www27 .brinkster.com/mahmoud690 /irmail :
Download :
http://www27.brinkster.com/mahmoud690/irmail/downloadAssembly.htm.htm
Download :
http://www27.brinkster.com/mahmoud690/irmail/Download-source.htm
ASP.NET:
http://www.asp .net/ControlGallery/ControlDetail.aspx?Control=1918&tabindex=2
234
ASP.NET
ASP.NET
ASP.NET
. Windows Authentication :
Forms-Based
1
235
ASP.NET
236
ASP.NET
237
ASP.NET
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="logon.aspx"
protection="All" path="/" timeout="30" />
</authentication>
: authorization - 4
<authorization>
<deny users ="?" />
<allow users = "*" />
</authorization>
)(
.
. Notepad - 1
: SQL - 2
if exists (select * from sysobjects where id =
object_id(N'[dbo].[Users]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Users]
GO
238
ASP.NET
ASP.NET
ASP.NET
241
ASP.NET
Imports System.Data.SqlClient
Imports System.Web.Security
ValidateUser - 3
. Connection String) .
.
.( Local SQL Server DOTNET
Function ValidateUser(uid As string, passwd As string) As Boolean
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim retVal As Boolean = False
cnn = New SqlConnection("Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=pubs;Workstation
ID=DOTNET;")
cmd = New SqlCommand("Select * from users where uname = '" & uid & "'", cnn)
cnn.Open()
dr = cmd.ExecuteReader()
While (dr.Read())
If Strcomp(dr.Item("Pwd"), passwd, 1) = 0 Then
retVal = True
End If
End While
cnn.Close()
ValidateUser = retVal
End Function
242
ASP.NET
- 4
. cmdLogin_ServerClick
:cmdLogin_ServerClick
RedirectFromLoginPage :
Private Sub cmdLogin_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles cmdLogin.ServerClick
If ValidateUser(txtUserName.Value,txtUserPass.value) Then
FormsAuthentication.RedirectFromLoginPage(txtUserName.Value, _
chkPersistCookie.Checked)
Else
lblMsg.Text = "Unknown User! try again."
End If
End Sub
.( authentication ticket) .
: .
Private Sub cmdLogin_ServerClick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles cmdLogin.ServerClick
If Validateuser(txtUserName.Value,txtUserPass.Value) Then
Dim tkt As FormsAuthenticationTicket
243
ASP.NET
244
ASP.NET
default.aspx
default.aspx .
.
logon.aspx .
- 1 default.aspx HTML .
> <Form :
>"<input type="submit" Value="SignOut" runat="server" id="cmdSignOut
) (log out default.aspx .
. .
- 2 code-behind default.aspx :
Imports System.Web.Security
- 3 cmdSignOut_ServerClick :
Private Sub cmdSignOut_ServerClick(ByVal sender As System.Object, ByVal e As
_ )System.EventArgs
Handles cmdSignOut.ServerClick
)(FormsAuthentication.SignOut
)Response.Redirect("logon.aspx", True
End Sub
245
ASP.NET
- 4 . .
.
. HashPasswordForStoringInConfigFile
FormsAuthentication .
.
SQL Connection ) (Web.config
.
.
!
Secure Socket Layer
SSL .
246
ASP.NET
.
< authentication> timeout
.
: ASP.NET
http://www.gotdot.NETcom/QuickStart/aspplus/default.aspx?url=/quickstart/aspplu
s/doc/formsauth.aspx
http://msdn.microsoft.com/library/enus/cpguidnf/html/cpconcookieauthenticationusinganxmlusersfile.asp
http://msdn.microsoft.com/library/default.asp?url=/library/enus/cpguide/html/cpconaspnetwebapplicationsecurity.asp
http://msdn.microsoft.com/library/dotnet/cpref/frlrfsystemwebsecurity.htm
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaspnetconfiguration.asp
http://msdn.microsoft.com/library/default.asp?url=/library/enus/cpguide/html/cpgrfaspnetconfigurationsections.asp
http://msdn.microsoft.com/library/en-us/dnbda/html/authaspdot.NETasp
247
ASP.NET
ASP.NET
.
... .
.
.
.
www.iranasp.net/download/ webtech047.zip :
iranasp .
1620 !
162 ) (
!! iranasp
1620
.
.
1
248
ASP.NET
.
.
! .
" " ! !
Page Navigation . Navigation
.
.
O .
)!( .
.
249
ASP.NET
9 Next Prev
.
.
Next Prev .
IranASP.NET .
ASP.NET DataGrid
:
( DataGrid
.
( DataGrid
DataGrid
.
.
Cache .
250
ASP.NET
ASP.NET Repeater
.
. .
. Repeater
DataGrid DataList .
ASP.NET
.
...
!
User Control
. HTML :
ASP.NET
></TR
></TABLE
></P
Label
. codebehind .
.
.
: CurrentPage .
.
: PageSize .
.
: TotalRecords .
.
: InitNav
.
:ShowNav .
:CssClass CSS .
252
ASP.NET
: InActiveCssClass CSS
) "" (.
User Control . Visual Studio .NET
Solution Explorer drag-and-drop
. :
"<%@ Register TagPrefix="uc1" TagName="PageNavigation
>Src="PageNavigation.ascx" %
...
><uc1:PageNavigation id="pnPageNavigate" runat="server"></uc1:PageNavigation
10 "" "" .
.
253
ASP.NET
PageNavigation
.
:
;protected YourNamespace.PageNavigation pnPageNavigate
.
.
;)( this.pnPageNavigate.InitNav
DataSet ds = GetPagedAllNews (this.pnPageNavigate.CurrentPage ,
this.pnPageNavigate.PageSize,
;)out this.pnPageNavigate.TotalRecords
;this.repNews.DataSource = ds
;)(this.repNews.DataBind
;)(this.pnPageNavigate.ShowNav
InitNav ShowNav .
CurrentPage PageSize TotalRecords .
.
GetPagedAllNews . :
private DataSet GetPagedAllNews (int CurrentPage, int PageSize, out int
)TotalRecords
{
;)( DataSet ds = new DataSet
254
ASP.NET
procGetPagedAllNews
.
News SQL Server .
:
255
ASP.NET
NewsID int
NewsTitle nvarchar (256)
:
CREATE PROCEDURE dbo.procGetPagedAllNews
(
@CurrentPage int,
@PageSize int,
@TotalRecords int output
)
AS
SET NOCOUNT ON
--Create a temp table to hold the current page of data
--Add an ID column to count the records
CREATE TABLE #TempTable
(
ID int IDENTITY PRIMARY KEY,
NewsID int,
NewsTitle nvarchar (256),
)
--Fill the temp table with the News data
INSERT INTO #TempTable
(
256
ASP.NET
NewsID,
NewsTitle,
)
SELECT NewsID, NewsTitle
FROM News
--Create variable to identify the first and last record that should be selected
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
SELECT @LastRec = (@CurrentPage * @PageSize + 1)
--Select one page of data based on the record numbers above
SELECT *
FROM
#TempTable
WHERE
ID > @FirstRec
AND
ID < @LastRec
--Return the total number of records available as an output parameter
SELECT @TotalRecords = COUNT(*) FROM #TempTable
ConnectionString
.
257
ASP.NET
XML ) ASP.NET (
CNN news.com
asp aspx phphtml
.
:
XML .
JSP PHP ASP.NET ColdFusion
ASP.NET .
XML XSL
.
) (
Template ASP ASP.NET .
1
258
ASP.NET
CNN news.com
< >
html asp aspx php jsp
ASP.NET PHP
.
.
.
)
( .
ASP.NET ASP
. ) (Render
.
259
ASP.NET
) ) id
Template SQL .
URL article.aspx?id=102632 :
id 102632 ASP.NET
:
SELECT * FROM Articles WHERE ID=@id
:
><#% DataBinder.Eval( Container, DataItem.ArticleTitle ) %
Template .
) (102632
.
102632.htm .
server .
260
ASP.NET
article.aspx?id=102632
- 1 .
ASP.NET PHP HTML
.
.
Shared Hosting
.
Load -2 .
.
!
) (resources
. .
.
261
ASP.NET
- 3 .
.
down
exception .
.
- 4 .
.
.
5
URL
article.aspx?id=102632&cat=214&sessionid=423442 )
( .
102632.htm
.
- 6 .
262
ASP.NET
. ) SQL
Server MySQL ORACLE DBMS ( .
x
)
( .
Host
!
- 7 Host .
HTML
web server .
.
upload .
) (
.
263
ASP.NET
XML ) ASP.NET (
CNN news.com
asp aspx phphtml
.
www.iranasp .net/download/behrooznp002.zip :
XML ASP.NET
.
XML
.
ASP ASP.NET Template XSL
.
Template XHTML .
XHTML XSL .
HTMLXHTML
1
264
ASP.NET
XHTML .
) ( HTML XHTML
XHTML . Dreamweaver
!
HTML HTML XHTML .
tag XML well-form
. XML tag . > <table></table
tag )> ( <br tag > </br .
XHTML .
XML .
XML . ;  
space XML space
. .
XHTML XML .
: utf-8 .
xml .
XHTMLXSL
265
ASP.NET
Template . XSL
. XSL
.
XSL
. XSL eXtensible Stylesheet Language . XSL
XML CSS HTML . CSS XSL
. CSS
XSL XML .
XSL XML XSLT
) XSL Transformation (.
:
266
ASP.NET
>"<xsl:for-each select="//Table
...
></xsl:for-each
Table .
xml
XML xslt XSL
HTML .!
ASP.NET
ASP.NET
publish .
ASP.NET HTML save
. ASP.NET
upload.
:
) VB.NET C# (
- 1 import:
267
ASP.NET
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.IO.Path
Imports System.Xml
Imports System.Xml.Xsl
datagrid - 2
. ASP.NET
ASP.NET
datagrid . datagrid
. ) ( select
.
J - 3
Function GenerateOneHTML(ByVal RecordID As Integer) As Boolean
'single node----------------------Dim myData As DataSet = GetDataSet()
Dim doc As XmlDataDocument = New XmlDataDocument(myData)
Dim FileName As String
Dim ln As Integer
Dim node As XmlElement = doc.DocumentElement.SelectSingleNode("//Table[ID="
+ RecordID.ToString + "]")
268
ASP.NET
269
ASP.NET
.
.
:
- 1 xml dataset
- 2
- 3)(Tarnsform
XSLT .
XSLT !
:
dataset xml:
'single node----------------------)(Dim myData As DataSet = GetDataSet
)Dim doc As XmlDataDocument = New XmlDataDocument(myData
Dim FileName As String
Dim ln As Integer
Dim node As XmlElement = doc.DocumentElement.SelectSingleNode("//Table[ID=" +
)"]" RecordID.ToString +
270
ASP.NET
dataset GetDataSet
. ADO.NET
) DataReader
(DataSet .
XmlDataDocument dataset XML .
XmlElement .
id input .
:
xml node.OuterXml XmlDocument
dataset ) if
(:
Dim doc2 As XmlDocument = New XmlDocument
)doc2.LoadXml(node.OuterXml
'Generate HTML file name
FileName = RecordID.ToString
Dim HTMLsPath As String = Server.MapPath("\") + "Articles\" +
"\" Trim(doc2.SelectSingleNode("//Category").InnerText) +
271
ASP.NET
XmlDocument xml .
) xml ( .
System.xml System.xml.xsl .
RecordID path
HTML .
XSL .
syntax ) (:
doc2.SelectSingleNode("//FieldName").InnerText
:
!
XslTransform .
overload . .
)!( . XSL
temp.html ) (path
. load .
XmlTextWriter ) (stream Transform :
'Transform
Dim xslt As XslTransform = New XslTransform
)"xslt.Load(HTMLsPath + "temp.html
272
ASP.NET
ASP.NET
Indentation . 2 .
nesting HTML .
Transform . .
!
XmlTextWriter .
) .( id
datagrid checkbox
. id
. overwrite
. update.
Layout XSL .
. XSL htm html Dreamweaver
. XSL Transformation
.
:
. .
274
ASP.NET
:
1 .
.
www.behrooznp.com/default.htm 1
275
ASP.NET
Report
Visual
Studio .NET Setup .
Crystal Report .NET
. .
.NET Visual Studio.NET
. Setup
.NET Framework .
Crystal Report
Setup .
Setup :
Setup .
Setup Solution Explorer Add
Merge Module :
1
276
ASP.NET
Crystal_Database_Access2003.msm
Crystal_Database_Access2003_enu.msm
Crystal_regwiz2003.msm
Properties Crystal_regwiz2003.msm Solution Explorer
.
License Key MergeModuleProperties Properties
.
:
Visual Studio .NET Help About Licence Key
Crystal Reports for Visual Studio .NET
.
277
ASP.NET
.NET
.NET
.
.
Microsoft .NET
. .
. .NET .NET
C# VB.NET
) VB Syntax
(.
.
VB.Net C# Windows Application :
-
VB MyvbProj .NET .
C# MycsProj .
1
278
ASP.NET
Referencese Myvbproj
Referencese Add .
VB C# Button
VB C# :
279
ASP.NET
Principle Generic
FormsAuthentication
.
ASP.NET .
FormsAuthentication .
WebApplication . Logon ! :
Web.Config -1 FormsAuthentication .
-2 Ticket
-3 GenericPrincipalFormsIdentity
-4
-1 Web.Config > <authentication :
><"authentication mode="Form
"<forms name="TestCookie " loginUrl= "login.aspx" protection="All" timeout="30
1
280
ASP.NET
>path="/"></forms
></authentication
> <authorization > <authentication .
><authorization
><deny users="?" /
><allow users="*" /
></authorization
-2 Ticket
Ticket FormsAuthentication
.
) ( . .
Web.Config . Function :
Function IsAuthenticated(ByVal uid As String,ByVal pwd As String)As Boolean
...
Return true
End Function
. Function . :
281
ASP.NET
282
ASP.NET
ASP.NET
FormsIdentity
: Identity GenericPrincipal
' Create an Identity object
Dim id As New FormsIdentity(authTicket)
' This principal will flow throughout the request.
Dim principal As New GenericPrincipal(id, roles)
' Attach the new principal object to the current HttpContext object
Context.User = principal
: Test.aspx -5
Imports System.Security.Principal
: Load
Dim p As IPrincipal = HttpContext.Current.User
Response.Write("Authenticated Identity is: " + p.Identity.Name)
Response.Write("<p>")
If p.IsInRole("admin") Then
Response.Write("RoleName is: Admin")
End If
ASP.NET
ASP.NET
.
) Static ) Dynamic
.
HTML .
Static Dynamic HTML Client
. Dynamic Server
.
ASP.NET . IIS
ASP.NET HTML
1
285
ASP.NET
Client .
HTML HTML Client.
. )
).1 ASP .JET Client
HTTP 1.1
.
.
HTTP 1.0
) 7 30(.
HTML Editor
.
.
Visual Basic.NET HTML Client
Client HTTP 1.0
.
www.softtool.info/aspjet/fa/default.htm 1
286
ASP.NET
.
HTTP 1.0 .
Tag
Tag
.
:
HttpResponse.Filter .
WhitespaceFilter
WhitespaceFilter.vb
Application_BeginRequest Global.asax :
Sub Application_BeginRequest(ByVal sender As Object,
)ByVal e As EventArgs
' Fires at the beginning of each request
Response.Filter = New
)WhitespaceFilter(Response.Filter
End Sub
287
ASP.NET
Load Global.asax
:
Sub Application_BeginRequest(ByVal sender As Object,
)ByVal e As EventArgs
' Fires upon attempting to authenticate the use
If
= )"Request.Url.PathAndQuery.ToLower.IndexOf("makethumbnail
-1 Then
Response.Filter = New
)WhitespaceFilter(Response.Filter
End If
End Sub
HTML
Editor NotePad
.
.
.
:WhitespaceFilter
288
ASP.NET
: Class
Imports System.IO
Imports System.Text.RegularExpressions
:
' This filter gets rid of all unnecessary whitespace in
the output.
289
ASP.NET
.
#Region " Code that will most likely never change from
filter to filter. "
. Stream
' The following members of Stream must be
overridden.
Public Overrides ReadOnly Property CanRead() As
Boolean
Get
Return True
End Get
End Property
ASP.NET
End Property
ASP.NET
End Get
Set(ByVal Value As Long)
_position = Value
End Set
End Property
ASP.NET
#End Region
. Write
' Write is the method that actually does the
filtering.
293
ASP.NET
294
ASP.NET
") = -1
.
295
ASP.NET
.
.
.
' Eliminate known comments.
These
ASP.NET
ASP.NET
s = s.Replace("style=""display:inline""> ",
"style=""display:inline"">")
s = s.Replace(" <H", "<H").Replace(" <h",
"<h").Replace(" </H", "</H").Replace(" </h", "</h")
s = s.Replace("<UL> ", "<UL>").Replace("<ul> ",
"<ul>")
s = s.Replace(" <TABLE", "<TABLE").Replace("
<table", "<table")
s = s.Replace(" <li>", "<li>").Replace(" <LI>",
"<LI>")
s = s.Replace(" <br>", "<br>").Replace(" <BR>",
"<BR>").Replace("<br> ", "<br>").Replace("<BR> ", "<BR>")
s = s.Replace(" <ul>", "<ul>").Replace(" <UL>",
"<UL>")
: Tag
' Replace long tags with short ones
s = s.Replace("<STRONG>",
"<B>").Replace("<strong>", "<b>")
s = s.Replace("</STRONG>",
"</B>").Replace("</strong>", "</b>")
: HTML
298
ASP.NET
299
ASP.NET
") = -1
:
' Finally, we spit out what we have done.
Dim outdata() As Byte =
System.Text.Encoding.UTF8.GetBytes(s)
_sink.Write(outdata, 0, outdata.GetLength(0))
300
ASP.NET
End Class
http://www.codeproject.com/aspnet/ WhitespaceFilter.asp:
301
ASP.NET
RSS
. RSS RSS
XML Really Simple Syndication
.
. ASP.NET RSS
RSS
. XML RSS
. RSS
<rss version="2.0">
<channel xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>IranASP.NET New Articles RSS Feed</title>
<language>fa-IR</language>
<copyright>(c) 2004 by IranASP.NET</copyright>
<pubDate>Sun, 08 Aug 2004 06:11:37 GMT</pubDate>
<lastBuildDate>Sun, 08 Aug 2004 06:11:37 GMT</lastBuildDate>
<generator>IranASP.NET rss generator</generator>
<item>
ASP.NET</title>
<title>
1
302
ASP.NET
><link>http://www.iranasp.net/articles/showarticle.aspx?articleid=154</link
><pubDate>Sun, 25 Jul 2004 19:30:00 GMT</pubDate
></item
></channel
></rss
> : <rss RSS . RSS
2 .
> :<channel RSS > <channel .
> <tile>,<link > <item.
>: <title RSS .
> :<link URL RSS .
>: <description .
> :<copyright .
>: <generator Application .
RSS > <item . > <item
.
><item .
303
ASP.NET
>:<title .
>:<link URL .
>:<description .
>:<pubDate .
Sun, 25 Jul 2004 12:00:00 GMT .
RSS
RSS . RSS
XML . RSS XML
Text writer . .
.
VS.NET . > <item XML
. ) (properties )(methods
:
)(properties
:Outputstream ) ( Stream .
304
ASP.NET
ASP.NET
properties RSS
. ( Public )
Public Class Rss
Public OutputStream As Stream
Public RssTitle As String
Public PublisherUrl As String
Public Description As String
Public Copyright As String
Public Generator As String
Public ItemSource As DataSet
Public ItemTitleField As String
Public ItemUrlField As String
Public ItemDescriptionField As String
Public ItemPublicationDateField As String
Public Shared Function PublishRss(ByVal r As Rss)
Dim writer As New XmlTextWriter(r.OutputStream,
System.Text.Encoding.ASCII)
writer.WriteStartElement("rss")
writer.WriteAttributeString("version", "2.0")
writer.WriteStartElement("channel")
writer.WriteElementString("title", r.RssTitle)
writer.WriteElementString("link", r.PublisherUrl)
writer.WriteElementString("description", r.Description)
writer.WriteElementString("copyright", r.Copyright)
writer.WriteElementString("generator", r.Generator
306
ASP.NET
ASP.NET
:WriteAttributeString .
:WriteElementString .
:WriteEndElement .
.
:Flush .
WriteStartElement WriteEndElement
.
ASP.NET
.
.
RSS .
)Article_ title - Varchar (255
)Article_ Description -Varchar (1000
)Article_ url - Varchar (255
Article_ pubdate - DateTime
GetDataSet
RSS . DataAdapter :
308
ASP.NET
ASP.NET
r.ItemDescriptionField = "Article_Description"
r.ItemPublicationDateField = "Article_pubdate"
r.ItemUrlField = "Article_url"
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.ContentType = "text/xml"
Rss.PublishRss(r)
Response.End()
End Sub
. Rss PublishRss
. RSS XML !
http://www.dotnetbips.com:
310
ASP.NET
. ASP.NET
. .NET
.
ASP.NET 1,0 1,1 2002 2003
.NET ASP.NET .
Visual Studio .NET Whidbey 2004 .
1
311
ASP.NET
. :
) ( !!!
!!
.
MSDN
.
ASP.NET 2.0
ASP.NET 2.0 :
- 1 Web
Microsoft Information Services (IIS) 5.0
. ASP.NET 2.0 IIS 6.0
.
.
. .
.
312
ASP.NET
- 2
ASP.NET 2.0 Wizard
) (
- 3 Web
ASP.NET 2.0 Account
. .
Login Account Login
.
- 4
ASP.NET 2.0 Master PageTheme Skin
.
.
ASP.NET 1.x
ASP.NET 1.x ASP.NET
2.0 ASP.NET 1.x . ASP.NET
313
ASP.NET
314
ASP.NET
Provider
ASP.NET . Provider
:
:Membership .
:Profile Profile .
:Personalization Provider
.
:Site Navigation Provider ASP.NET
.
:Data Provider ADO.NET Provider Database
) ( API . ASP.NET 2.0
.NET ADO.NET .
Provider Provider
Profile Profile Membership .
ASP.NET 2.0 .
ASP.NET 2.0
315
ASP.NET
316
ASP.NET
> <Script
. .
Code Behind
ASPX
Check Box .
317
ASP.NET
318
ASP.NET
ASP.NET
}
}
ASPX :
{ namespace ASP
public partial class Webform1_aspx
{
)void Page_Load(object sender, EventArgs e
{
;"Label1.Text = "Hello ASP.NET 2.0
}
}
}
Code Behind . Code Behind
ASP.NET .
/Code directory
ASP.NET .
Web .
Reference Web.
320
ASP.NET
321
ASP.NET
Intellisense XML
. Web.Config Intellisense
Visual Studio .
Intellisense .
ASP.NET 2.0 Administrative Web site
.
Administrative Web site
ASP.NET 2.0
Local host
Administrator
Profile .
Trace .
322
ASP.NET
ASP.NET 2.0 ) (MMC IIS
.NET Framework .
ASP.NET
API
API . System.Configuration.Configuration
. XML
Local Authentication .
: Machine
[C#]
Configuration cfg = Configuration.GetConfigurationForUrl("/Application_name");
Response.Write( cfg.Web.Authentication.Mode.ToString() );
[VB.NET]
Dim cfg As Configuration =
Configuration.GetConfigurationForUrl("/Application_name")
Response.Write( cfg.Web.Authentication.Mode.ToString() )
: authentication Forms-Based
[C#]
Configuration cfg = Configuration.GetConfigurationForUrl("/MyApp");
cfg.Web.Authentication.Mode = HttpAuthenticationMode.Forms;
cfg.Update();
[VB.NET]
Dim cfg As Configuration = & _
324
ASP.NET
)"Configuration.GetConfigurationForUrl("/MyApp
)(cfg.Web.Authentication.Mode = HttpAuthenticationMode.Forms cfg.Update
.
Development
ASP.NET 2.0 Visual Studio 2005
.
ASP.NET 1.x .
Server
ASP.NET 1.x Visual Studio .NET IIS
Microsoft FrontPage Server Extensions .
IIS
:
The Development Server
Visual Studio .NET 2005 Server Web
Server . .
Server
325
ASP.NET
.
IIS .
The Production Server
IIS .
Visual Studio .NET Connection .
326
ASP.NET
ASP.NET 1.x
. ASP.NET 1.x Batch Start Up
. . Server
.
ASP.NET 2.0 Pre-Compile
) (deployment
.
Pre-Compile ASP.NET.
327
ASP.NET
Navigation
ASP.NET 1.x
HyperLink
.
. ASP.NET 1.x
HTML . ASP.NET 2.0
Navigation
.
ASP.NET 2.0 (Logical
)Structure . Navigation
1
328
ASP.NET
Navigation
.
. Navigation
Menu Tree View ... .
Web.SiteMap
SiteMap ASP.NET 2.0 .
XML Navigation ASP.NET 2.0
.
Navigation . (Logical
)Structure :
- 1 XML Web.SiteMap
. Visual Studio.NET 2005
Site. Add New Item SiteMap
Intellisense .
>? "<?xml version="1.0" encoding="utf-8
><siteMap
>"<siteMapNode title="Home" url="default.aspx
><siteMapNode title="Article 1" url="~/articles/demoarticle1.aspx" /
><siteMapNode title="Article 2" url="~/articles/demoarticle2.aspx" /
><siteMapNode title="Article 3" url="~/articles/demoarticle3.aspx" /
329
ASP.NET
</siteMapNode>
<siteMapNode title="Picture Gallery" url="~/PhotoAlbum/PhotoAlbums.aspx">
<siteMapNode title=
"Meetings"url="~/PhotoAlbum/PictureAlbum.aspx?albumid=1"/>
<siteMapNodetitle="Activities"url="~/PhotoAlbum/PictureAlbum.aspx?albumid=2
"/>
<siteMapNode title=
"Training"url="~/PhotoAlbum/PictureAlbum.aspx?albumid=3"/>
</siteMapNode>
</siteMap>
(Drap & Drown ToolBox SiteMap DataSource - 2
Web.SiteMap .(
Tree SiteMap DataSource
. Menu View
<%@ page language="VB" master="~/Mysite.master" %>
<asp:content id="Content1" contentplaceholderid="LeftSideContent">
<H2>Navigation </h2>
<asp:treeview id="Navigation tree" runat="server" datasourceid="NavSource"/>
</asp:content>
Navigation
Navigation Navigation ASP.NET 2.0
< asp:TreeView> < asp:Menu> .
330
ASP.NET
URL
ASP.NET 2.0 Navigation URL .
URL ) URL MSDN !!( . URL
ASP ISAPI Handler
. ASP.NET 2.0 URL Mapping Web.Config
URL URL
.
>"<urlMappings enabled="true
><add url= "~/Home.aspx"mappedUrl="~/Default.aspx?tabid=0" /
></urlMappings
Home.aspx )
(Redirect Default.aspx?tabid=0
331
ASP.NET
332
ASP.NET
: SiteMapDataSource Navigation
.
ASP.NET 2.0 . GridView
DataGrid
.
333
ASP.NET
DetailView
.
Web Mobile
ASP.NET Microsoft Mobile
Internet Toolkit MMIT . ASP.NET 2.0
MMIT . ASP.NET 2.0
Mobile .
.
ASP.NET 2.0
334
ASP.NET
ASP.NET 2.0 .
Master Pages
.
.
Master Pages .
. Visual Inheritance
Microsoft Windows.
Master Page ASP.NET )
.master ( .aspx . Master Pages
> <asp:ContentPlaceHolder .
. ContenetPlaceHolder .
Visual Studio 2005
HTML . Master Page :
"<%@ master language="C#" compilewith="site.master.cs
>classname="ASP.site_master" %
><html
><head runat="server"><title>Untitled Page</title></head
335
ASP.NET
><body
>"<form runat="server
>"<asp:contentplaceholder id="ContentPlaceHolder1" runat="server
></asp:contentplaceholder
></form
></body
></html
Master Page
ASP.NET .
Master Page Frame Master Page
. Frame Master Page .
- 1 .
Master Page Frame
.
- 2 HTML
Frame . Visual Studio .
- 3 Master Pages.
HTML .
Master Page
.
336
ASP.NET
)(Content Pages
Master Page ContentPlaceHolder
Master Page . > <asp:content
><asp:contentPlaceHolder Master Page ContentPlaceHolder ID .
Master Page .
><%@ page language="VB" master="~/Mysite.master" %
>"<asp:content id="Content1" contentplaceholderid="LeftSideContent
><H2>Navigation </h2
><asp:treeview id="Navigation tree" runat="server" datasourceid="NavSource"/
></asp:content
>"<asp:content id="Content1" contentplaceholderid="RightSideContent
><asp:label runat="server">Support section</asp:label
></asp:content
: ASP.NET
Master Page .
Master Page
Master Page .
IT .
337
ASP.NET
Master Page
Master Page
.
.
Master Page ) (Public
Master Page .
338
ASP.NET
SkinsThemes
CSS
. . CSS
. ASP.NET 2.0
Themes
CSS Style Theme
: Style Sheet Theme
339
ASP.NET
Theme -1 Style
.
Theme -2 CSS Style .
Theme -3 Style Sheet .
Theme -4 Refrence Style Sheet .
Themes . Theme
Skin .
Theme
Theme Skin Themes
. Theme . skins.
Theme Style Sheet .
340
ASP.NET
Skin. Skin
. Pink Themes . ASPX
: Pink Theme skin.
<asp:DropDownList runat="server" BackColor="hotpink" ForeColor="white" />
<asp:DataGrid runat="server" BackColor="#CCCCCC" BorderWidth="2pt"
BorderStyle="Solid" BorderColor="#CCCCCC" GridLines="Vertical"
HorizontalAlign="Left">
<HeaderStyle ForeColor="white" BackColor="hotpink" />
<ItemStyle ForeColor="black" BackColor="white" />
<AlternatingItemStyle BackColor="pink" ForeColor="black" />
</asp:DataGrid>
. Theme
. Data Grid
Theme
: Theme
<% "page language="VB" theme="Pink @%> - 1
</"pages theme="Pink> Web.config - 2
341
ASP.NET
Web.Config . Theme
.
342
ASP.NET
Skins
Skin
. Skin
. Skin
SkinID .
>!><!- Default Skin --
=<asp: label runat="server" Font-names="verdana, arial" font-size="10pt" ForeColor
>"#000066" BackColor="transparent"/
>!><!- Title Skin --
<asp: label runat="server" id="foo" skinid="Title" Font-names="verdana, arial" font
size="18pt" ForeColor= "#000066" BackColor="transparent" font-bold="true" font>underline="true"/
Skin SkinID
.
Skin
Skin Theme Skin
. SkinID Skin
Skin SkinID .
.
343
ASP.NET
)(User Membership
ASP .
. Login
.
. .
Microsoft Access Microsoft SQL Server .
Web.Config .
Login ASP.NET 2.0 .
Login
ASP.NET 2.0 Login
.
><asp:CreateUserWizard
.
. Label Value Error message validation
344
ASP.NET
. LoginName LoginStatus
.
LoginView
) ( . .
ASP
.
Profile
Profile ASP.NET 2.0
. ASP
session
. Profile Profile ASPX .
Profile
Wen.Config Machine.Config > <property
Profile ... .
><profile
>"<group name="BillingAddress
><add name="Street" type="System.String" /
345
ASP.NET
Profile
Profile Visual Studio 2005
Profile .
ASP.NET
ASP.NET
: ASP.NET
ASP.NET .
. .
ASP.NET! .
. ASP.NET
.
ASP.NET .
.
.
ASP.NET
.
ASP.NET .
ASP.NET .
1
347
ASP.NET
. .
.
.
.
. .
ASP.NET ADO.NET
XML
. .
.
.
. .
.
1 W3Schools 2 QuickStart
. / ASP.NET
.
www.w3schools.com/aspnet/default.asp 1
samples.gotdotnet.com/quickstart/default.htm 2
348
ASP.NET
.
.
.
.
.
. IranASP.NET
.
. !
.
.
.
.
.
. .
349
ASP.NET
.
ASP.NET !
.
!
.
.
Reading .
.
.
. .
.
.
.
.
.
350
ASP.NET
.
.
.
. .
ASP.NET ADO.NET
. .
ASP.NET
. ASP.NET
. .
ASP.NET .
. .
ASP.NET
ASP.NET
. .
. ASP.NET
:
.
. .
. . .
.
.
.
! .
.
352
ASP.NET
. .
: . . .
ASP.NET .
353
ASP.NET
- ASP.NET
ASP.NET ASP.NET
Client .
Event Log .
)(Customize
)(Event Log
ASP.NET Client .
:
1
354
ASP.NET
(Run-time errors):
.
) ( .
ASP.NET .
. :
><%@ Page Debug="true" %
Web.config
.
><configuration
><system.web
><compilation debug="true"/
></system.web
></configuration
: .
.
.
)(Development ASP.NET
355
ASP.NET
.
client )(Local
ASP.NET (client ( . client
.
Web.config :
><configuration
><system.web
><customErrors defaultRedirect="genericerror.htm" mode="RemoteOnly" /
></system.web
></configuration
client ASP.NET
client )(Remote genericerror.htm .
.aspx .ASP.NET
QueryString .
client )(Remote .
><%@ Page Language="C#" Description="Error page"%
><html
><head
><title>Error page</title
></head
356
ASP.NET
><body
><h1>Error page</h1
>Error originated on: <%=Request.QueryString["ErrorPage"] %
></body
></html
: aspnet_isapi.dll IIS .
aspnet_isapi.dll ASP.NET IIS .
)(Configuration IIS IIS .
attribute > <customErrors .
Attribute
mode
)(Remote .
) RemoteOnlyOff On : (.
defaultRedirect
. .
357
ASP.NET
Mode
On
ASP.NET .
ASP.NET .
Off
ASP.NET .
RemoteOnly
.< customErrors>
[Web.config]
<configuration>
<system.web>
<customErrors defaultRedirect="genericerror.htm" mode="On"/>
</system.web>
</configuration>
[Genericeroor.htm'
<html>
<head>
<title>An Error Has Occured</title>
</head>
<body bgcolor="beige">
358
ASP.NET
<font face="verdana">
<h4>We're Sorry...</h4>
An error has occured on the page you were requesting. If this problem persists,
please contact the site administrator.
<p>
<hr>
</font>
</body>
</html>
[Custom1.aspx]
<html>
<script language="C#" runat="server">
void Error_500(Object sender, EventArgs e) {
String foo = null;
Response.Write(foo.ToString());
}
</script>
<body>
<form runat="server">
<h4><font face="verdana">Cause an Error to Occur...</font></h4>
<asp:button text="500 Server Error" OnClick="Error_500" width="150"
359
ASP.NET
runat="server"/><p>
</form>
</body>
</html>
HTTP < error> < customErrors> .
: .
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="/genericerror.htm">
<error statusCode="500" redirect="/error/callsupport.htm"/>
<error statusCode="404" redirect="/error/notfound.aspx"/>
<error statusCode="403" redirect="/error/noaccess.aspx"/>
</customErrors>
</system.web>
</configuration>
.< error> attribute
Attribute
:. HTTP StatusCode
ASP.NET
. client Redirect
aspx .< error>
QueryString " File Not Found"
.
[Custom2.aspx]
<html>
<script language="C#" runat="server">
void Error_404(Object sender, EventArgs e) {
Response.Redirect("nowhere.aspx");
}
void Error_500(Object sender, EventArgs e) {
String foo = null;
Response.Write(foo.ToString());
}
</script>
<body>
<form runat="server">
<h4><font face="verdana">Cause an Error to Occur...</font></h4>
<asp:button text="404 Not Found" OnClick="Error_404" width="150"
361
ASP.NET
runat="server"/><p>
<asp:button text="500 Server Error" OnClick="Error_500" width="150"
runat="server"/><p>
</form>
</body>
</html>
[Notfound.aspx]
<%@ Page Language="C#" %>
<html>
<head>
<title>An Error Has Occured</title>
</head>
<body bgcolor="ccffcc">
<font face="verdana">
<h4>We could not locate the page you requested...</h4>
<% if ( Request.QueryString["aspxerrorpath"] != null ) { %>
<%=HttpUtility.HtmlEncode(Request.QueryString["aspxerrorpath"])%>
<% } %>
<p>
Perhaps you mis-typed the URL? Please try again, or visit our search page for help.
<p>
<hr>
</font>
362
ASP.NET
</body>
</html>
[Web.config]
<configuration>
<system.web>
<customErrors defaultRedirect="genericerror.htm" mode="On">
<error statusCode="404" redirect="notfound.aspx"/>
</customErrors>
</system.web>
</configuration>
363
ASP.NET
- ASP.NET
ASP.NET ASP.NET
Client .
Event Log .
. Page
Page_Error override .
.
>"<script language="C#" runat="server
{ )void Page_Error(Object source, EventArgs e
">String message = "<font face=verdana color=red
">+ "<h4>" + Request.Url.ToString() + "</h4
">'+ "<pre><font color='red
">+ Server.GetLastError().ToString() + "</pre
;">+ "</font
;)Response.Write(message
1
364
ASP.NET
}
</script>
. Page_Error
[error2.aspx]
<html>
<script language="C#" runat="server">
void Error_500(Object sender, EventArgs e) {
String foo = null;
Response.Write(foo.ToString());
}
void Page_Error(Object sender, EventArgs e) {
String message = "<font face=verdana color=red>"
+ "<h4>" + Request.Url.ToString() + "</h4>"
+ "<pre><font color='red'>" + Server.GetLastError().ToString() + "</pre>"
+ "</font>";
Response.Write(message);
Server.ClearError();
}
</script>
365
ASP.NET
<body>
<form runat="server">
<h4><font face="verdana">Cause an Error to Occur...</font></h4>
<asp:button text="500 Server Error" OnClick="Error_500" width="150"
runat="server"/><p>
</form>
</body>
</html>
. System.Web.Mail .ASP.NET
:@ Import
<%@ Import Namespace="System.Web.Mail" %>
. SmtpMail MailMessage
MailMessage mail = new MailMessage();
mail.From = "[email protected]";
mail.To = "[email protected]";
mail.Subject = "Site Error";
mail.Body = message;
mail.BodyFormat = MailFormat.Html;
SmtpMail.Send(mail);
366
ASP.NET
.
Mail SMTP :
. IIS Mail SMTP .
[error3.aspx]
<%@ Import Namespace="System.Web.Mail" %>
<html>
<script language="VB" runat="server">
Sub Error_500(sender As Object, e As EventArgs)
Dim foo As String = Nothing
Response.Write(foo.ToString())
End Sub
Sub Page_Error(Sender As Object, E As EventArgs)
Dim message As String = "<font face=verdana color=red>" _
& "<h4>" & Request.Url.ToString() & "</h4>" _
& "<pre><font color=red>" & Server.GetLastError().ToString() & "</pre>" _
& "</font>"
Response.Write(message)
Response.Write("An error has occured on this server, and the administrator of the
site has been notified.")
367
ASP.NET
mail.From = "
mail.To = "
ASP.NET
ASP.NET
EventLog.CreateEventSource(LogName, LogName);
}
// Insert into event log
EventLog Log = new EventLog();
Log.Source = LogName;
Log.WriteEntry(Message, EventLogEntryType.Error);
}
.
.
. IIS
[Global.asax]
<%@ Import Namespace="System.Diagnostics" %>
<script language="C#" runat="server">
void Application_Error(Object sender, EventArgs e) {
String Message = "\n\nURL:\n http://localhost/" + Request.Path
+ "\n\nMESSAGE:\n " + Server.GetLastError().Message
+ "\n\nSTACK TRACE:\n" + Server.GetLastError().StackTrace;
// Create Event Log if it does not exist
370
ASP.NET
-1 :
.
-2
) ( .
ASP.NET .
-3 client client
ASP.NET . client ) client
371
ASP.NET
( .
.
-4
. > <customErrors ><error HTTP
.
-5 . Page
Page_Error override .
.
-6 System.Web.Mail
.
-7 Application_Error Global.asax
. .
-8 System.Diagnostics .
372
ASP.NET
QueryString .
.
.
VS.net C# Application ASP.net Web
Application . WebForm1.aspx Toolbox
Label WebForm1 Label1 .
Base64String
Base64String String ) string(
) !( " "I LOVE ASP.net
Base64String " ." =SSBMT1ZFIEFTUC5uZXQ
;"string String = "I LOVE ASP.net
;)byte [] Byte = System.Text.Encoding.ASCII.GetBytes(String
;)Label1.Text = Convert.ToBase64String(Byte
1
373
ASP.NET
ASP.NET
. DES :TripleDES
Data Encryption Standard. :DES
. :MD5
.( Hash function) Hash ComputeHash MD5
binary string binary string ( Hash functions) Hash
!
.( Hash )
.(! )
byte[] IV = new byte[8] {240, 32, 45, 29, 0, 76, 173, 59};
string cryptoKey = "All you need is Love";
string MyString = "I LOVE ASP.net";
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(MyString);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
des.Key =
MD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(cryptoKey));
des.IV = IV;
byte[] CodedBuffer =
des.CreateEncryptor().TransformFinalBlock(buffer,0,buffer.Length);
Label1.Text = System.Convert.ToBase64String(CodedBuffer,0,CodedBuffer.Length);
cryptoKey IV
375
ASP.NET
)DESCryptoServiceProvider (TripleDESCryptoServiceProvider
Key IV Initialization Vector )
Key IV DESCryptoServiceProvider
( . IV
IV !
IV byte cryptoKey string "All you need
"is Love " "All you need is Love . MyString
string ) . C#
(.
:des.Key Key
MD5.ComputeHash Key
MD5.ComputeHash string cryptoKey
byte (System.Text.ASCIIEncoding.ASCII.GetBytes(cryptoKey)).
CreateEncryptor TransformFinalBlock
Hash byte .
byte string Base64String
.
376
ASP.NET
TripleDESCryptoServiceProvider
System.Security.Cryptography MD5CryptoServiceProvider
using System.Security.Cryptography namespace
.
: CreateDecryptor
byte[] IV = new byte[8] {240, 32, 45, 29, 0, 76, 173, 59};
string cryptoKey = "All you need is Love";
string CodedString64 = "zNvKahC6S/+8xMX3o658wQ==";
byte[] buffer = Convert.FromBase64String(CodedString64);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
des.Key =
MD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(cryptoKey));
des.IV = IV;
byte[] CodedBuffer =
des.CreateDecryptor().TransformFinalBlock(buffer,0,buffer.Length);
Label1.Text = System.Text.Encoding.ASCII.GetString (CodedBuffer);
" ) jcUKVu8D4dlpy4BHw6bgefaVMWW9x0qV "
! IV Key IV ( !
! " ! red rose" Key
377
ASP.NET
TripleDES
DES ) !(.
Key )
email ! 10000
!( . server
Key Web.config ! .
378
ASP.NET
) (Whois ASP.NET
www.Register.com
.
ASP.NET .
Query . TCP 43
. 2 .
:
;Using System. NET.Sockets
;Using System.Text
Using System.IO
;Using System.Text.RegularExpressions
TcpClient NetFramework. .
System. NET.Sockets .
.
1
www.mit.edu/afs/athena/contrib/potluck/net-services/whois-servers.list 2
379
ASP.NET
Query
:
;string StrSvr,StrDomain, Resp
;TcpClient TcpClt
;byte[] ArrDomain
;Stream TcpStr
;StreamReader TcpStrRdr
Query .
)(... OrgCom .
. whois.internic.com
.NET com. edu. Info.
.
.
DropDownList :
|| "if (DDLstSuffix.SelectedItem.Value == ".COM
== DDLstSuffix.SelectedItem.Value == ".NET" || DDLstSuffix.SelectedItem.Value
)"".EDU
{
;"StrSvr = "whois.internic.net
StrDomain = TxtDomainName.Text.Trim() + DDLstSuffix.SelectedItem.Value+
;""\r\n
380
ASP.NET
}
else if (DDLstSuffix.SelectedItem.Value == ".ORG")
{
StrSvr = "whois.publicinterestregistry.net";
StrDomain = TxtDomainName.Text.Trim() + DDLstSuffix.SelectedItem.Value+
"\r\n";
}
else if (DDLstSuffix.SelectedItem.Value == ".BIZ")
{
StrSvr = "whois.neulevel.biz";
StrDomain = TxtDomainName.Text.Trim() + DDLstSuffix.SelectedItem.Value+
"\r\n";
}
else if (DDLstSuffix.SelectedItem.Value == ".INFO")
{
StrSvr = "whois.afilias.info";
StrDomain = TxtDomainName.Text.Trim() + DDLstSuffix.SelectedItem.Value+
"\r\n";
}
else if ((DDLstSuffix.SelectedItem.Value == ".IR") || (DDLstSuffix.SelectedItem.Value
== ".CO.IR") || (DDLstSuffix.SelectedItem.Value == "..NETIR") ||
(DDLstSuffix.SelectedItem.Value == "ID.IR"))
{
StrSvr = "whois.nic.ir";
StrDomain = TxtDomainName.Text.Trim() + DDLstSuffix.SelectedItem.Value+
"\r\n";
}
381
ASP.NET
"\ "r\n .
.
. TcpClient
. :
-1 TcpClient : Connect
;)(TcpClient TcpClt = new TcpClient
;)TcpClt.Connect(StrSvr,43
-2 TcpClient
. Constructor :
;)TcpClient objTCPC = new TcpClient(StrSvr, 43
GetBytes ) Encoding (System.Text StrDomain
.
;)ArrDomain = Encoding.ASCII.GetBytes(strDomain
GetStream TcpClient Stream
:
382
ASP.NET
;)(TcpStr = TcpClt.GetStream
Stream Write Byte Stream :
;)TcpStr.Write (ArrDomain,0,StrDomain.Length
StreamReader
Encoding .
;)TcpStrRdr = new StreamReader(TcpClt.GetStream(),Encoding.ASCII
ReadToEnd .
" "\n "> "<br . Replace RegEx
:
;)">Resp = Regex.Replace(TcpStrRdr.ReadToEnd(),"\n","<br
;)(Resp = Resp.ToLower
" "no match " "not found " "no entries found
. .
. IsMatch RegEx
. True False
.
383
ASP.NET
384
ASP.NET
1
385
ASP.NET
HttpHandler.
HttpHandler
HttpHandler API Request/Response
. Handler
doc. .
E-Commerce FTP .
Web.Config
: web.config Secure .
><HttpHandlers
><add verb="*" path="*.doc" type="pdfIntercept.pdfHandler, pdfInterceptX" /
></HttpHandlers
IHttpHandler doc
.
verb POST GET HEAD *
.
386
ASP.NET
Path * doc.
doc
Type Handle .
.
][NAMESPACE].[CLASS], [ASSEMBLY NAME
Custom Extension
IIS .
:
Read : False
Write: False
Directory Browsing: False
IIS Manager Properties/Edit Home
Configuration . doc, pdf
. add .
HttpHandler .
387
ASP.NET
HttpHandler
Authentication . HttpHandler
.
using System;
using System.Web;
using System.IO;
namespace pdfIntercept
{
public class pdfHandler : IHttpHandler
{
//Notice ProcessRequest is the only method
//exposed by the IHttpHandler
public void ProcessRequest(HttpContext context)
{
try
{
string strString = "yes";
HttpRequest oRequest = context.Request;
HttpResponse oResponse = context.Response;
//ADD YOUR CUSTOM AUTHENICATION HERE
//ADD YOUR CUSTOM AUTHENICATION HERE
388
ASP.NET
ASP.NET
ASP.NET
ASP.NET
:
HttpHandler -1 doc .
-2
.
-3 Binary Stream .
-4 Denied
HttpHandler .
E-Commerce
. URL
.
392
ASP.NET
ASP.NET
.
.
www.iranasp.net/download/hrooznamechi002.zip :
.
. .
ASP.NET
.
Graphics .
DrawImage .
DrawImageUnscaled
.
:
- 1 ) (.
1
393
ASP.NET
- 2 )
(.
- 3 )
(.
:
- 1 ImageAttributes
.
- 2 Graphics
.
DrawImage ". "myGraphics
graphics " "img .
)
result.jpg
readme.doc (.
- 1 :
)>myGraphics.DrawImage(img,<point
394
ASP.NET
X Y .
. )
(
)
( .
- 2 :
)myGraphics.DrawImage(img,BiggerRectangle
) BiggerRectangle
( . .
- 3 :
DistRectangle=new Rectangle(100,100,10,10)//
)myGraphics.DrawImage(img, DistRectangle,75,40,10,10,GraphicsUnit.Pixel
) ( DrawImage
. GraphicsUnit Pixel .
.
.
- 4 :
395
ASP.NET
396
ASP.NET
) ( .
.
- 7 :
;)Rectangle DistRectangle = new Rectangle(50,50,320,240
;)Rectangle SourRectangle= new Rectangle(0, img.Height, img.Width,- img.Height
;)myGraphics.DrawImage(img,DistRectangle,SourRectangle,GraphicsUnit.Pixel
ImageAttributes .
ColorMatrix alpha .
property ColorMatrix.Matrix33
.
- 8 :
;))myGraphics.DrawImage(img1,new Point(0,0
;)(ImageAttributes ia = new ImageAttributes
;)(ColorMatrix cm = new ColorMatrix
;cm.Matrix33=0.5f
;)ia.SetColorMatrix(cm
myGraphics.DrawImage(img2,new Rectangle(0, 0, img2.Width, img2.Height ), 0, 0,
;)img2.Width, img2.Height, GraphicsUnit.Pixel, ia
- 9 Thumbnail :
397
ASP.NET
Thumbnail .
Graphics
) (10 . Thumbnail
.
:
System.Drawing.Image.GetThumbnailImageAbort myCallBack = new
;)System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback
= System.Drawing.Image imgResizedImage
;)MainPic.GetThumbnailImage(360,270,myCallBack,IntPtr.Zero
:
) : callback (callbackData callback
Image.GetThumbnailImageAbort . GDI+1 0
. ) (.
callbackData IntPtr.Zero.
Thumbnail
Thumbnail .
) 120 (120
.
398
ASP.NET
DrawImage .
.
- 10 :
;)System.Drawing.Image NewImage = new System.Drawing.Bitmap(300,300
= System.Drawing.Graphics NewImageGraphics
;)System.Drawing.Graphics.FromImage(NewImage
;)Rectangle DistRectangle = new Rectangle(0,0,NewImage.Width,NewImage.Height
;)Rectangle SourRectangle = new Rectangle(0,0,my1stImage.Width,my1stImage.Height
NewImageGraphics.DrawImage(my1stImage,DistRectangle,SourRectangle,GraphicsUn
;)it.Pixel
Image NewImage Bitmap
.
. )(
result.jpg .
IIS NET Framework. .
399
ASP.NET
ASP.NET
ASP.NET
.
) (CLIENT .
4 .
.
: ) (session ) . (persistent
.
.
.
.
. .
.
.
. .
1
400
ASP.NET
HttpCookie System.Web .
Response Request
HttpCookieCollection .
HttpCookieCollection
. HttpCookie
. Name Value
. Expires HttpCookie
. UID PASS.
Response.Cookies.Add :
Listing 1. Creating cookies
'
'
)"Dim cookie As HttpCookie = New HttpCookie("UID
"cookie.Value = "myid
cookie.Expires = #9/28/2002#
)Response.Cookies.Add(cookie
)"cookie = New HttpCookie("PASS
"cookie.Value = "mypass
cookie.Expires = #9/28/2002#
)Response.Cookies.Add(cookie
401
ASP.NET
. Request.Cookies
: ListBox
Listing2 . Read cookies
'
Dim cookieCols As New HttpCookieCollection()
cookieCols = Request.Cookies
Dim str As String
'
For Each str In cookieCols
ListBox1.Items.Add("Cookie: " + str)
ListBox1.Items.Add("Value:" & _
Request.Cookies(str).Value)
Next
HttpCookieCollection Remove Clear
: Remove .
Listing3 . Deleting cookies
Dim cookieCols As New HttpCookieCollection()
cookieCols = Request.Cookies
Dim str As String
'
402
ASP.NET
Request.Cookies.Remove("PASS")
Request.Cookies.Remove("UID")
. .
. Values
.
Listing4 . Creating a dictionary cookie
Dim cookDict As HttpCookie = New HttpCookie("dict")
cookDict.Values("fname") = "first name"
cookDict.Values("lname") = "last name"
cookDict.Values("Address") = "address"
Response.Cookies.Add(cookDict)
Asp.Heaven :
403
ASP.NET
404
ASP.NET
HTML
HTML ASP.NET
www.iranasp.net/download/htmlcontrols.zip :
ASP.NET : HTML Web.
HTML HTML .
HTML HTML
ASP.NET .
HTML .
.
><html
><head><title>SimpleHTML.htm</title></head
><body
>"<form method="post" action="SimpleHTML.htm
Enter your favorite color:
><br
>"<input name="favColor" type="text
><p
>"!<input type="submit" value="Submit
1
405
ASP.NET
></form
></body
></html
.
ASP.NET .
><html
><head><title>SimpleASPX.aspx</title></head
><body
>"<form runat="server
Enter your favorite color:
><br
>"<input id="favColor" type="text" runat="server
><p
>"<input type="submit" value="Submit!" runat="server
></form
406
ASP.NET
></body
></html
HTML
:
aspx .
" runat="server .
name id > <input .
Method Action > <form ASP.NET
.
. HTML HTML ASP.NET
.
407
ASP.NET
ASP.NET
ASP.NET
www.iranasp.net/download/webcontrols.zip :
HTML .
HTML
. HTML > <select
ListBox ComboBox InputLine
TextBox > <input > <textarea.
ASP.NET . ASP.NET
.
HTML HTML
. ASP.NET :
:TextBox )( .
: Label .
: CheckBox /.
: RadioButton .
: HyperLink ( ( .
1
408
ASP.NET
: Button HTML
.
: LinkButton HTML
.
: ImageButton HTML
.
HTML . ASP.NET
TextBox Button .
><html
><head><title>Guestbook.aspx</title></head
><body
><h3>Please Sign Our Guestbook!</h3
>"<form runat="Server
Your Name:
><br
<asp:TextBox
"ID="username
>runat="Server" /
><p
409
ASP.NET
Comments:
><br
<asp:TextBox
"ID="comments
"TextMode="Multiline
"Columns="50
"Rows="4
>runat="Server" /
><p
<asp:Button
"!Text="Submit
>Runat="Server" /
></form
></body
></html
.
. TextBox
.
<asp:TextBox
"ID="username
>runat="Server" /
410
ASP.NET
:
)(... Label TextBox
ID
" runat="Server
HTML .
411
ASP.NET
ASP.NET
ASP.NET
www.iranasp.net/download/eventhandle.zip :
HTML ) (Button )( ) (Event
) (ComboBox .
.
Load Init Unload .
/ ) (checkbox .
HTML ASP.NET .
. ) (Event Handling
.
.
HTML
HTML ASP.NET ServerClick .
.
1
412
ASP.NET
. ServerClick
.
<Script runat="Server">
Sub submitText( s As Object, e As EventArgs )
mySpan.InnerHtml = StrReverse( myTextArea.Value )
End Sub
</Script>
<html>
<head><title>HtmlControlEvents.aspx</title></head>
<body>
<form runat="server">
Enter some text:
<br>
<textarea
id="myTextArea" cols="30" rows="3"
runat="Server"></textarea>
<p>
<input type="submit" value="Submit Text!"
runat="server" onServerClick="submitText">
413
ASP.NET
><p
><span id="mySpan" runat="server"></span
></form
></body
></html
HTML :
"!<input type="submit" value="Submit Text
>"runat="server" onServerClick="submitText
" onServerClick="submitText .
onServerClick submitText .
submitText .
textbox > <span .
submitText : object EventArgs.
object .
. EventArgs .
.
414
ASP.NET
. HTML
. Click Button
.
<Script runat="Server">
Sub submitText( s As Object, e As EventArgs )
myLabel.Text = StrReverse( myTextBox.Text )
End Sub
</Script>
<html>
<head><title>WebControlEvents.aspx</title></head>
<body>
<form runat="server">
Enter some text:
<br>
<asp:TextBox
id="myTextBox"
TextMode="Multiline"
Columns="30"
Rows="3"
Runat="Server" />
415
ASP.NET
<p>
<asp:Button
Text="Submit Text!"
runat="server"
onClick="submitText" />
<p>
<asp:Label
id="myLabel"
runat="server" />
</form>
</body>
</html>
: Button
<asp:Button
Text="Submit Text!"
runat="server"
onClick="submitText" />
Button Click onClick
. Button . submitText
Textarea submitText
. Label
416
ASP.NET
Label
Label
www. iranasp.net/download/labelcontrol.zip :
ASP.NET Label
. Text
.
Page-Load .
>"<Script runat="Server
Sub Page_Load
) "lblDate.Text = Now.ToString( "D
End Sub
></Script
><html
><head><title>ShowDate.aspx</title></head
><body
<asp:Label
"id="lblDate
1
417
ASP.NET
Runat="Server" />
</body>
</html>
.
. 24 p Verdana
<Script runat="Server">
Sub Page_Load
lblDate.Text = Now.ToString( "D" )
End Sub
</Script>
<html>
<head><title>LabelFormat.aspx</title></head>
<body>
<asp:Label
id="lblDate"
ForeColor="Blue"
BackColor="Yellow"
Font-Name="Verdana"
Font-Size="24pt"
418
Runat="Server" />
</body>
</html>
419
ASP.NET
ASP.NET
ListBox ArrayList
ArrayList .
www.iranasp.net/download/shahoo03.zip :
ASP.NET ListBox Page_Load .
ASP.NET ) ( Data souce .
.
ASP.NET ArrayList .
) (Objects Collection . ArrayList .
ListBox Datasource .
Datasource . DataBind
ListBox . ArrayList
ListBox ) (lstFlowers ArrayList .
.
><% @Page Language="VB" Debug="True" %
><html><head><title>Databing Demo</title></head
><body
>"<form runat="server
Select a flower, and then click the submit button please:
1
420
ASP.NET
<br>
<asp:ListBox id="lstFlowers" runat="server" rows="3"
AutoPostBack="True" onSelectedChanged="showSelection"/>
</asp:ListBox>
<br><br>
<asp:Label id=lblMessage runat="server"></asp:Label></p>
</form>
</body></html>
<script language=vb runat="server">
sub Page_Load(source As Object, e As EventArgs)
if Not Page.IsPostBack Then
Dim myArrayList As New ArrayList
myArrayList.Add("Azalea")
myArrayList.Add("Tulip")
myArrayList.Add("Rose")
lstFlowers.DataSource=myArrayList
lstFlowers.DataBind()
lstFlowers.SelectedIndex=0
end if
end sub
sub showSelecttin(Sender As Object, e As EventArgs)
lblMessage.Text="You have selected " +lstFlowers.SelectedItem.Text
end sub
</script>
421
ASP.NET
HyperLink
HyperLink
www.iranasp.net/download/shahoo02.zip :
)( ASP.NET HyperLink .
Text NavigateUrl
ImageUrl
NavigateUrl .
( hyper.gif ).
><%@ Page Language="VB" Debug="True" %
><html
><head
><title>HyperLink Control</title
></head><body
"<asp:HyperLink id="hl1" runat="server
"NavigateUrl="http://www.iranasp.net
>Text=" Go to IranASP.NET" /
><br
"<asp:HyperLink id="hl2" runat="server
"NavigateUrl="http://www.iranasp.net/forum
"ImageUrl="hyper.gif
1
422
423
ASP.NET
ASP.NET
ASP.NET
.
.
ASP .
VB VBScript . ASP
. Visual InterDev
. InterDev
.
Web Form ASP.NET
HTML .
Web From
. Hello World
.
1
424
ASP.NET
.
2000 .
2000 ) (Professional
Professional .4
.NET Framework
. .
NTFS
.
Hello World
ASP.NET Web Application
HelloWorld . http://localhost.
OK solution .
Web Form WebForm1.aspx . .
OK .
Visual Studio Projects web application
. :
inetpub/wwwroot .
IIS Application script .
425
ASP.NET
426
ASP.NET
427
ASP.NET
IntelliSense lblText
Label . InterDev
.
Web Form Text Submit
. . F5
WebForm1.aspx .
WebForm2.aspx Solution Explorer WebForm2.aspx
Set As Start Page . .
Web FormWebForm2.aspx
Label . Label
. .
428
ASP.NET
ASP.NET
ASP.NET ASP
.
ASP HTML
. ASP ASP.NET
ASP HTML . ASP
HTML
.
) (Execute HTML .
aspx . ) IIS
Server .NET Framework (
aspx runtime ASP.NET .
ASP
. ASP
. aspx .
) ( aspx aspx.vb
HTML ASP
.
1
429
ASP.NET
ASP.NET
Global.asax.vb HelloWorld.dll
.
aspx ASP.NET cls
dll . dll HelloWorld.dll
HTML .
.NET Framework System .
aspx System.Web.UI.Page .
aspx ) ( system.web.ui.page .
Request Response ... .
.
. .
431
ASP.NET
html
.
ASP .
:
.
.
aspx ( vb cs (
.
.
.
aspx vb
Solution Explorer Show All Files .
1
432
ASP.NET
aspx vb . WebForm2.aspx.vb
WebForm2 .
System.Web.UI.Page Response , Request ,
Server , Session Application .
WithEvents .
.
ASP 50 100 .
.
.
.
ActiveX
ActiveX . ActiveX HTML
.
HelloWorld . WebForm3.aspx
. toolbox Calendar
. !! ASP & Drag
Drop !!
433
ASP.NET
!
:
-------------------------------ID
myCal
BackColor
BorderColor
Black
BorderStyle
Solid
BorderWidth
1px
DayHeaderStyle , BackColor
DayHeaderStyle , BorderColor
DayHeaderStyle , BorderStyle
Inset
DayHeaderStyle , BorderWidth
1px
True
Short
Verdana
X-Small
NextPrevFormat
ShortMonth
OtherMonthDayStyle , ForeColor
Silver
SelectedDayStyle , BackColor
SelectedDayStyle , ForeColor
White
. WebForm3.aspx
Internet . toolbox
. Netscape 4 Explorer
434
ASP.NET
ASP.NET Server Control HTML Server Control Validation Control
.
. :
HTML Server Control
ASP.NET Server Control
Validation Control
User Control
Server-Side Control .
Server-Side Control
ASP ASP > % <% HTML .
HTML ASP .
.
. nm .
. Request
1
435
ASP.NET
value .
.
.
submit .
" runat="server . " runat="server
:
><HTML
><HEAD
><title>Untitled</title
></HEAD
><BODY
>"<Form Action="testform.aspx" runat="server
? What is your name
"<asp:textbox name="nm
"value="" size="40
>MAXLength="40" runat="Server"/><br
>" <input Type="submit" Name="cmd" Value=" Submit
></FORM
></BODY
></HTML
436
ASP.NET
aspx ASP.NET .
. ASP
aspx . = server .
ASP.NET .
.
HTML form
ID Name __ VIEWSTATE
.
HTML Server Control
HTML Server Control " runat="server .
) (Toolbox .
HTML HTML . HTML Server
" runat="server .
HTML Server Control HTML
CheckBox , ListBox , TextBox , Table , Form .
.
HTML
. HTML
437
ASP.NET
"runat="server Design
Run As Server Control .
HTML System.Web.UI.HTMLControls .
HTML HTML Server Control
:
.
client
.
.
HTML Server Control ASP
. ASP ASP.NET .
HTML Server Control ASP.NET Server Control
.
ASP.NET Server Controls
HTML Server Control HTML
. ASP.NET Server Controls
.
438
ASP.NET
ASP.NET
:
:RequiredFieldValidator .
:CompareValidator .
:RangeValidator .
:RegularExpressionValidator
.
CustomValidator .
.
HelloWord . ID
txtName . RequiredFieldValidator
. Text Submit .
ID rfvTxtName .
.
ControlToValidate txtName . ErrorMessage Required
Field. Please enter your name . .
440
ASP.NET
WebForm4.aspx .
.
.
.
HTML
.
.
User Controls
.
.
441
ASP.NET
.
.
. HTTP
. :
.
.
HTML .
.
.
.
.
.
. .
.
1
442
ASP.NET
. 6
Form_Unload Form_QueryUnload Form_Load Form_Initialize
Form_Terminate.
. HTML
. .
:
: Form_Initialize Form_Load 6 .
Page_Load .
. .
:
.
.
: .
Form_Unload Form_Terminate .
443
ASP.NET
.
Page_Unload .
:
Postbacknon-Postback
ApplicationSession
.
Client
ASP.NET Server
HTML .
MouseMove .
Postbacknon-Postback
444
ASP.NET
ASP.NET .
OnChange
.
. .
DataGrid
DataGrid container . ) (
. container container
ItemCommand .
.
Application Session
ASP Application Session
SessionStart ApplicationEnd ApplicationStart SessionEnd.
.
445
ASP.NET
DataGrid
DataGrid
www.iranasp.net/download/pourshahid01.zip :
.
AutoGenerateColumns=True DataGrid
BoundColumn
.
. Data
Grid .
System.Data
) ASP.NET C# VB.NET JS.NET
(.
CreateDataSource
.
) ( Page_Load
1
446
ASP.NET
DataGrid
. HTML
<%@ Import Namespace ="System.Data" %>
<html>
<script language="VB" runat="server">
Function CreateDataSource() As ICollection
Dim dt As DataTable
Dim dr As DataRow
Dim i As Integer
'create a DataTable
dt = New DataTable
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("DateTimeValue", GetType(Boolean)))
dt.Columns.Add(New DataColumn("BoolValue", GetType(Integer)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType Double)))
'Make some rows and put some sample data in
For i = 1 To 9
dr = dt.NewRow()
dr(0) = i
447
ASP.NET
449
ASP.NET
ASP.NET
AdRotator
AdRotator
.
Rotator Schedule .
( Properties) Advertisement File . XML
. AdRotator
File :AdRotator.aspx
<%@ Page Language="VB" %>
<html>
<body>
<H1>AdRotator in ASP.NET</H1>
<asp:AdRotator id=MyAdRotator runat=server
AdvertisementFile="Advertisement.xml"
BorderWidth=2 />
</body>
</html>
1
450
ASP.NET
ASP.NET
: Keyword .
: Impressions .
AdRotator ) XML (
HTML Client ) Imperssions
(.
Keyword
Filter .
http://www.iranasp.net .
File :AdRotator.aspx
<asp:AdRotator id=MyAdRotator runat=server
"AdvertisementFile="Advertisement.xml
"KeywordFilter="ASP
>BorderWidth=2 /
:
http://www.123aspx.com
http ://www.aspnextgen.com
452
ASP.NET
ASP.NET
ASP.NET .
.
. ASP.NET
.
.
ASP.NET
HTML .
.
ASP.NET
.
True False
.
.
False .
1
453
ASP.NET
.
.
10 5
.
ASP.NET :
RequiredFieldValidator
ReqularExpressionValidator
CompareValidator
RangeValidator
CustomVlidator
ValidationSummary
. BaseValidator
WebControl System.UI.WebControls Control
System.Web.UI . Text Label
.
.
454
ASP.NET
: ControlToValidate ID TextBox
. .
: Display . :
: None
ValidationSummary .
.
: Static
.
.
:Dynamic Static
.
.
: Enabled .
: EnabledClientScrip .
: ErrorMessage .
455
ASP.NET
: ForeColor .
: IsValid .
: Visible .
) ASP.NET (
www.nashreoloom.com/showbooks.aspx@id=110
456
ASP.NET
ViewState -
ASP .
ASP.NET ViewState .
Back ...
. ViewState !
ASP.NET )(
.! ASP.NET ViewState
. ViewState
)( . :
) (Hidden Field . >"<Form runat="server
ASP.NET . :
>"<Form name="_ct10" method="post" action="page.aspx" id="_ct10
"<input type="hidden" name="__VIEWSTATE
>value="dDwtNTI0ODU5MDE1Ozs+ZBCF2ryjMpeVgUrY2eTj79HNl4Q" /
some code
></form
ViewState ASP.NET WebForm .
ViewState Directive aspx :
1
457
ASP.NET
458
ASP.NET
ViewState -
ASP .
ASP.NET ViewState .
serializable TypeConverter
ViewState . serializable
TypeConverter ViewState
.
String ArrayList HashTable .
ViewState
round-trip
.
ViewState
) (Connection String ViewState .
EnableViewState
ViewState .
DataList Repeater DataGrid ViewState
. false
1
459
ASP.NET
EnableViewState
.
Session ViewState .
:
][C#
;"ViewState["MyData"] = "This is some data.
][VB.NET
"ViewState("MyData") = "This is some data.
ViewState
ViewState .
:
][C#
;]"string strTmp = (string) ViewState["MyData
][VB.NET
)]"Dim strTmp As String = CStr(ViewState["MyData
Label
ViewState .
][VB.NET
' This control renders values stored in view state for Text and FontSize properties.
460
Imports System
Imports System.Web
Imports System.Web.UI
Namespace ViewStateControlSamples
Public Class LabelVB : Inherits Control
' Add property values to view state with set;
' retrieve them from view state with get.
Public Property [Text] As String
Get
Return CStr(ViewState("Text"))
End Get
Set
ViewState("Text") = Value
End Set
End Property
ASP.NET
ASP.NET
End Set
End Property
Protected Overrides Sub Render(Output As HtmlTextWriter)
Output.Write("<font size=" & Me.FontSize & ">" & Me.Text & "</font>")
End Sub
End Class
End Namespace
[C#]
// This control renders values stored in view state for Text and FontSize properties.
using System;
using System.Web;
using System.Web.UI;
namespace ViewStateControlSamples {
public class Label: Control {
// Add property values to view state with set;
// retrieve them from view state with get.
public String Text {
get {
return (String) ViewState["Text"];
}
462
ASP.NET
set {
ViewState["Text"] = value;
}
}
463
ASP.NET
ListBox
ListBox .
ASP.NET
ListBox .
ASP.NET RequiredFieldValidator .
ControlToValidate ListBox !
:
ASP.NET
. RequiredFieldValidator
.
:
1
464
ASP.NET
BaseValidator ) ( .
Client Side .
Server Side
.
RequieredItem
)
SelectionMode ListBox Multiple (.
DropDownList
CheckBoxList RadioButtonList .
:
][C#
;using System
;using System.Text
;using System.Web.UI
;using System.Web.UI.WebControls
namespace MyLib
{
>/// <summary
/// Summary description for RequieredListBoxValidator.
>/// </summary
public class RequieredListBoxValidator : BaseValidator
{
465
ASP.NET
ASP.NET
ASP.NET
ASP.NET
}
}
DLL ( DLL ) Assembly
VS.NET References
. .
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<%@ Register TagPrefix="mylib" Namespace="MyLib" Assembly="MyLib" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="WebForm1" method="post" runat="server">
<asp:ListBox id="ListBox1" runat="server" SelectionMode="Multiple">
<asp:ListItem Value="1">Item 1</asp:ListItem>
<asp:ListItem Value="2">Item 2</asp:ListItem>
<asp:ListItem Value="3">Item 3</asp:ListItem>
</asp:ListBox>
469
ASP.NET
<mylib:RequieredListBoxValidator id="RequieredListBoxValidator1"
runat="server" RequieredItem="2" ErrorMessage="You have to select at least 2 items
from list box!" ControlToValidate="ListBox1"></mylib:RequieredListBoxValidator>
<br>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
470
ASP.NET
ListBox ASP.NET
listbox Style
.
www.iranasp.net/download/ webtech038.zip :
ASP.NET
. ListBox
.
.
.
.
ListBox
:
1
471
ASP.NET
;ListItem item
)for(int i = 1; i<=10; i++
{
;)( item = new ListItem
;)( item.Value = i.ToString
;)( item.Text = "Item" + i.ToString
;)"item.Attributes.Add ("Style", "background-color: #0000ff;color: #ffffff
;)myListBox.Items.Add (item
}
! Style ListItem
HTML render .
ASP.NET ListBox .
.
ASP.NET
.
ListBox
ASP.NET render .
ListBox!
Inheritance ) . )!
472
ASP.NET
StyledListBox
ListBox . C# :
][C#
;using System
;using System.Collections
;using System.Web.UI
;using System.Web.UI.WebControls
namespace ColoredListBox
{
>/// <summary
/// Summary description for StyledListBox.
>/// </summary
public class StyledListBox : System.Web.UI.WebControls.ListBox
{
}
}
. ColoredListBox
. StyledListBox public
. ListBox ASP.NET
System.Web.UI.WebControls.ListBox ListBox
.
473
ASP.NET
ListBox
ListBox .
. ListBox
. ListBox RenderContents
:
[C#]
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ColoredListBox
{
/// <summary>
/// Summary description for StyledListBox.
/// </summary>
public class StyledListBox: System.Web.UI.WebControls.ListBox
{
override protected void RenderContents(HtmlTextWriter writer)
{
for(int c=0;c<Items.Count;c++)
{
ListItem i = Items[c];
writer.WriteBeginTag("option");
474
ASP.NET
if(i.Selected)
writer.WriteAttribute("selected","selected",false);
writer.WriteAttribute("value",i.Value,true);
IEnumerator d = Items[c].Attributes.Keys.GetEnumerator();
while(d.MoveNext())
writer.WriteAttribute(d.Current.ToString(),Items[c].Attributes[d.Current.ToString()]);
writer.Write('>');
System.Web.HttpUtility.HtmlEncode(i.Text,writer);
writer.WriteEndTag("option");
writer.WriteLine();
}
}
}
}
HtmlTextWriter !
.
Attribute selected value listbox
! ListBox HTML
:
[C#]
IEnumerator d = Items[c].Attributes.Keys.GetEnumerator();
while(d.MoveNext())
writer.WriteAttribute(d.Current.ToString(),Items[c].Attributes[d.Current.ToString()]);
475
ASP.NET
ListBox .
ColoredListBox.StyledListBox listbox
. codebehind .
[C#]
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ColoredListBox
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected StyledListBox ListBox1;
private void Page_Load(object sender, System.EventArgs e)
476
ASP.NET
{
// Put user code to initialize the page here
ListItem item;
item = new ListItem ("IranASP.NET 1", "1");
item.Attributes.Add ("Style", "background-color:#39B54A; color:#ffffff");
this.ListBox1.Items.Add (item);
item = new ListItem ("IranASP.NET 2", "2");
item.Attributes.Add ("Style", "color:#0000ff");
this.ListBox1.Items.Add (item);
item = new ListItem ("IranASP.NET 3", "3");
item.Attributes.Add ("Style", "background-color:#ff0000; color:#ffffff");
this.ListBox1.Items.Add (item);
}
}
}
listbox aspx
StyledListBox .
:
ASP.NET
!
: Style
listbox .
478
ASP.NET
JavaScript ASP.NET
Server-Side Client-Side
.
ASP.NET ) Server-Side (
. JavaScript ) Client-Server (
.
! . JavaScript
JScript JavaScript JavaScript
. .
Server-Side Client-Side ASP.NET
. ASP.NET .
ASP.NET ASP.NET
.
.
Submit . ASP.NET
JavaScript __ doPostBack .
HTML . runtime
Render HTML .
1
479
ASP.NET
ASP.NET
. ASP .NET ASP.NET
.
aspnet_client .
JScript ASP.NET
.
ASP.NET
. ASP.NET
.
Page
Page ASP.NET
)(Method .
:RegisterClientScriptBlock JavaScript
. ) (string key script
. script JavaScript key
. > <form
www.iranasp.net/tutorial/article.aspx@articleid=107 1
480
ASP.NET
. HTML
. ASP.NET
HTML ( comment) JavaScrip
.
<script language="JavaScript">
<!-
// -->
</script>
.
[C#]
<html>
<head>
<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e) {
// Form the script that is to be registered at client side.
String scriptString = "<script language=JavaScript> function DoClick() {";
scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<";
scriptString += "/";
scriptString += "script>";
481
ASP.NET
if(!this.IsClientScriptBlockRegistered("clientScript"))
this.RegisterClientScriptBlock("clientScript", scriptString);
}
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="text" id="show" style="width=200"> <input type="button"
value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>
:IsClientScriptBlockRegistered
RegisterClientScriptBlock ( key)
RegisterClientScriptBlock .
.
RegisterClientScriptBlock :RegisterStartupScript
. .< form/>
[C#]
<html>
<head>
482
ASP.NET
</script>
</head>
<body topmargin="20" leftmargin="10" onload="Page_Load()">
<form id="myForm" runat="server">
<span id="showMessage1"></span>
<br>
<input type="button" value="ClickMe" onclick="DoClick()">
<br>
<span id="showMessage2"></span>
</form>
483
ASP.NET
></body
></html
:IsStartupScriptRegistered
) (key RegisterStartupScript .
RegisterStartupScript
.
:GetPostBackClientEvent
)(Submit .
:GetPostBackEventReference GetPostBackClientEvent
) (Submit .
:GetPostBackClientHyperlink
) (Submit :javascript .
:RegisterOnSubmitStatement OnSubmit
. .
][C#
)void Page_Load(Object sender, EventArgs e
{
;"{ )(String scriptString = "<script language=JavaScript> function doClick
scriptString += "document.write('<h4>' + myForm.myHiddenField.value+
;"<};)'>'</h4
484
ASP.NET
.
. static
) new
( . ) (namespace
(Common.PageUtil.MakeJavaScriptBlock).
.
;using System
;using System.Web.UI
;using System.Text
485
ASP.NET
using System.Web.UI.WebControls;
namespace Common
{
/// <summary>
/// Utility class for ASP.NET pages
///
/// Be sure to notice that this code is provided as a technology sample
/// and 'as is' and no warranties are made by the author.
///
/// </summary>
public class PageUtil
{
// This static methods helps you build your JavaScript blocks easily
public static string MakeJavaScriptBlock(string strJavascript)
{
string sScript;
sScript = "\n<script language=\"javascript\">\n";
sScript += "<!--\n";
sScript += strJavascript;
sScript += "// -->\n";
sScript += "</script>\n";
return sScript;
}
// This staic method is used in popup screens
// to close popup after doing some thing
486
ASP.NET
487
ASP.NET
DataList
DataList
. DataList
.
DataSource . DataList
DataBase DataBind DataSet Table
.
:
[Code Behind - VB.NET]
Dim Conn As New OleDbConnection
Dim Comm As New OleDbCommand
Dim ds As New DataSet
Dim adp As New OleDbDataAdapter
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Conn.ConnectionString = "Your ConnectionString"
Comm.CommandText = "Select Top 10 * from TableName"
Comm.Connection = Conn
adp.SelectCommand = Comm
1
488
ASP.NET
adp.Fill(ds, "Blog")
Conn.Close()
DataList1.DataSource = ds.Tables("Blog").DefaultView
DataList1.DataBind()
End Sub
[HTML Code]
<asp:DataList Width="100%" id="DataList1" runat="server">
<ItemTemplate>
<font color="Orange"><%# databinder.Eval(container.dataitem,"RowName")
%></font>
</ItemTemplate>
</asp:DataList>
<ItemTemplate> . RowName HTML
< FooterTemplate> < HeaderTemplate> .
. Eval .
Happy DataListing!
489
ASP.NET
ASP.NET
ASP.NET
.
ASP.NET .
.
ASP POST ASP
. ) ) ASP.NET
ASP.NET .
. :
Querystring
Session
Server.Transfer
Querystring
Querystring .
.
490
ASP.NET
.
. :
Button LinkButton
String URL
.
QueryString String
Response.Redirect String
:
private void Button1_Click
)(object sender, System.EventArgs e
{
;string url
url="anotherwebform.aspx?name=" +
TextBox1.Text + "&email=" +
;TextBox2.Text
491
ASP.NET
;)Response.Redirect(url
}
private void Page_Load
)(object sender, System.EventArgs e
{
;]"Label1.Text=Request.QueryString["name
;]"Label2.Text=Request.QueryString["email
}
Session
Session
. Session
. Session
. :
Button LinkButton
Session
Server.Transfer
492
ASP.NET
. Session
:
private void Button1_Click
(object sender, System.EventArgs e)
{
//textbox1 and textbox2 are webform
//controls
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Server.Transfer("anotherwebform.aspx");
}
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
493
ASP.NET
Server.Transfer
.
.
. .
Get
Button LinkButton
Server.Transfer
Context.Handler
. Get .
:
:
public string Name
{
get
{
;return TextBox1.Text
494
ASP.NET
}
}
public string EMail
{
get
{
return TextBox2.Text;
}
}
. Server.Transfer
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("anotherwebform.aspx");
}
private void Page_Load
(object sender, System.EventArgs e)
{
//create instance of source web form
WebForm1 wf1;
//get reference to current handler instance
wf1=(WebForm1)Context.Handler;
495
ASP.NET
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;
}
:
http://www.iranasp.net/Articles/ShowArticle.aspx?articleid=102
496
ASP.NET
DataGrid
DataGrid
www.iranasp.net/download/evalizadeh003.zip:
497
ASP.NET
. : BoundColumn
. Hyperlink : HyperLinkColumn
. : TemplateColumn
. Button : ButtonColumn
. Cancel Update Edit : EditCommandButton
: DataGrid
<asp:Datagrid id="dg" runat="server" AutoGenerateColumns="False"
BorderColor="Black" Font-Size="10" Font-Name="Arial" BackColor="#C6C3FF"
Headerstyle-Font-Size="12" Headerstyle-Font-Bold="True" Headerstyle-FontName="Arial" Headerstyle-Forecolor="#0F0F0F" Headerstyle-BackColor="#8482C6"
cellspacing="0" cellpadding="0" GridLines="Both">
<columns>
<asp:BoundColumn HeaderStyle-HorizontalAlign="Center" DataField="ProdName"
HeaderText="ProdName"></asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
Images
</HeaderTemplate>
<ItemTemplate>
<div align="center">
<img src='/prodimages/<%# Container.DataItem("ImageName") %>'
498
ASP.NET
>border="0" /
></div
></ItemTemplate
></asp:TemplateColumn
"<asp:BoundColumn DataField="Comments
>HeaderText="Comments"></asp:BoundColumn
></columns
></asp:Datagrid
DataGrid .
BoundColumn TemplateColumn BoundColumn
. BoundColumn
DataField DataGrid .
DataGrid.
"<asp:BoundColumn HeaderStyle-HorizontalAlign="Center
>DataField="ProdName" HeaderText="ProdName"></asp:BoundColumn
TemplateColumn DataGrid
TemplateColumn . TemplateColumn DataGrid
:
: HeaderTemplate .
: ItemTemplate .
499
ASP.NET
EditItemTemplate: .
FooterTemplate: .
products.mdb
.
500
ASP.NET
DataGrid
Hotmail Yahoo
.
checkbox . ASP.NET
. DataGrid ASP.NET
.
DataGrid .
www.iranasp.net/download/szhooshmand001.zip :
Datagrid )
ID( . Datagrid checkbox
.
. DataTable
firstname lastname String ID Integer
. DataTable .
501
ASP.NET
ASP.NET
dr.Item(0) = "Ehsan"
dr.Item(1) = "Mojtahedi"
dr.Item(2) = "5"
dt.Rows.Add(dr)
Return dt
End function
) DataTable dt DataTable
.( Page_load
Private dt As DataTable
dt . Page_Load
. Datagrid
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DataGrid1.AllowPaging = True
DataGrid1.PageSize = 3
If Not IsPostBack Then
dt = generateDataSource()
viewstate.Add("dt", dt)
DataGrid1.DataSource = dt
DataGrid1.DataBind()
Else
dt = CType(viewstate("dt"), DataTable)
DataGrid1.DataSource = dt
503
ASP.NET
End If
End Sub
Datagrid
Datagrid Property Builder .
Columns Available Columns Template Column
< Selected Columns . Header text
Select . OK . checkbox .
Datagrid Edit Template ] Select - Column [0 .
checkbox Item Template .
End template editing .
DataGrid DataGrid DataBind
Datasource . DataSource
Databind ). (
Databind DataBind
Datagrid .
ID
. ID . ID
arraylist arrselected .
504
ASP.NET
505
ASP.NET
506
ASP.NET
Datagrid . template
column checkbox Datagrid . DataBinding
PreRender
Datagrid .
507
ASP.NET
DataSet
- 1 DataGrid
- 2 DataList
- 3 Repeater
- 4
508
ASP.NET
: Connection
Dim strConn as string = initial catalog=Northwind;integrated
security=SSPI;persist security info=False;workstation id=DOTNET"
Dim MyConn as New SQLConnection(strConn)
DataSet:
Dim ds as DataSet=New DataSet()
DataAdapter:
Dim MySQL as string = "Select Employees.FirstName, Employees.LastName,
Employees.Title from Employees"
Dim da as New SQLDataAdapter(MySQL,MyConn)
: DataAdapter Fill
da.Fill(ds,"Employees")
DataTable DataSet
.
509
ASP.NET
DataSet DataAdapter .
DataSet :
- 1DataGrid
Employees ) DataSet ( DataGrid
:
MyDataGrid.Datasource=ds.Tables("Employees").DefaultView
)(MyDataGrid.DataBind
Datasource DataGrid -
Employees DataSet - DataGrid
DataBind .
- 2DataList
DataList Repeater DataGrid
:
MyDataList.Datasource=ds.Tables("Employees").DefaultView
)(MyDataList.DataBind
- 3 Repeater
510
ASP.NET
MyRepeater.datasource = ds.Tables("Employees").DefaultView
)(MyRepeater.DataBind
DataList DataGrid Repeater DataBound .
DataBound Programmatically .
.
.
. DataGrid
. Visual Studio .NET Auto Format
) DataGrid (DataList . DataList
DataGrid .
Repeater DataList
.
DataList Repeater
) DataGrid
( . DataList :
"<asp:DataList id="MyDataList" runat="server" GridLines="None
cellpadding="2" cellspacing="2" Headerstyle-BackColor="#8080C0" Headerstyle-FontName="Arial" Headerstyle-Font-Size="8" Font-Name="Arial" Font-Bold="false" Font>"Size="8
511
ASP.NET
><ItemTemplate
<%# DataBinder.Eval(Container.DataItem, "firstname") %> <%#
>DataBinder.Eval(Container.DataItem, "lastname") %><b><i><%#DataBinder.Eval(Container.DataItem, "Title") %> </i></b
></ItemTemplate
></asp:DataList
DataBinder.Eval data-binding
. :
><%# DataBinder.Eval(Container, EvalExpression, FormatExpression) %
Container DataBound
Container.DataItem Container . EvalExpression
FormatExpression
.
- 4 DataSet
DataSet .
DataSet String . :
Dim sEmps as String
Dim dr As DataRow
For Each dr In ds.Tables("Employees").Rows
512
ASP.NET
)"sEmps += "<b>" & dr("firstname") & " " & dr("lastname") & " </b> - " & dr("Title
">& "<br
Next
For
Each Next String . text
literal :
litEmps.text=sEmps
513
ASP.NET
. WinForm
.
.
.
.
: Windows Control Library Web Control Library.
.
)(UserControl1.cs .
.
514
ASP.NET
515
ASP.NET
public ControlName
{
this.borderSide = System.Windows.Froms.Boder3DSide.All;
this.border3DStyle = System.Windows.Froms.Border3DStyle.Etched;
}
(override)
.
protected override void OnPaint(System.Windows.From.PaintEventArgs e)
{
base.OnPaint(e);
System.Windows.Froms.ControlPaint.DrawBorder3D (
e.Graphics,
this.ClientRectangle,
this.border3DStyle,
this.borderSide );
}
Object Browse
. Add Override
516
ASP.NET
Properties
.
:Bindable true
designer )
( .
:DefualtValue
.
:Category
Properties .
:Description
Properties .
:ReadOnly true
.
:Editor . Editor
Editor ) (.
517
518
ASP.NET
ASP.NET
. WinForm
.
.
.
Design .
UITypeEditor .
EditValue GetEditStyle . EditValue
. .
.
public class StringEditor : System.Drawing.Design.UITypeEditor
{
public override object EditValue(ITypeDescriptorContext context,
)IServiceProvider serviceProvider, object value
{
))if ((context != null) && (serviceProvider != null
{
519
ASP.NET
ASP.NET
}
;)return base.GetEditStyle(context
}
}
Editor
.
[Editor(typeof(StringEditor),
]))typeof(UITypeEditor
public string ServerUrl
{
...
enum
enum .
enum
ListboxTypeEditor FillInList
. .
public class FormatListboxTypeEditor : ListboxTypeEditor
{
protected override void FillInList(ITypeDescriptorContext context,
)IServiceProvider provider, ListBox listBox
{
;)"listBox.Items.Add("Item 1
521
ASP.NET
;)"listBox.Items.Add("Item 2
;)"listBox.Items.Add("Item 3
;listBox.BorderStyle = BorderStyle.None
}
}
)(ToolBox
.
.
Bitmap 16 16*16 .
Build Action Embedded Resource .
ToolboxItem ToolboxBitmap .
])[ToolboxItem(true
]))[ToolboxBitmap(typeof(ImageName
public class DividerPanel : System.Windows.Forms.Panel
{
...
Designer
522
ASP.NET
.
.
public class ControlNameDesigner :
System.Windows.Forms.Design.ScrollableControlDesigner
{
}
. PreFilterProperties
protected override void PreFilterProperties(
System.Collections.IDictionary properties)
{
properties.Remove("BorderStyle");
}
Designer DesignerAttribute
.
[DesignerAttribute(typeof(ClassNameDesigner))]
public class ControlName : System.Windows.Forms.Panel
{
...
523
ASP.NET
Assembly
. assembly
AssemblyInfo.cs .
.
[assembly: AssemblyTitle("Control Title")]
[assembly: AssemblyDescription("Control Description")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Company")]
[assembly: AssemblyProduct("Product Name")]
[assembly: AssemblyCopyright("Copyright Info")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
.
// Flagging your assembly with the CLS Compliant attribute
// lets the Framework know that it will work with all
// CLS Compliant languages, and theoretically with all
// future framework platforms (such as Mono on Linux).
// If possible you should avoid using any non-CLS compliant code
// in your controls such as unsigned integers (uint) and
// calls to non-framework assemblies.
[assembly: System.CLSCompliant(true)]
524
ASP.NET
525
ASP.NET
:ASP.NET 2.0
Master Page
ASP.NET 2.0 .
Master Page .
. Master Page
.
.
. .
" .
ASP.NET User Control
) User Control ( . User
Control aspx
.
) ASP.NET 2 ( Master Page
. Master
Page ASP.NET 2 Web Developer 2005 Express Edition .
.
Shahabfar.com Iranian .NET Community 1
526
ASP.NET
:
Web Developer ASP.NET 2
.
- 1 Web Dev New Web Site New Web
Site .
- 2 Project Types ) C#
( .
.
- 3 Visual Studio installed templates ASP.NET Web Site .
- 4 Location . "
C:\WebSite\WebSite1
Web Dev Default.aspx .
Master Page.
527
ASP.NET
Master Page
Master Page
. Master Page . table
footer .
Content Placeholder
Master Page .
: Master Page
- 1 Solution Explorer Add
New Item .
- 2 Visual Studio Installed Templates Master Page
Master1.
- 3 Place code in separate file Code
behind .
- 4 Language .
Master Page Source View .
. body asp.contentplaceholder
528
ASP.NET
Master Page
Master Page aspx . Master Page
. Master Page
ContentPlaceholder .
.
table Master Page
. ContentPlaceHolder Master Page
table .
table Master Page .
- 1 Design View Master Page.
- 2 Master Page BgColor
.
- 3 Layout Insert Table .
529
ASP.NET
Master Page .
- 1 Copyright
.
- 2 Navigation toolbox Menu table
) ASP.NET 2 .
Menu" ( .
Orientation Menu Horizontal . Common
Menu Task Menu Edit Menu Items
.
- 3 Items
. Text Home NavigationUrl
530
ASP.NET
ContentPlaceHolder :
- 1 ContentPlaceHolder table
.
- 2 .
Maste Page
ASP.NET Master Page . Master
Page . aspx Master Page
. " home
about .
home.aspx :
- 1 Solution Explorer Add New Item
.
531
ASP.NET
532
ASP.NET
Master Page
. .
home.aspx .
ContentPlaceHolder CreateCustomContent
. ContentPlaceHolder Welcome to my website
.
about.aspx home .
Ctrl+F5 .
533
ASP.NET
534
ASP.NET
:ASP.NET 2.0
Master Page
Master Page
ASP.NET 2.0 .
Master Page .
.
.
Master Page ."
.
Master Page .
Master Page .
Master Page
button Master Page . Master Page
.
:
- 1 Solution Explorer Master1.master .
535
ASP.NET
- 2 paste .
- 6 properties DOCUMENT
.
- 7 BgColor .
536
ASP.NET
- 1 LinkButton Master2.master
" Change to MP1
- 2 button . .
)void LinkButton1_Click(object sender, EventArgs e
{
;"Session("masterpage") = "MasterPage1.master
;))(Response.Redirect(Request.Url.ToString
}
Master Page Session
.
- 3 Master1.master LinkButton
Change to MP2 .
- 4 .
)void LinkButton1_Click(object sender, EventArgs e
{
537
ASP.NET
;"Session("masterpage") = "MasterPage2.master
;))(Response.Redirect(Request.Url.ToString
}
- 5 About.aspx .
- 6 Page_PreInit .
[Session[masterpage
Me.MasterPageFile . " Page_PreInit .
WebForm Master Page .
Page_PreInit . Page_Init Page_Load
Page_PreInit .
538
ASP.NET
Master Page .
MSN.com
. Master Page
.
Web Developer 2005 Express Edition (ASP.NET 2) beta
www.shahabfar.com/express
MSDN:
539
ASP.NET
User Control
540
ASP.NET
UC .
Event .
.
UC .
. Event
UC .
) (Data Bound DataList Repeater DataGrid .
DataList .
DataList .
.
UC SelectionChangedEventArgs
. System.EventArgs .
.
.
UC .
public class SelectionChangedEventArgs : EventArgs
{
;public int SelectedIndex
}
541
ASP.NET
delegate . delegate
. delegate .
public delegate void SelectionChangedEventHandler(object sender,
;)SelectionChangedEventArgs e
;public event SelectionChangedEventHandler SelectionChanged
.
DataList UC . .
Event . .
)public void SelectMenuItem(int index
{
;)(dlMenu.DataBind
;)(SelectionChangedEventArgs ev = new SelectionChangedEventArgs
;ev.SelectedIndex = index
)if(SelectionChanged != null
;)SelectionChanged(this, ev
}
DataList .
. null SelectionChanged
542
ASP.NET
SelectionChangedEventHandler delegate .
.
.
543
ASP.NET
) (User Control
LoadControl
ASP.net .
HTML net. . .ascx
aspx tag
.
"<%@ Register TagPrefix="uc1" TagName="HeaderUserControl
>Src="HeaderUserControl.ascx" %
...
><uc1:HeaderUserControl id="Header1" runat="server"></uc1:HeaderUserControl
load . Page_Load
Button_Click . !
.net LoadControl )
tag html ASP. net .net ( .
FeaturedProduct.ascx . :
544
ASP.NET
place holder's controls collection . :
;)PlaceHolderLeftMenu.Controls.Add(FeaturedProductUserControl
CMS
IBuySpy .
ASPAlliance:
545
ASP.NET
.
.
[email protected]
[email protected]
m_bashiry@walla .com
:
http://bashiry.persiangig.com/Ebook
546