Upload
portaldoestudantesql
View
3.380
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Visual Studio® 2008: ASP.NET 3.5
Module 2: Implementing a User Interface with ASP.NET Server Controls
• Consuming Controls to Interact with Users
• Creating Custom Controls
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
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
Adding Server Controls to an ASP.NET Page
<form id="form1" runat="server"><div>
<asp:Button ID=“okButton" runat="server" Text="OK" />
</div>
</form>
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
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" />
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");
}
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
User Controls and Custom Server Controls
MyUserControl.ascx
MyCustomServerControl.dll
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)
{
}
Creating Custom Server Controls
• Creating a custom server control in Visual Studio 2008
• Adding metadata to your control
• Inheriting from built-in controls
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);
}
Placing a Custom Server Control in a Web Form
MyCustomServerControl.dll
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
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
Module Review and Takeaways
• Review Questions
• Real-world Issues and Scenarios
• Tools