17
Visual Studio® 2008: ASP.NET 3.5

Visual studio 2008 asp net

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Visual studio 2008 asp net

Visual Studio® 2008: ASP.NET 3.5

Page 2: Visual studio 2008 asp net

Module 2: Implementing a User Interface with ASP.NET Server Controls

• Consuming Controls to Interact with Users

• Creating Custom Controls

Page 3: Visual studio 2008 asp net

Lesson: Consuming Controls To Interact with Users

• Common Standard and HTML Controls

• Adding Server Controls to an ASP.NET Page

• Demonstration: Coding Server Controls

• Validating Data

• Creating New Controls Programmatically

Page 4: Visual studio 2008 asp net

Common Standard and HTML Controls

Common Standard Controls:

Label

Button

TextBox

DropDownList

CheckBox, CheckBoxList

RadioButton, RadioButtonList

HiddenField

Calendar

AdRotator

Wizard

Panel

Substitution

Common HTML Controls:

Input (Text)

Input (Button)

Input (Submit)

Input (File)

Input (Password)

Input (Checkbox)

Input (Radio)

Input (Hidden)

TextArea

Table

Select

Div

Page 5: Visual studio 2008 asp net

Adding Server Controls to an ASP.NET Page

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

<asp:Button ID=“okButton" runat="server" Text="OK" />

</div>

</form>

Page 6: Visual studio 2008 asp net

Demonstration: Coding Server Controls

In this demonstration you will see how to write code in the Button_Click event of a Button Control to set a property of a Label

Page 7: Visual studio 2008 asp net

Validating Data

Validation Controls:

RequiredFieldValidator

RangeValidator

RegularExpressionValidator

CompareValidator

CustomValidator

ValidationSummary

<asp:TextBox ID="numberTextBox" runat="server" />

<asp:RequiredFieldValidator ID="rfv1"runat="server"ErrorMessage="You must enter a value"ControlToValidate="numberTextBox" />

Page 8: Visual studio 2008 asp net

Creating New Controls Programmatically

<asp:PlaceHolder id="PlaceHolder1" runat="server" />

protected void Page_Load(object sender, EventArgs e)

{

Button submitButton = new Button();

submitButton.Text = "Click Here";PlaceHolder1.Controls.Add("submitButton");

}

Page 9: Visual studio 2008 asp net

Lesson: Creating Custom Controls

• User Controls and Custom Server Controls

• Creating User Controls

• Creating Custom Server Controls

• Rendering Content in a Custom Server Control

• Placing a Custom Server Control in a Web Form

• Best Practices for Custom Controls

Page 10: Visual studio 2008 asp net

User Controls and Custom Server Controls

MyUserControl.ascx

MyCustomServerControl.dll

Page 11: Visual studio 2008 asp net

Creating User Controls

NamesControl.ascx

<% @Control Language="C#" ClassName=“NamesControl"CodeBehind=“NamesControl.ascx.cs" %>

<asp:TextBox ID=“firstNameText" runat="server"

ReadOnly="True" />

<asp:TextBox ID=“lastNameText" runat="server" />

<asp:Button ID=“saveButton" runat="server"

Text="Save" OnClick=“saveButton_Click" />

NamesControl.ascx.cs

protected void saveButton_Click(object sender,

EventArgs e)

{

}

Page 12: Visual studio 2008 asp net

Creating Custom Server Controls

• Creating a custom server control in Visual Studio 2008

• Adding metadata to your control

• Inheriting from built-in controls

Page 13: Visual studio 2008 asp net

Rendering Content in a Custom Server Control

MyServerControl.cs

private TextBox nameTextBox;

protected override void

Render(HtmlTextWriter writer)

{

writer.RenderBeginTag(HtmlTextWriterTag.Div);

nameTextBox.RenderControl(writer);

writer.RenderEndTag();

}

protected override void CreateChildControls()

{

Controls.Clear();

nameTextBox = new TextBox();

nameTextBox.Text = "Insert your name here";this.Controls.Add(nameTextBox);

}

Page 14: Visual studio 2008 asp net

Placing a Custom Server Control in a Web Form

MyCustomServerControl.dll

Page 15: Visual studio 2008 asp net

Best Practices for Custom Controls

• Create custom server controls if you wish to protect your source code

• Create user controls if you wish to use markup to design your control

• Use a unique namespace when you create custom server controls

• Use metadata to inform developers about properties and methods in your control

Page 16: Visual studio 2008 asp net

Lab: Consuming and Creating ASP.NET Server Controls

• Exercise 1: Creating a User Interface by Using Server Controls in an ASP.NET Form

• Exercise 2: Creating User Controls and Custom Server Controls

Logon information

Virtual machine 6463A-LON-DEV-02

User name Student

Password Pa$$w0rd

Estimated time: 75 minutes

Page 17: Visual studio 2008 asp net

Module Review and Takeaways

• Review Questions

• Real-world Issues and Scenarios

• Tools