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: Common HTML Controls: Label Input (Text) Button Input (Button) TextBox Input (Submit) DropDownList Input (File) CheckBox, CheckBoxList Input (Password) RadioButton, RadioButtonList Input (Checkbox) HiddenField Input (Radio) Calendar Input (Hidden) AdRotator TextArea Wizard Table Panel Select Substitution 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

Visual studio 2008 asp net

  • 1.
  • 2.
    Module 2: Implementinga User Interface with ASP.NET Server Controls • Consuming Controls to Interact with Users • Creating Custom Controls
  • 3.
    Lesson: Consuming ControlsTo 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
  • 4.
    Common Standard andHTML Controls Common Standard Controls: Common HTML Controls: Label Input (Text) Button Input (Button) TextBox Input (Submit) DropDownList Input (File) CheckBox, CheckBoxList Input (Password) RadioButton, RadioButtonList Input (Checkbox) HiddenField Input (Radio) Calendar Input (Hidden) AdRotator TextArea Wizard Table Panel Select Substitution Div
  • 5.
    Adding Server Controlsto an ASP.NET Page <form id="form1" runat="server"> <div> <asp:Button ID=“okButton" runat="server" Text="OK" /> </div> </form>
  • 6.
    Demonstration: Coding ServerControls 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
  • 7.
    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" />
  • 8.
    Creating New ControlsProgrammatically <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"); }
  • 9.
    Lesson: Creating CustomControls • 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
  • 10.
    User Controls andCustom Server Controls MyUserControl.ascx MyCustomServerControl.dll
  • 11.
    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) { }
  • 12.
    Creating Custom ServerControls • Creating a custom server control in Visual Studio 2008 • Adding metadata to your control • Inheriting from built-in controls
  • 13.
    Rendering Content ina 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); }
  • 14.
    Placing a CustomServer Control in a Web Form MyCustomServerControl.dll
  • 15.
    Best Practices forCustom 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
  • 16.
    Lab: Consuming andCreating 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
  • 17.
    Module Review andTakeaways • Review Questions • Real-world Issues and Scenarios • Tools