Visual studio 2008 asp net


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Visual studio 2008 asp net

  1. 1. Visual Studio® 2008: ASP.NET 3.5
  2. 2. Module 2: Implementing a User Interface withASP.NET Server Controls• Consuming Controls to Interact with Users• Creating Custom Controls
  3. 3. 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
  4. 4. Common Standard and HTML ControlsCommon 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. 5. Adding Server Controls to an ASP.NET Page<form id="form1" runat="server"><div> <asp:Button ID=“okButton" runat="server" Text="OK" /></div></form>
  6. 6. Demonstration: Coding Server ControlsIn this demonstration you will see how to write code in theButton_Click event of a Button Control to set a property of aLabel
  7. 7. Validating DataValidation 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. 8. 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");}
  9. 9. 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
  10. 10. User Controls and Custom Server Controls MyUserControl.ascx MyCustomServerControl.dll
  11. 11. Creating User ControlsNamesControl.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. 12. Creating Custom Server Controls• Creating a custom server control in Visual Studio 2008• Adding metadata to your control• Inheriting from built-in controls
  13. 13. Rendering Content in a Custom Server ControlMyServerControl.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. 14. Placing a Custom Server Control in a Web Form MyCustomServerControl.dll
  15. 15. 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
  16. 16. Lab: Consuming and Creating ASP.NET ServerControls• Exercise 1: Creating a User Interface by Using Server Controls in an ASP.NET Form• Exercise 2: Creating User Controls and Custom Server ControlsLogon informationVirtual machine 6463A-LON-DEV-02User name StudentPassword Pa$$w0rdEstimated time: 75 minutes
  17. 17. Module Review and Takeaways• Review Questions• Real-world Issues and Scenarios• Tools