Professional ASP.NET 3.5 in C# and Visual Basic Part 23 - Pdf 16

Evjen c03.tex V2 - 01/28/2008 12:33pm Page 174
Chapter 3: ASP.NET Web Server Controls
Listing 3-39: Uploading the file contents into a Byte array
VB
Dim myByteArray() As Byte
Dim myStream As System.IO.MemoryStream
myStream = FileUpload1.FileContent
myByteArray = myStream.ToArray()
C#
Byte myByteArray[];
System.IO.Stream myStream;
myStream = FileUpload1.FileContent;
myByteArray = myStream.ToArray();
In this example, instances of a
Byte
array and a
MemoryStream
object are created. First, the
MemoryS-
tream
object is created using the FileUpload control’s
FileContent
property as you did previously. Then
it’s fairly simple to use the
MemoryStream
object’s
ToArray()
method to populate the
myByteArray()
instance. After the file is placed into a
Byte

Sub NextView(ByVal sender As Object, ByVal e As System.EventArgs)
MultiView1.ActiveViewIndex += 1
End Sub
<
/script
>
<
html xmlns=" />>
<
head runat="server"
>
<
title
>
MultiView Server Control
<
/title
>
<
/head
>
<
body
>
<
form id="form1" runat="server"
>
<
asp:MultiView ID="MultiView1" runat="server"
>

<
asp:View ID="View2" runat="server"
>
Billy’s Famous Pan Pancakes
<
p/
>
<
i
>
Mix 1/2 cup flour, 1/2 cup milk and 2 eggs in bowl.
<
br /
>
Pour in cast iron pan. Place in oven.
<
/i
><
p/
>
<
asp:Button ID="Button2" runat="server" Text="Next Step"
OnClick="NextView" /
>
<
/asp:View
>
<
asp:View ID="View3" runat="server"
>

>
C#
<
%@ Page Language="C#"%
>
<
script runat="server"
>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MultiView1.ActiveViewIndex = 0;
}
}
void NextView(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex += 1;
}
<
/script
>
175
Evjen c03.tex V2 - 01/28/2008 12:33pm Page 176
Chapter 3: ASP.NET Web Server Controls
Figure 3-41
This example shows three views expressed in the MultiView control. Each view is constructed with an
<
asp:View
> server control t hat also needs

method.
NextView
simply adds one
to the
ActiveViewIndex
value, thereby showing the next view in the series until the last view is shown.
The view series is illustrated in Figure 3-42.
In addition to the Next Step button on the first and second views, you could place a b utton in the second
and third views to enable the user to navigate backward through the views. To do this, create two but-
tons titled Previous Step in the last two views and point them to the following method in their
OnClick
events:
176
Evjen c03.tex V2 - 01/28/2008 12:33pm Page 177
Chapter 3: ASP.NET Web Server Controls
Figure 3-42
VB
Sub PreviousView(ByVal sender As Object, ByVal e As System.EventArgs)
MultiView1.ActiveViewIndex -= 1
End Sub
C#
void PreviousView(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex -= 1;
}
Here, the
PreviousView
method subtracts o ne from the
ActiveViewIndex
value, thereby showing the

In its simplest form, the Wizard control can be just an
<
asp:Wizard
> element with any number of
<
asp:WizardStep
> elements. Listing 3-41 creates a Wizard control that works through three steps.
Listing 3-41: A simple Wizard control
<
%@ Page Language="VB"%
>
<
html xmlns=" />>
<
head runat="server"
>
<
title
>
Wizard server control
<
/title
>
<
/head
>
<
body
>
<

<
/WizardSteps
>
178
Evjen c03.tex V2 - 01/28/2008 12:33pm Page 179
Chapter 3: ASP.NET Web Server Controls
<
/asp:Wizard
>
<
/form
>
<
/body
>
<
/html
>
In this example, three steps are defined with the <
asp:WizardSteps
> control. Each step contains
content — simply text in this case, although you can put in anything you want, such as other Web server
controls or even user controls. The order in which the
WizardSteps
are defined is based completely on
the order in which they appear within the
<
WizardSteps
> element.
The

asp:WizardStep
> elements in the Wizard
control:
<
asp:WizardStep runat="server" Title="Step 1"
>
This is the first step.
<
/asp:WizardStep
>
By default, each wizard step created in Design view is titled
Step X
(with
X
being the number in the
sequence). You can easily change the value of the
Title
attributes of each of the wizard steps to define
the steps as you see fit. Figure 3-44 shows the side navigation of the Wizard control with renamed titles.
Figure 3-44
Examining the AllowReturn Attribute
Another interesting point of customization for the side navigation piece of the Wizard control is the
AllowReturn
attribute. By setting this attribute on one of the wizard steps to
False
, you can remove the
capability for end users to go back to this step after they have viewed it. The end user cannot navigate
backward to any viewed steps that contain the attribute, but he would be able to return to any steps that
do not contain the attribute or that have it set to
True

attribute in the <
asp:WizardStep
> element to make your own determination about which
buttons are used for which steps.
In addition to
Auto
,
StepType
value options include
Start
,
Step
,
Finish
,and
Complete
.
Start
means
that the step defined has only a Next b utton. It simply allows the user to proceed to the next step in the
series. A value of
Step
means that the wizard step has Next and Previous buttons. A value of
Finish
means that the step includes a Previous and a Finish button.
Complete
enables you to give some final
message to the end user who is working through the steps of your Wizard control. In the Wizard control
shown in Listing 3-42, for example, when the end user gets to the last step and clicks the Finish button,
nothing happens and the user just stays on the last page. You can add a final step to give an ending

<
/asp:WizardStep
>
<
/WizardSteps
>
When you run this Wizard control in a page, you still see only the first three steps in the side navigation.
Because the last step has a
StepType
set to
Complete
, it does not appear in the side navigation list. When
the end user clicks the Finish button in Step 3, the last step —
Final Step
— is shown and no buttons
appear with it.
Adding a Header to the Wizard Control
The Wizard control enables you to place a header at the top of the control by means of the
HeaderText
attribute in the main <
asp:Wizard
> element. Listing 3-43 provides an example.
Listing 3-43: Working with the HeaderText attribute
<
asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0"
HeaderText="&nbsp;Step by Step with the Wizard control&nbsp;"
HeaderStyle-BackColor="DarkGray" HeaderStyle-Font-Bold="true"
HeaderStyle-Font-Size="20"
>


Chapter 3: ASP.NET Web Server Controls
After you decide which buttons to use within the Wizard navigation, you can choose their style. By
default, regular buttons appear; you can change the button style with the
CancelButtonType
,
Finish-
StepButtonType
,
FinishStepPreviousButtonType
,
NextStepButtonType
,
PreviousStepButtonType
,
and
StartStepNextButtonType
attributes. If you use any of these button types and want all the but-
tons consistently styled, you must change each attribute to the same value. The possible values of these
button-specific elements include
Button
,
Image
,and
Link
.
Button
is the default and means that the navi-
gation system uses buttons. A value of
Image
enables you to use image buttons, and

into logical pieces. The end user can then work systematically through each section of the f orm. The
developer, dealing with the inputted values of the form, has a few options because of the various events
that are a vailable in the Wizard control.
The Wizard control exposes events for each of the possible steps that an end user might take when
working with the control. The following table describes each of the available events.
Event Description
ActiveStepChanged
Triggers when the end user moves from one step to the next. It does not
matter if the step is the middle or final step in the series. This event
simply covers each step change generically.
CancelButtonClick
Triggers when the end user clicks the Cancel button in the navigation
system.
FinishButtonClick
Triggers when the end user clicks the Finish button in the navigation
system.
NextButtonClick
Triggers when the end user clicks the Next button in the navigation
system.
PreviousButtonClick
Triggers when the end user clicks the Previous button in the navigation
system.
SideBarButtonClick
Triggers when the end user clicks one of the links contained within the
sidebar navigation of the Wizard control.
183


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status