0% found this document useful (0 votes)
10 views94 pages

T 470 F 03

The document discusses questions about ASP.NET buttons, forms, and client-side scripting. It explains how buttons and forms work in different ASP.NET versions and how to open windows and check for confirmation using JavaScript. Event handling for buttons is also covered.

Uploaded by

hnhngtb1111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views94 pages

T 470 F 03

The document discusses questions about ASP.NET buttons, forms, and client-side scripting. It explains how buttons and forms work in different ASP.NET versions and how to open windows and check for confirmation using JavaScript. Event handling for buttons is also covered.

Uploaded by

hnhngtb1111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 94

PART 3

Q14 Button , ?
Q15 , ?
Q16 ASP.NET ?
Q17 ?
Q18 , Image ?
Q19 ?
Q20 , ASP.NET ?
Q21 ASP.NET Ajax ?
Q22 , ASP.NET AJAX ?
Q23 ?
Q24 ?
Q25 ?
Q26 HTML ?
Q27 ASP.NET 2.0 ?
Q28 Master Page ?
Q29 Content Page Master Page , ?
Q30 Menu SiteMap XML ?
Q14 Button
?
,

V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

,
, , ,
,

Web , ,
,
Web

, Web Server ,

ASP.NET , , ,
, , ,
Round-trip ( ),
, 1000 , 1000*n (n Round-trip )
, Round-trip 30K , 30MB
Round-trip ,

, ,
Post Back, (Page Refreshing) ,
, ,
, ( )
3-2
Button , ? Q14

Web ,
, , (Real-time
response) , ,
, , , Client
Script ( )

Client Script , HTML ,


, DOM ( )
, ,
Client Script JavaScript, Client Script ,
JavaScript

alert(" ");

confirm(" ");

,
, true
confirm() false

3-3
Part3

, ,

if (confirm(" "))

//

else

//

ASP.NET , <input type="submit" />


( ) HTML , , ,
ASP.NET , ViewState
ID , , event.returnValue = false;
, ,

<input type="submit" value=" "

onclick="event.returnValue=confirm( ' ?' );" />

<input type="submit" value=" "

onclick="return confirm( ' ?' );" />

3-4
Button , ? Q14

Server ,

// for ASP.NET 1.x

cmdSubmit.Attributes.Add(

"onclick", "return confirm( ' ?' );");

// for ASP.NET 2.0

cmdSubmit.OnClientClick =

"return confirm( ' ?' );";

, DOM
window.open() ,
(opener) window.open()

window.open(strURL, strName, strFeatures);

strURL ( )

strName ,

_blank ,

_parent URL (Frame) ,


, _self

_search URL , IE
7.0 ( )

_self URL

_top , URL ,
, _self

3-5
Part3

strFeatures , ,
,

menubar yes, no, 0, 1

toolbar yes, no, 0, 1

status yes, no, 0, 1

width

height

scrollbars yes, no, 0, 1

resizable yes, no, 0, 1

left x

top y

location yes, no, 0, 1 (IE 7 )

0 no, 1 yes

, ,
500 , 500 ,

window.open("CustomerForm.aspx", "CustomerForm",

"menubar=no, toolbar=no, status=no, scrollbars=no,

resizable=no, height=500px, width=500px");

, ,

3-6
Button , ? Q14

//

public void Page_Load(object sender, EventArgs e)

cmdSubmit.OnClientClick = "return confirm( ' ?' );";

<!-- HTML -->

<asp:Button ID="cmdSubmit" runat="server"

OnClientClick=" return confirm( ' ?' );"

OnClick="cmdSubmit_Click" />

//

public void Page_Load(object sender, EventArgs e)

cmdSubmit.OnClientClick = @"window.open( 'Form.aspx' , 'Form' ,

'toolbar=no, status=no, menubar=no, height=400px, width=500px,

scrollbars=yes, resizable=no' )");

, Exam 70-528: TS: Microsoft .NET Framework 2.0 Web Client


Development

Web

Client Script Round-trip

Q16 ASP.NET

3-7
Q15 ,
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

ASP.NET 2.0 Web , ,


, ( ),

, ,
, ,

Web ,
HTTP POST , PHP JSP
, (Process-Oriented)

3-8
, Q15

ASP.NET , ASP.NET
,
ASP.NET

<form runat="server">

</form>

, HTML FORM ,

<form name="aspnetForm" method="post" action="Form.aspx"

id="aspnetForm">

</form>

ASP.NET HTTP POST ,


, , Post Back, Page.IsPostBack HTTP
POST Round-trip, , Page.IsPostBack true,
, Page.IsPostBack false

,
,
, , ,
,
, , ,
, , , ,
,

3-9
Part3

, ,
, , ,

// Server-Side

Response.Redirect("Form.aspx");

// Client-Side (Scripting)

window.location.href="Form.aspx";

, Exam 70-528: TS: Microsoft .NET Framework 2.0 Web Client


Development

Web

Page.IsPostBack Round-trip

Client Script Round-trip

3-10
Q16 ASP.NET

V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

1. , ,
,

2. , (
),

ASP.NET , ,
HTTP , Windows Forms
Web , HTTP POST
Client-Server

, HTTP ( HTTP GET


HTTP POST) , ,
, (Full Page Refresh) ,
, , , ,
Web

, HTML
( HTML ), HTML ,
, Dynamic HTML ,
HTML , HTML ,
scripting language ( ), JavaScript
VBScript, , , JavaScript
, VBScript Windows Scripting Host

3-11
Part3

, ASP.NET Post-Back,
, JavaScript ,
JavaScript ASP.NET
ASP.NET , JavaScript

AJAX (Asynchronous JavaScript and XML) Web 2.0


, JavaScript , ,
Post-Back , ,
(Partial Page Refresh) , ASP.NET AJAX
, ASP.NET ,
ASP.NET AJAX

, ASP.NET

ASP.NET 1.x , ,
,

Page.RegisterClientScriptBlock()

Page.RegisterStartupScript()

Page.RegisterOnSubmitStatement()

, <script> </script>
, , Page.RegisterStartupScript()
, , Page.RegisterClientScriptBlock() <head>
</head> , Page.RegisterOnSubmitStatement()
Post-Back ( )
DHTML scripting ,
, Response.Write() ,
( ) ( Literal
), , Page

3-12
ASP.NET Q16

ASP.NET 2.0, , ClientScriptManager


(Page.ClientScript) , , ASP.NET
2.0 Callback , ClientScriptManager
, ClientScriptManager
, ,
, (Callback) ASP.NET AJAX

, Literal ,
Literal ,

<! in HTML -->

<asp:Literal ID="ScriptSpace" runat="server"

EnableViewState="false" />

// in code-behind class

this.ScriptSpace.Text =

"<script> alert('Thanks for your cooperation.'); </script>";

,
RegisterClientScriptBlock() , Response.Write()
( )

, , ,
ClientScript.RegisterClientScriptInclude() , ASP.NET 2.0
, ASP.NET 1.x, HTML

, ,
, , (
Button OnClientClick) , , 1

3-13
Part3

1 ,

<!-- in HTML -->

<asp:Button ID="cmdLoadList" runat="server"

OnClientClick="return LoadList();"

Text=" ListBox" /><br />

<asp:ListBox ID="listData" runat="server" Rows="5" Width="400px" />

<asp:Literal ID="ScriptSpace" runat="server" />

// in code

protected void Page_Load(object sender, EventArgs e)

string myScript = @"

<script>

var data = new Array(

'data1', 'data2', 'data3', 'data4', 'data5',

'data6', 'data7', 'data8', 'data9', 'data10' );

function LoadList()

var listBox = document.getElementById('listData');

for (var i=0; i<data.length; i++)

var opt = document.createElement('OPTION');

opt.text = data[i];

opt.value = data[i];

listBox.options.add(opt);

3-14
ASP.NET Q16

return false;

</script>

";

// Literal

this.ScriptSpace.Text = myScript;

, JavaScript ,
, , JavaScript
, , , ,
AJAX

Q14 Button , ?

Q17 ?

Q20 , ASP.NET

Q23 ?

3-15
Q17
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

, , ,
,

MSDN ,
, ,
, Request.Browser ,

, ActiveX Control,
ActiveX Control ,
, ,
, ,

,
, , HTTP,
, ,
, HTTP GET HTTP POST, HTTP
POST , ,
, HiddenField ,

, , ,
, Q16 ASP.NET

3-16
Q17

, (
), , ,

, HiddenField (
),

, , 1

1 ,

<!-- HTML -->

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

<head runat="server">

<title> </title>

<script language="javascript" type="text/javascript">

function executeScript()

3-17
Part3

document.getElementById("hiddenField").value = "10000";

document.form1.submit();

</script>

</head>

<body>

<form id="form1" runat="server">

<asp:Button ID="cmdExecuteScript" runat="server"

Text=" "

OnClientClick="executeScript(); event.returnValue=false;" />

<asp:Label ID="labelResult" runat="server" />

<asp:HiddenField ID="hiddenField" runat="server" />

<asp:Literal ID="ScriptSpace" runat="server"

EnableViewState="false" />

</form>

</body>

</html>

// in code

protected void Page_Load(object sender, EventArgs e)

if (Page.IsPostBack) // , "!"

this.labelResult.Text = this.hiddenField.Value;

, , (executeScript()) ,
HiddenField , ,
, (document.
form1.submit()) , ,
HiddenField

3-18
Q17

, , ,
, 2

2 ,

<!-- HTML -->

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


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

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

<head runat="server">

<title> </title>

<script language="javascript" type="text/javascript">

function executeScript()

document.getElementById("hiddenField").value =

window.navigator.userAgent;

document.form1.submit();

</script></head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="labelBrowserString" runat="server" />

<asp:HiddenField ID="hiddenField" runat="server" />

<asp:Literal ID="ScriptSpace" runat="server"

EnableViewState="false" />

</div>

</form>

</body>

</html>

3-19
Part3

// in code

protected void Page_Load(object sender, EventArgs e)

if (Page.IsPostBack)

this.labelBrowserString.Text = this.hiddenField.Value;

else

string script = @"

<script>

executeScript();

</script>";

this.ScriptSpace.Text = script;

, Literal , ,

ASP.NET 2.0 , <%@ Page %> ,


EnableEventValidation="false", ASP.NET 2.0
,

Q16 ASP.NET

3-20
Q18 , Image
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

, ,
, ,

, , ,
,
, ,

, ,
, , ,
, , ,

, , ,
( ), , HTTP ,

System.Net HTTP ,
HttpWebRequest HttpWebResponse , Request Re-
sponse HttpWebRequest Credentials ,
,

HttpWebRequest request =

WebRequest.Create(context.Request.QueryString["url"])

as HttpWebRequest;

3-21
Part3

if (context.Request.QueryString["uid"] != null)

request.Credentials = new NetworkCredential(

context.Request.QueryString["uid"],

context.Request.QueryString["pwd");

Image , HTTP Han-


dler (HTTP ) , Image URL HTTP
Handler , HTTP Handler ,
Image

Image1.ImageUrl = "MyHandler.ashx?url=xxx&uid=xxx&pwd=xxx";

HTTP Handler , HTTP ,


, , Page Rendering,
, , HTTP
Handler

HTTP Handler .ashx, IHttpHandler


ProcessRequest() IsReusable() ProcessRequest()
, Request Response HTTP
Handler

<%@ WebHandler Language="C#" Class="Handler" %>

using System;

using System.Web;

public class Handler : IHttpHandler {

3-22
, Image Q18

public void ProcessRequest (HttpContext context) {

// HTTP Request Response

// context.Request Request ,

// context.Response Response

public bool IsReusable {

get {

return false;

1. HTTP Handler

2. HttpWebRequest , , HttpWebRequest.
Credentials

HttpWebRequest request =

WebRequest.Create(context.Request.QueryString["url"])

as HttpWebRequest;

if (context.Request.QueryString["uid"] != null)

request.Credentials = new NetworkCredential(

context.Request.QueryString["uid"],

context.Request.QueryString["pwd");

3-23
Part3

3. HttpWebRequest.GetResponse() HttpWebResponse

4. HttpWebResponse.GetResponseStream()

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

//

byte[] data = new byte[(int)response.ContentLength];

int buffer = 8192; //

int readBytes = 0;

int offset = 0;

string contentType = response.ContentType;

Stream s = response.GetResponseStream();

5. ,

do

if (offset == response.ContentLength) //

break;

if (buffer >= (int)response.ContentLength) //

readBytes = s.Read(data, offset, (int)response.ContentLength);

else

readBytes = s.Read(data, offset,

Math.Max(buffer, (((int)response.ContentLength) - offset)));

offset += readBytes; //

while (readBytes > 0);

3-24
, Image Q18

6. HttpWebResponse,

7. ContentType, Response.BinaryWrite()

response.Close();

context.Response.Buffer = false;

context.Response.ContentType = contentType;

context.Response.BinaryWrite(data);

8. Image ImageUrl HTTP Handler

HTTP Handler

<%@ WebHandler Language="C#" Class="GetImageWithCredentials" %>

using System;

using System.IO;

using System.Web;

using System.Drawing;

using System.Net;

using System.Net.Sockets;

public class GetImageWithCredentials : IHttpHandler {

public void ProcessRequest (HttpContext context)

HttpWebRequest request =

WebRequest.Create(context.Request.QueryString["url"])

as HttpWebRequest;

3-25
Part3

if (context.Request.QueryString["uid"] != null)

request.Credentials = new NetworkCredential(

context.Request.QueryString["uid"],

context.Request.QueryString["pwd");

HttpWebResponse response =

request.GetResponse() as HttpWebResponse;

byte[] data = new byte[(int)response.ContentLength];

int buffer = 8192;

int readBytes = 0;

int offset = 0;

string contentType = response.ContentType;

Stream s = response.GetResponseStream();

do

if (offset == response.ContentLength)

break;

if (buffer >= (int)response.ContentLength)

readBytes = s.Read(data, offset, (int)response.ContentLength);

else

readBytes = s.Read(data, offset,

Math.Max(buffer, (((int)response.ContentLength) - offset)));

offset += readBytes;

while (readBytes > 0);

response.Close();

3-26
, Image Q18

context.Response.Buffer = false;

context.Response.ContentType = contentType;

context.Response.BinaryWrite(data);

public bool IsReusable {

get {

return false;

HttpWebRequest WebClient
WebClient HttpWebRequest, ,
DownloadFile() , , DownloadData()
,
,

, , WebClient
, , HttpWebRequest, HttpWebRequest , WebClient
Stream, DownloadData() DownloadFile() ( )

Q25 ?

3-27
Q19
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5 V ASP.NET AJAX

DBA ( ) ,
( , , Email ),
,

, ,
, , ,
, , ,

02-20392839

(02)20392839

0220392839

02-2039-2839

(02)2039-2839

...

xx xxx

xx xx xxx

xx xx xx xxx

xx xx xx xx xxx
3-28
Q19

, ,
, , ,
,

, ,
, , , , ,
, Email , Email
username@mailserverurl , ,

Email , Regular Ex-


pression ( ) (pattern) ,
RegularExpressionValidator , Email Regular Expres-
sion

^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2, 4}$

Regular Expression ,
, , (
), , http://www.regular-
expressions.info ,
Regular Expression ,

ASP.NET 2.0 ASP.NET AJAX , ASP.NET AJAX Con-


trol Toolkit MaskedEdit , ,
, ASP.NET 1.x,

MaskedEdit , ,
,
ASP.NET AJAX Control Toolkit , ASP.NET
( ), 1

3-29
Part3

1 MaskedEdit

<ajaxToolkit:MaskedEditExtender ID="maskedEdit" runat="server"

TargetControlID="TextBox2" // MaskedEdit ID

Mask="9, 999, 999.99" //

// Tooltip (true/false)

MessageValidatorTip="true"

// CSS

OnFocusCssClass="MaskedEditFocus"

// CSS

OnInvalidCssClass="MaskedEditError"

MaskType="Number" //

InputDirection="RightToLeft" //

AcceptNegative="Left" //

DisplayMoney="Left" //

// Tooltip (true/false)

ErrorTooltipEnabled="True"/>

TargetControlID Mask

MaskType { None, Date, Time, Number, DateTime }

Mask

C ( )

3-30
Q19

/ , 9999/99/99

: , 99:99

. , 999, 999.999

, , 999, 999, 999

\ , Mask ,
\NT\$999, 999, 999

9999/99/99 99:99

\$999, 999, 999

(99)9999-9999

FM0091-9992-AG01 LL9999-9999-LL99

MaskedEdit , MaskedEditValidator ,
Tooltip ,
2

2 MaskedEditValidator

<ajaxToolkit:MaskedEditValidator

ControlExtender="MaskedEditExtender2" // MaskedEdit ID

ControlToValidate="TextBox2" // ID

IsValidEmpty="False" // (true/false)

MaximumValue="12000" //

// Tooltip

EmptyValueMessage="Number is required"

// Tooltip

InvalidValueMessage="Number is invalid"

// MaximumValue Tooltip

MaximumValueMessage="Number > 12000"

3-31
Part3

// MinimumValue Tooltip

MinimumValueMessage="Number < 100"

MinimumValue="100" //

// ,

EmptyValueBlurredText="*"

// ,

InvalidValueBlurredMessage="*"

// MaximumValue,

MaximumValueBlurredMessage="*"

// MinimumValue,

MinimumValueBlurredText="*"

Display="Dynamic" //

//

TooltipMessage="Input a number: 100 - 12.000"

/>

, 0-25000 MaskedEdit ,
, , 3

3 0-25000 MaskedEdit MaskedEditValidator

<asp:TextBox ID="T_Amount" runat="server" Columns="15" />

<ajaxToolkit:MaskedEditExtender ID="ME_T_Amount"

TargetControlID="T_Amount" InputDirection="rightToLeft"

runat="server" MaskType="Number" AcceptNegative="None"

Mask="\NT\$99, 999" MessageValidatorTip="true"

ErrorTooltipEnabled="true" />

<ajaxToolkit:MaskedEditValidator ID="MEV_T_Amount" Display="none"

MinimumValue="0" MaximumValue="25000" runat="server"

ControlExtender="ME_T_Amount" MaximumValueMessage=" 25000"

MaximumValueBlurredMessage=" 25000"

ControlToValidate="T_Amount"

TooltipMessage=" 0-25000 " />


3-32
Q19

ASP.NET 1.x, Regular Expression


, ASP.NET 2.0, ASP.NET AJAX Control Toolkit
MaskedEdit MaskedEditValidator

, , ,
, , , ,
, ( ), (
)

, , ,
, , ,
, (Clean) (Data Quality) , ,
,

ASP.NET AJAX ,

Q12 ASP.NET AJAX ASP.NET 2.0

3-33
Q20 ASP.NET
,

V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

ASP.NET , Web
, , (
), ,
, ASP.NET

ASP.NET , ,
, , RangeValidator,
RequiredFieldValidator CompareValidator
, RegularExpressionValidator ,
Regular Expression

, , ,
,
, , , ,

, ASP.NET
CustomValidator , ,

CustomValidator , ,
, CustomValidator

3-34
, ASP.NET Q20

function [funcation_name](oSrc, args)

// oSrc: , args:

var validated = false;

//

if (validated = true)

args.IsValid = true; //

else

args.IsValid = false; //

args.IsValid , CustomValidator

, CustomValidator ServerValidate ,

<asp:CustomValidator

ClientValidationFunction="client_validation_function"

OnServerValidate="event_handler" />

ClientValidationFunction

OnServerValidate ServerValidate

, , CustomValidator
, , CustomValidator

Q16 ASP.NET

3-35
Q21 ASP.NET Ajax

V ASP.NET 2.0 V ASP.NET 3.5 V ASP.NET AJAX

, ASP.NET
AJAX , , ASP.
NET AJAX ,

ASP.NET AJAX UpdatePanel


UpdateProgress , , ASP.
NET AJAX ASP.NET 2.0 , Member-
ship Profile, ASP.NET AJAX Application Service
, ,

(Forms Authentication) Application Service ,


Membership Service,
, , Membership Service
ASP.NET 2.0 ASP.NET AJAX Application Service
UpdatePanel UpdateProgress , ,
, ,

ASP.NET AJAX Application Service Sys.Service


AuthenticationService ProfileService , Forms Authentica-
tion Profile Service , AuthenticationService XMLHTTP
, ,

3-36
ASP.NET Ajax Q21

login() ( 1)

logout() ( 2)

defaultLoginCompletedCallback , Callback

defaultLogoutCompletedCallback , Callback

defaultFailedCallback , Callback

isLoggedIn

timeout

1 Sys.Services.AuthenticationService.login

Sys.Services.AuthenticationService.login(

userName, //

password, //

isPersistent, // (true/false)

redirectUrl, // URL, null

customInfo, // , null

loginCompletedCallback, // Callback

failedCallback, // Callback

userContext //

);

2 Sys.Services.AuthenticationService.logout

Sys.Services.AuthenticationService.logout(

redirectUrl, // URL, null

logoutCompletedCallback, // Callback

failedCallback, // Callback

userContext //

);

3-37
Part3

, Web Service (
), Sys.Services.AuthenticationService.login()
, 3

3 Web Service

<%@ WebService Language="C#" Class="MyAuthenticationService" %>

using System.Web.Services;

using System.Web.Script.Services;

[ScriptService] // Web Service ASP.NET AJAX

public class MyAuthenticationService : System.Web.Services.WebService

[WebMethod]

public bool Login(string userName, string password,

bool createPersistentCookie)

// , , true, false

return true;

[WebMethod]

public void Logout()

//

3-38
ASP.NET Ajax Q21

1. Script Manager, ASP.NET AJAX


,

2.

3. JavaScript ,
, 4 5

// ASP.NET Ajax library

if (typeof(Sys) !== "undefined")

Sys.Application.notifyScriptLoaded();

var panelLogin = null;

var panelLogout = null;

function pageLoad()

panelLogin = $get("panelLogin");

panelLogout = $get("panelLogout");

function login()

3-39
Part3

var username = $get("<% = this.T_UserName.ClientID %>").value;

var password = $get("<% = this.T_Password.ClientID %>").value;

//

Sys.Services.AuthenticationService.login(

username, password, false, null, null,

OnLoginCompleted, OnFailed, "User Context");

function logout()

//

Sys.Services.AuthenticationService.logout(

null, OnLogoutCompleted, OnFailed, null);

function OnFailed(error, userContext, methodName)

//

alert(" , " + error.get_message());

function OnLoginCompleted(validCredentials, userContext, methodName)

//

if (validCredentials == true)

panelLogin.className = "displayHide";

panelLogout.className = "displayVisible";

else

alert(" ");

}
3-40
ASP.NET Ajax Q21

function OnLogoutCompleted(result)

panelLogin.className = "displayVisible";

panelLogout.className = "displayHide";

...

<asp:Button ID="cmdLogin" OnClientClick="login(); return false;"

runat="server" Text=" " />

...

<asp:Button ID="cmdLogout" runat="server" Text=" "

OnClientClick="return confirm(' ,
');" />

...

4. Web Service ( 6) ,
ASP.NET AJAX , ,
,

6 ASP.NET AJAX Web Service

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.Script.Services;

[ScriptService]

public class LoginService : System.Web.Services.WebService

3-41
Part3

[WebMethod]

public bool Login(string userName, string password,

bool createPersistentCookie)

// ,

if (userName == "test" && password == "password")

return true;

else

return false;

5. ScriptManager, AuthenticationService Web


Service, , Membership Service ,
7

7 AuthenticationService, Web Service

<asp:ScriptManager ID="ScriptManager1" runat="server">

<AuthenticationService Path="LoginService.asmx" />

</asp:ScriptManager>

6. , ,
"test",
"password", ,
,

ASP.NET AJAX ,

Q12 ASP.NET AJAX ASP.NET 2.0

3-42
Q22 NET AJAX
, ASP.

V ASP.NET 2.0 V ASP.NET 3.5 V ASP.NET AJAX

PHP ASP , ,
, ASP.NET 2.0 ASP.NET AJAX,
, ASP.NET AJAX

ASP , Web ,
(Request, Response, Application, Server Session) , AJAX
, ,
, , ,
, ,

ASP.NET ASP.NET
, , , ASP.NET
, JavaScript , HTML ,
ASP.NET , ASP.NET

ASP.NET AJAX JavaScript ,


JavaScript , (Assembly Resource) ,
AJAX ScriptManager
, HTML , AJAX

(.js) , ScriptManager
ScriptReference

<asp:ScriptManager ID="ScriptManager1" runat="server">

<ScriptReference Path="~/scripts/myscripts.js" />

</asp:ScriptManager>

3-43
Part3

, ScriptManager ScriptReference

<asp:ScriptManager ID="ScriptManager1" runat="server">

<ScriptReference Assembly="MyScriptRes"

Name="MyScriptRes.MyScript.js" />

</asp:ScriptManager>

ASP.NET AJAX ,

1. ScriptManager , , Assembly
Name , , Path

2. HTML

3. <script type="text/javascript" src="..." /> ,


HTML

ASP.NET AJAX ,

Q12 ASP.NET AJAX ASP.NET 2.0

3-44
Q23
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5 V ASP.NET AJAX

, , ,
, , ,
PostBack , , PostBack

, ,
( ), ,
, (Dynamic Control Creation)
,

, ,
Post-Back Round-trip , ,
, Round-trip ,
, Post-Back

, coding , Round-trip ,
, ,
JavaScript , HTTP POST

JavaScript ,

JavaScript ,

HTML

DOM

HTTP

XML ( AJAX )

3-45
Part3

, document.createElement()

var newobject = document.createElement(tagName);

tagName HTML

// Button

var obj = document.createElement("INPUT TYPE=button");

var obj = document.createElement("SELECT"); //

var obj = document.createElement("INPUT TYPE=text");

var obj = document.createElement("TABLE");

, ( DIV SPAN ),
innerHTML , document.
createElement()

<div id="ctlContainer"></div>

<script language="JavaScript" type="text/javascript">

// ID ctlContainer DIV

var obj = document.getElementById("ctlContainer");

3-46
Q23

//

obj.innerHTML =

"<input type='text' id='T_Value' style='width: 300px'>" +

"<input type='button' id='cmdSubmit' value=' '>";

</script>

, ,

object.eventName = eventHandler;

object

eventName

eventHandler

cmdSubmit.onclick = cmdSubmit_Click;

object.eventName = new function() {

//

};

, ,

3-47
Part3

, , XML ,
XML , ,
1, 2

1 XML

<Questions>

<Question ID="1" Caption=" (9 , 1


, 5 )" ResponseType="SingleChoice">

<AnswerList>

<Answer Caption="9" Value="9" />

<Answer Caption="8" Value="8" />

<Answer Caption="7" Value="7" />

<Answer Caption="6" Value="6" />

<Answer Caption="5" Value="5" />

<Answer Caption="4" Value="4" />

<Answer Caption="3" Value="3" />

<Answer Caption="2" Value="2" />

<Answer Caption="1" Value="1" />

</AnswerList>

</Question>

<Question ID="2" Caption=" "


ResponseType="MultipleChoice">

<AnswerList>

<Answer Caption=" " Value="A" />

<Answer Caption=" " Value="B" />

<Answer Caption=" " Value="C" />

<Answer Caption=" " Value="D" />

<Answer Caption=" " Value="E" />

</AnswerList>

3-48
Q23

</Question>

<Question ID="3" Caption=" "


ResponseType="MultipleText" />

</Questions>

2 XML

<Responses>

<Response ID="1"></Response>

<Response ID="2"></Response>

<Response ID="3"></Response>

</Responses>

XML , , ,
, , ,
Radio Button, CheckBox , ,
, 3

3 Radio Button CheckBox ( , QuestionLoad() )

case "SingleChoice":

answerList = nodes[i].selectNodes("AnswerList/Answer");

for (var j=0; j<answerList.length; j++)

html += "<INPUT TYPE='radio' name='o" +

nodes[i].attributes.getNamedItem("ID").value +

"' onclick='setResponse(" +

nodes[i].attributes.getNamedItem("ID").value +

", \"radio\", \"" +

answerList[j].attributes.getNamedItem("Value").value +

"\")' />" +

answerList[j].attributes.getNamedItem("Caption").value;

3-49
Part3

html += "<br><br>";

break;

case "MultipleChoice":

answerList = nodes[i].selectNodes("AnswerList/Answer");

for (var j=0; j<answerList.length; j++)

html += "<INPUT TYPE='checkbox' name='c" +

nodes[i].attributes.getNamedItem("ID").value + "' id='c" +

nodes[i].attributes.getNamedItem("ID").value + "_" + j +

"' onclick='setResponse(" +

nodes[i].attributes.getNamedItem("ID").value +

", \"checkbox\", null)' value='" +

answerList[j].attributes.getNamedItem("Value").value + "' />" +

answerList[j].attributes.getNamedItem("Caption").value;

html += "<br><br>";

break;

, TEXTAREA , ,
4

4 ( , QuestionLoad() )

case "MultipleText":

html += "<TEXTAREA style='width: 400px; height: 100px'


onchange='setMultipleTextResponse("

3-50
Q23

+ nodes[i].attributes.getNamedItem("ID").value + ")'></TEXTAREA>";

break;

, , , ,
setResponse(), setMultipleTextResponse
(), XML , 5

5 setResponse() setMultipleTextResponse()

function setResponse(id, type, value)

var xmlDoc = document.getElementById("QAnswer").XMLDocument;

if (type == "radio")

xmlDoc.documentElement.selectSingleNode(

"//Responses/Response[@ID='" + id + "']").text = value;

else

var objs = document.getElementsByName("c" + id);

var list = "";

// "A, B, C" ( )

for (var i=0; i<objs.length; i++)

if (objs[i].checked)

alert(objs[i].value);

list += (list == "") ? objs[i].value : ", " + objs[i].value;

3-51
Part3

xmlDoc.documentElement.selectSingleNode(

"//Responses/Response[@ID='" + id + "']").text = list;

function setMultipleTextResponse(id)

var xmlDoc = document.getElementById("QAnswer").XMLDocument;

xmlDoc.documentElement.selectSingleNode(

"//Responses/Response[@ID='" + id + "']").text =

event.srcElement.value;

, , ,
HiddenField , , XML
HiddenField , , 6

6 finish

function finish()

document.getElementById("response").value =

document.getElementById("QAnswer").XMLDocument.xml;

return true;

...

<asp:HiddenField ID="response" runat="server" />

<asp:Button ID="cmdSubmit" runat="server"

OnClientClick="return finish()" Text=" "

OnClick="cmdSubmit_Click" />

3-52
Q23

, , , 7

<script type="text/javascript" language="javascript">

QuestionLoad();

</script>

, ,
XML , System.Xml XmlDocument

,
, ,
, HTML DOM ,
, ,

3-53
Q24
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

, , ,
, ,

, , FAQ
, , OOP ,
, new ,

ASP.NET, Web-Based ,
, Web-Based (State-less) ,
, Web-Based
(Session, ViewState) , , ,
, ,

, , ,
, ,
,

, ASP.NET ,

1. Request Web Server ,


, , ASP.NET ,

3-54
Q24

2. , ID,
, ID , ,
,

3. ASP.NET , ,
, ,

4. ASP.NET ,
, ,

Button cmdSubmit = new Button(); // Button

cmdSubmit.ID = "cmdSubmit";

//

cmdSubmit.OnClick += new EventHandler(cmdSubmit_Click);

cmdSubmit.Text = " ";

Page.Controls.Add(cmdSubmit); // Page

, , ,
, PostBack,
ViewState PostBack , (
)

Page_Load Page_Init ,
MSDN Library Creating Dynamic Data Entry User Interfaces
, Page_Init, Page_Load ,
Page.IsPostBack ( )

3-55
Part3

public class _default : System.Web.UI.Page

protected void Page_Init(object sender, EventArgs e)

//

protected void Page_Load(object sender, EventArgs e)

if (!Page.IsPostBack)

//

public class _default : System.Web.UI.Page

protected void Page_Init(object sender, EventArgs e)

TextBox textbox = new TextBox();

textbox.ID = "myTextBox";

this.PlaceHolder1.Controls.Add(textbox);

protected void Page_Load(object sender, EventArgs e)

if (!Page.IsPostBack)

3-56
Q24

TextBox textbox =

this.PlaceHolder1.FindControl("myTextBox") as TextBox;

textbox.Text = "default value";

Q23 ,

, , XML ,
XML , ,
1
2,

, Page_Init , 1

1 Page_Init ,

protected void Page_Init(object sender, EventArgs e)

//

XmlDocument doc = new XmlDocument();

doc.LoadXml(this.QContent.DocumentContent);

XmlNodeList nodes =

doc.DocumentElement.SelectNodes("//Questions/Question");

XmlNodeList answers = null;

Panel panel = null;

foreach (XmlNode node in nodes)

3-57
Part3

panel = new Panel();

panel.ID = "Q" + node.Attributes.GetNamedItem("ID").Value;

panel.Width = new Unit(100, UnitType.Percentage);

Label labelCaption = new Label();

labelCaption.Text = node.Attributes.GetNamedItem("ID").Value +

". " + node.Attributes.GetNamedItem("Caption").Value +

"<br><br>";

panel.Controls.Add(labelCaption);

switch (node.Attributes.GetNamedItem("ResponseType").Value)

case "SingleChoice":

answers = node.SelectNodes("AnswerList/Answer");

for (int i = 0; i < answers.Count; i++)

RadioButton opt = new RadioButton();

opt.ID = "O" + node.Attributes.GetNamedItem("ID").Value +

i.ToString();

opt.GroupName =

"O" + node.Attributes.GetNamedItem("ID").Value;

opt.Text =

answers[i].Attributes.GetNamedItem("Caption").Value;

panel.Controls.Add(opt);

break;

3-58
Q24

case "MultipleChoice":

answers = node.SelectNodes("AnswerList/Answer");

for (int i = 0; i < answers.Count; i++)

CheckBox chk = new CheckBox();

chk.ID = "C" + node.Attributes.GetNamedItem("ID").Value +

i.ToString();

chk.Text =

answers[i].Attributes.GetNamedItem("Caption").Value;

panel.Controls.Add(chk);

break;

case "MultipleText":

TextBox text = new TextBox();

text.ID = "M" + node.Attributes.GetNamedItem("ID").Value;

text.TextMode = TextBoxMode.MultiLine;

text.Width = new Unit(400, UnitType.Pixel);

text.Height = new Unit(200, UnitType.Pixel);

panel.Controls.Add(text);

break;

default:

break;

3-59
Part3

Literal moreLine = new Literal();

moreLine.Text = "<br><br>";

panel.Controls.Add(moreLine);

this.placeQuestionnaireCtls.Controls.Add(panel);

doc = null;

, , 2

protected void cmdSubmit_Click(object sender, EventArgs e)

// XML

XmlDocument doc = new XmlDocument();

XmlDocument docAnswer = new XmlDocument();

doc.LoadXml(this.QContent.DocumentContent);

docAnswer.LoadXml(this.QAnswer.DocumentContent);

XmlNodeList nodes =

doc.DocumentElement.SelectNodes("//Questions/Question");

foreach (XmlNode node in nodes)

Panel panel = Page.FindControl("Q"

+ node.Attributes.GetNamedItem("ID").Value) as Panel;

switch (node.Attributes.GetNamedItem("ResponseType").Value)

3-60
Q24

case "SingleChoice":

foreach (Control ctl in panel.Controls)

if (ctl.GetType() == typeof(RadioButton))

RadioButton opt = ctl as RadioButton;

if (opt.Checked)

docAnswer.SelectSingleNode("//Responses/Response[@ID='"

+ node.Attributes.GetNamedItem("ID").Value

+ "']").InnerText = opt.Text;

break;

case "MultipleChoice":

string list = null;

foreach (Control ctl in panel.Controls)

if (ctl.GetType() == typeof(CheckBox))

CheckBox opt = ctl as CheckBox;

if (opt.Checked)

list += (list == null) ? opt.Text : ", " + opt.Text;

3-61
Part3

docAnswer.SelectSingleNode("//Responses/Response[@ID='"

+ node.Attributes.GetNamedItem("ID").Value

+ "']").InnerText = list;

break;

case "MultipleText":

foreach (Control ctl in panel.Controls)

if (ctl.GetType() == typeof(TextBox))

TextBox textBox = ctl as TextBox;

docAnswer.SelectSingleNode("//Responses/Response[@ID='"

+ node.Attributes.GetNamedItem("ID").Value

+ "']").InnerText = textBox.Text;

break;

default:

break;

docAnswer = null;

doc = null;

3-62
Q24

, ,
,
, (Rendering) ,
, ,
,

, , ,
, ,
, AJAX , ,
( , )

3-63
Q25
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

, , ,
Web , ,
ASP.NET

, (
), , OWC
(Office Web Component) Chart ,
, ,
(Agent)

,
, ,
(
)

3-64
Q25

.NET Framework , System.


Drawing System.Drawing.Drawing2D System.Drawing.Imaging
,

Image

Bitmap GIF

Graphics

Font

Pen, Brush

Point, PointF ( F )

Size, SizeF ( F )

Rectangle, RectangleF ( F )

LinearGradientBrush

PathGradientBrush

, , Windows ,
DC (Device Context) (Bitmap) , DC ,
.NET Framework , Bitmap , ,
,

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Drawing.Imaging;

using System.IO;

...

3-65
Part3

// 300px, 300px

Bitmap bmp = new Bitmap(300, 300);

//

Graphics g = Graphics.FromImage(bmp);

Graphics ,
,
, ,
(10px * 10px)

// Rectangle

Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

//

g.FillRectangle(

new LinearGradientBrush(rect, Color.Green, Color.Yellow, 45),

rect);

//

g.DrawRectangle(Pens.Black,

new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1));

//

3-66
Q25

g.DrawRectangle(Pens.Blue, 20, 20, 10, 10);

g.DrawRectangle(Pens.Blue, 40, 50, 10, 10);

g.DrawRectangle(Pens.Blue, 80, 150, 10, 10);

g.DrawRectangle(Pens.Blue, 220, 121, 10, 10);

g.DrawRectangle(Pens.Blue, 150, 143, 10, 10);

g.DrawRectangle(Pens.Blue, 220, 156, 10, 10);

g.DrawRectangle(Pens.Blue, 210, 244, 10, 10);

g.DrawRectangle(Pens.Blue, 250, 180, 10, 10);

, ,
(Memory stream) , Response.BinaryWrite()

MemoryStream ms = new MemoryStream();

bmp.Save(ms, ImageFormat.Png); // PNG

ms.Flush(); //

byte[] data = ms.ToArray(); //

Response.ContentType = "image/png";

Response.BinaryWrite(data); //

, ,

HTTP Handler, HTTP


Handler , HTTP Handler
1

3-67
Part3

1 HTTP Handler

public class DrawingChart : IHttpHandler {

public void ProcessRequest (HttpContext context) {

MemoryStream ms = new MemoryStream();

Bitmap bmp = new Bitmap(300, 300);

bmp.SetResolution(600, 600);

Graphics g = Graphics.FromImage(bmp);

g.InterpolationMode = InterpolationMode.High;

g.SmoothingMode = SmoothingMode.HighQuality;

Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

g.FillRectangle(

new LinearGradientBrush(rect, Color.Green, Color.Yellow, 45),

rect);

g.DrawRectangle(Pens.Black,

new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1));

g.DrawRectangle(Pens.Blue, 20, 20, 10, 10);

g.DrawRectangle(Pens.Blue, 40, 50, 10, 10);

g.DrawRectangle(Pens.Blue, 80, 150, 10, 10);

g.DrawRectangle(Pens.Blue, 220, 121, 10, 10);

g.DrawRectangle(Pens.Blue, 150, 143, 10, 10);

g.DrawRectangle(Pens.Blue, 220, 156, 10, 10);

g.DrawRectangle(Pens.Blue, 210, 244, 10, 10);

g.DrawRectangle(Pens.Blue, 250, 180, 10, 10);

3-68
Q25

bmp.Save(ms, ImageFormat.Png);

g.Dispose();

bmp.Dispose();

ms.Flush();

context.Response.ContentType = "image/png";

context.Response.BinaryWrite(ms.ToArray());

ms.Close();

public bool IsReusable {

get {

return false;

, Exam 70-528: TS: Microsoft .NET Framework 2.0 Web


Application

Web

ASP.NET Handler

Q47

3-69
Q26 HTML
V ASP.NET 1.0 V ASP.NET 1.1 V ASP.NET 2.0 V ASP.NET 3.5

EDM ( ) , Email
DM, , DM ,
HTML , ,
HTML

,
, HTML ,
, , HTML ,

HTML IE4.0 5.0 , ,


DHTML Editing, Scriptable Editing,
HTML , (What You See, What You Get) ,
, ,
( ),
,

94 HTML ( http://www.htmlarea.com) ,
, , CSS
, Office-Style Windows-Style ,
, , 100-200 (
) , ,
, ,
,

3-70
HTML Q26

, HTML FCKeditor HTML

1. FCKeditor (http://www.fckeditor.net/) , ,
FCKeditor , FCKeditor.NET, ASP.NET

2. FCKeditor_2.5.1.zip ( ,
FCKeditor ), FCKeditor ASP.NET ,
, FCKeditor ,
FCKeditor ,

3. Visual Studio, ,
FCKeditor.NET , FredCK.FCKeditorV2.dll , ,
FCKeditor

3-71
Part3

3-72
HTML Q26

4. FCKeditor ,

3-73
Part3

5. ,

HTML , ASP.NET 2.0


ValidateRequest="false" HTML ,
, ASP.NET , BasePath
"~/FCKeditor", 404

FCKeditor
FCKeditor , ,
FCKeditor fckconfig.js ,
FCKeditor fckconfig.js,

3-74
HTML Q26

FCKConfig.ToolbarSets["Default"] = [

['Source', 'DocProps', '-', 'Save', 'NewPage', 'Preview', '-',

'Templates'],

['Cut', 'Copy', 'Paste', 'PasteText', 'PasteWord', '-', 'Print',

'SpellCheck'],

['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll',


'RemoveFormat'],

['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select',

'Button', 'ImageButton', 'HiddenField'],

'/',

['Bold', 'Italic', 'Underline', 'StrikeThrough', '-', 'Subscript',

'Superscript'],

['OrderedList', 'UnorderedList', '-', 'Outdent', 'Indent'],

['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull'],

['Link', 'Unlink', 'Anchor'],

['Image', 'Flash', 'Table', 'Rule', 'Smiley', 'SpecialChar',


'PageBreak',

'UniversalKey'],

'/',

['Style', 'FontFormat', 'FontName', 'FontSize'],

['TextColor', 'BGColor'],

['FitWindow', '-', 'About']

] ;

, "[" "]" , "/" , "-"


, ", " , ,
FCKeditor , JSON (JavaScript Object Notation) ,
,

3-75
Part3

, ,

FCKConfig.ToolbarSets["myToolbar"] = [

['Cut', 'Copy', 'Paste', 'PasteText', 'PasteWord', '-', 'Print',

'SpellCheck'],

['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll',


'RemoveFormat'],

'/',

['Style', 'FontFormat', 'FontName', 'FontSize'],

['TextColor', 'BGColor']

, FCKeditor
ToolbarSet , ,
Visual Studio

// ContentEditor FCKEditor

this.ContentEditor.ToolbarSet = "myToolbar";

3-76
Q27 ASP.NET 2.0
?
V ASP.NET 2.0 V ASP.NET 3.5

ASP.NET 2.0 , ,
, ,
,

Membership Services ( , System.Web.Security )


ASP.NET 2.0 ,
, Login CreateUserWizard ,
Membership Services, , Mem-
bership , MembershipProvider (abstract class)
, , Provider Pattern ,
Plug-in

ASP.NET 2.0 Membership Provider

SqlMembershipProvider: SQL Server

ActiveDirectoryMembershipProvider: Active Directory

, SqlMembershipProvider , ADO.NET SQL


Server , , SQL
Server Express, ,

3-77
Part3

SQL Server Membership Services


Membership Service SQL Server Express , ,
App_Data aspnetdb.mdf , Membership Services
SQL Server, SQL Server Express ,

.NET Framework SQL Server aspnet_regsql.


exe, , ASP.NET ( Membership Service,
Role Service, Web Part, Web Profile, Web Events )

aspnet_regsql -S "localhost" -E A m d "MyDB"

(-S) localhost , (-E) ,


MyDB (-d) , (-A m) , , ,

, ASP.NET ,
, Session State Cache Dependency SQL Server ,
, , aspnet_regsql.exe A all

, .NET Framework , aspnet_regsql, Google


, aspnet_regsql

3-78
ASP.NET 2.0 ? Q27

, ,
aspnetdb , ,

, Membership Services ,
Membership Provider, MembershipProivder
, ,

Membership Provider, ( ),
MembershipProvider

public class MyProvider : Membership Provider

, override , Membership Provider

3-79
Part3

Membership Provider, 8
17 , ,

EnablePasswordReset (true/false) Initialize()

EnablePasswordRetrieval (true/false) CreateUser()

RequiresQuestionAndAnswer (true/false) UpdateUser()

RequiresUniqueEmail (true/false) DeleteUser()

PasswordFormat (true/false) ValidateUser()

MaxInvalidPasswordAttempts (int) GetUser() * 2,

PasswordAttemptWindow (int) GetAllUsers()

ApplicationName (string) GetNumberOfUsersOnline()

ResetPassword()

GetUserNameByEmail()

ChangePassword()

ChangePasswordQuestionAndAnswer()

FindUsersByName()

FindUsersByEmail()

UnlockUser()

, ,
, MembershipUser

, Membership Membership.GetUser() MembershipUser


, Membership.GetUser() ,
GetUser

1 MembershipProvider.GetUser()

public override MembershipUser GetUser(string username,

bool userIsOnline)

3-80
ASP.NET 2.0 ? Q27

MembershipUser user = null; //

DataTable table = DataProvider.GetCustomerInfo(username);

// MembershipUser

if (table != null)

user = new MembershipUser(

"CustomProvider", table.Rows[0]["Name"].ToString(),

table.Rows[0]["CustomerID"].ToString(),

table.Rows[0]["Email"].ToString(),

table.Rows[0]["PwdQuestion"].ToString(),

table.Rows[0]["Comments"].ToString(),

true, false, new DateTime(2007, 1, 1, 0, 0, 0),

DateTime.Now, DateTime.Now,

Convert.ToDateTime(table.Rows[0]["LastPwdChangeDate"].ToString(),

Convert.ToDateTime(table.Rows[0]["LastLockedDate"].ToString()));

table = null;

return user;

MembershipProvider ,
, ,

// Membership Provider

public void UpdateProperties(

MembershipUser user, string Company, string Professions,

string SocialIDNum, string Cellphone)

DataProvider.UpdateProperties(

user.ProviderUserKey, Company, Professions,

SocialIDNum, Cellphone);

}
3-81
Part3

//

CustomProvider cp = Membership.Provider as CustomProvider;

cp.UpdateProperties(

user, this.Company.Text, this.Professions.Text,

this.SocialIDNum.Text, this.Cellphone.Text);

Membership Provider , Web.config ,


ASP.NET , .NET Framework SDK
OdbcMembershipProvider

<membership defaultProvider="OdbcProvider"

userIsOnlineTimeWindow="15">

<providers>

<add

name="OdbcProvider" // Membership Provider

type="OdbcMembershipProvider" // Membership Provider

// Membership Provider

connectionStringName="OdbcServices"

enablePasswordRetrieval="true"

enablePasswordReset="true"

requiresQuestionAndAnswer="true"

writeExceptionsToEventLog="true" />

</providers>

</membership>

Membership Provider ,
Visual Studio ASP.NET (Web Site Management
Tool) , , ASP.NET ( )

3-82
ASP.NET 2.0 ? Q27

, Membership Provider ,
Web.config Membership Provider

3-83
Part3

Membership Provider , ,
Web.config

, , Membership Provider

, ,
,

MembershipProvider , Membership Services


, Membership Provider Web.config
, ASP.NET 2.0

3-84
ASP.NET 2.0 ? Q27

, ASP.NET

Membership Provider OdbcMembershipProvider, MSDN

http://msdn2.microsoft.com/zh-tw/library/44w5aswa(VS.80).aspx

OdbcMembershipProvider

http://msdn2.microsoft.com/zh-tw/library/317sza4k(VS.80).aspx

Membership Provider ,

http://msdn2.microsoft.com/zh-tw/library/f1kyba5e(VS.80).aspx

MVP ASP.NET 2.0 , Membership


Provider

ASP.NET
ASP.NET 2.0 , ASP.NET 2.0 ,
Visual Studio 2005 ASP.NET 2.0 ,
ASP.NET , Membership, Role, Profile ,
(Provider) , ASP.NET ,
(URL ) , (
)

3-85
Part3

Membership Membership Provider


Membership Service Login, CreateUserWizard, LoginState ,
, Membership Service ,
, , Member-
ship Service , , ,
Membership Service , Provider Pattern
( , ) , ,
, Membership Provider

, Login Authenticate , LoginStatus


Page.IsAuthenticated , PasswordRecovery ChangePassword
, CreateUserWizard, Wizard

, , ,
( ASP.NET ) ,
, Membership Provider,

, Membership Service , ,
Membership Service , Membership Provider

, Exam 70-528: TS: Microsoft .NET Framework 2.0 Web Client


Development

Web

Web

Web

API Membership

3-86
Q28 Master Page ?
V ASP.NET 2.0 V ASP.NET 3.5

, ASP.NET 2.0,
, Master Page ( ) Content Page
( ) , Master Page,

Master Page,
, Master Page,

Master Page ASP.NET 2.0 FRAME


, ASP PHP ,
(Consistency Style) , , ,

<!-- #include virtual="header.asp" -->

<!-- #include virtual="menu.asp" -->

Web , Web
, Web ,
, , ,

3-87
Part3

Web , Layout (
), Master Page Layout, Content Page
, , Master Page
,
Master Page

, ,
, , Master Page, ,

Master Page, ,
Page_PreInit , Page.MasterPageFile
Master Page PreInit ,

private void Page_PreInit(object sender, EventArgs e)

// place master page changing code here.

, Master Page

private void Page_PreInit(object sender, EventArgs e)

Page.MasterPageFile = "~/masterPages/MasterPage_New.master";

3-88
Master Page ? Q28

, Master Page ,
Cookie , Master Page,

// Master Page

private void cmdSetMasterPage_Click (object sender, EventArgs e)

Response.Cookies.Add(

"MasterPage", "~/masterPage/MyMasterPage.master");

// Master Page , Master Page

private void Page_PreInit(object sender, EventArgs e)

Page.MasterPageFile = Request.Cookies["MasterPage"];

, Exam 70-528: TS: Microsoft .NET Framework 2.0 Web Client


Development

Master Page

Master Page

3-89
Q29 Page
Content Page
,
Master

V ASP.NET 2.0 V ASP.NET 3.5

Web Master Page, Master Page


, SiteMap Menu , , Menu
, , Master Page Menu,
Menu

Master Page , Master Page


, Master Page ,
Sitemap, ( ) , Web
Hosting

Master Page , Page ,


Master , Master Page, Page.Master
Master Page

, Master Page (ID imageHeader) ,

Control ctl = Page.Master.FindControl("imageHeader");

if (ctl != null)

Image imageHeader = ctl as Image;

imageHeader.ImageUrl = " ";

3-90
Content Page Master Page , Q29

Page.Master Master Page , Menu ID mainMenu


, Menu

Menu menu = Page.Master.FindControl("mainMenu");

, Menu

, Exam 70-528: TS: Microsoft .NET Framework 2.0 Web Client


Development

Master Page

Content Page Master Page

3-91
Q30 XML
Menu SiteMap

V ASP.NET 2.0 V ASP.NET 3.5

SiteMap , Web.sitemap ,
SiteMap , Menu Web.sitemap
,

, Site Map Menu , Menu


, Site Map , ,
, Web.sitemap, Menu ,

Web.sitemap SiteMap , XML ,


XmlDocument , , , Menu
Menu , 1

Web.sitemap , (Recursive
Function) ,

3-92
Menu SiteMap XML Q30

1 Web.sitemap Menu

protected void Page_Load(object sender, EventArgs e)

if (!Page.IsPostBack)

XmlDocument doc = new XmlDocument();

doc.Load(Server.MapPath("~/Web.sitemap"));

this.AppendMenuItem(null, doc.DocumentElement.ChildNodes);

doc = null;

private void AppendMenuItem(MenuItem rootItem, XmlNodeList itemNodes)

MenuItem item = null;

foreach (XmlNode node in itemNodes)

item = new MenuItem();

item.Text = node.Attributes.GetNamedItem("title").Value;

if (node.Attributes.GetNamedItem("url") != null)

item.NavigateUrl = node.Attributes.GetNamedItem("url").Value;

else

item.NavigateUrl = "javascript://";

3-93
Part3

if (node.ChildNodes.Count > 0)

this.AppendMenuItem(item, node.ChildNodes);

if (rootItem == null)

this.myMenu.Items.Add(item);

else

rootItem.ChildItems.Add(item);

Q42 XML ?

Q43 XML ?

3-94

You might also like