SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

PPT
2310 b 11
Krazy Koder
 
PPTX
Ajax control asp.net
Sireesh K
 
PPT
2310 b 06
Krazy Koder
 
PPT
ASP.NET 03 - Working With Web Server Controls
Randy Connolly
 
PPT
Introduction To Asp.Net Ajax
Jeff Blankenburg
 
PPTX
Ch3 server controls
Madhuri Kavade
 
PPTX
Asp.net html server control
Sireesh K
 
PPT
Web controls
Sarthak Varshney
 
PPTX
Asp PPT (.NET )
Ankit Gupta
 
PPT
2310 b 16
Krazy Koder
 
PPT
Asp.net server controls
Raed Aldahdooh
 
PPTX
Asp.NET Validation controls
Guddu gupta
 
PDF
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
PPTX
Powershell_Basics_Robin
Robin Aggarwal
 
PPT
ASP.NET AJAX Basics
petrov
 
PPTX
Custom controls
aspnet123
 
PPT
Custom Controls in ASP.net
kunj desai
 
PPT
ASP.NET Session 6
Sisir Ghosh
 
PPTX
Custom control in asp.net
Sireesh K
 
PPTX
ASP.NET Lecture 6
Julie Iskander
 
2310 b 11
Krazy Koder
 
Ajax control asp.net
Sireesh K
 
2310 b 06
Krazy Koder
 
ASP.NET 03 - Working With Web Server Controls
Randy Connolly
 
Introduction To Asp.Net Ajax
Jeff Blankenburg
 
Ch3 server controls
Madhuri Kavade
 
Asp.net html server control
Sireesh K
 
Web controls
Sarthak Varshney
 
Asp PPT (.NET )
Ankit Gupta
 
2310 b 16
Krazy Koder
 
Asp.net server controls
Raed Aldahdooh
 
Asp.NET Validation controls
Guddu gupta
 
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
Powershell_Basics_Robin
Robin Aggarwal
 
ASP.NET AJAX Basics
petrov
 
Custom controls
aspnet123
 
Custom Controls in ASP.net
kunj desai
 
ASP.NET Session 6
Sisir Ghosh
 
Custom control in asp.net
Sireesh K
 
ASP.NET Lecture 6
Julie Iskander
 

Viewers also liked (8)

PDF
FXML for Structure, CSS for Styling and JavaFX as Standard GUI Library
Yuichi Sakuraba
 
PDF
Exploiting User Comments for Audio-visual Content Indexing and Retrieval (ECI...
Carsten Eickhoff
 
PPTX
Visual storytelling: Why is it so powerful?
David Navarro
 
PPTX
Chapter 3 — Program Design and Coding
francopw
 
PPTX
Overview of Visual Studio Team System 2010
joycsc
 
PPT
Slideshare Powerpoint presentation
elliehood
 
PDF
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 
PPTX
Slideshare ppt
Mandy Suzanne
 
FXML for Structure, CSS for Styling and JavaFX as Standard GUI Library
Yuichi Sakuraba
 
Exploiting User Comments for Audio-visual Content Indexing and Retrieval (ECI...
Carsten Eickhoff
 
Visual storytelling: Why is it so powerful?
David Navarro
 
Chapter 3 — Program Design and Coding
francopw
 
Overview of Visual Studio Team System 2010
joycsc
 
Slideshare Powerpoint presentation
elliehood
 
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 
Slideshare ppt
Mandy Suzanne
 
Ad

Similar to Visual studio 2008 asp net (20)

PPTX
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
PPS
12 asp.net session17
Niit Care
 
PPSX
12 asp.net session17
Vivek Singh Chandel
 
PPT
2006 - Basta!: Advanced server controls
Daniel Fisher
 
PPSX
03 asp.net session04
Vivek Singh Chandel
 
PPS
03 asp.net session04
Mani Chaubey
 
PPTX
UNIT1.pptx Introduction to ASP.NET IN IMR COLLEGE JALGOAN
dnyandip40
 
PPT
Session iii(server controls)
Shrijan Tiwari
 
PPT
Controls
Iblesoft
 
PPTX
Controls
teach4uin
 
PDF
ASP.NET User Controls - 20090828
Viral Patel
 
PPTX
ASP DOT NET
Pratik Tambekar
 
PPS
03 asp.net session04
Niit Care
 
PPT
How to develop asp web applications
Deepankar Pathak
 
PPT
Developing an ASP.NET Web Application
Rishi Kothari
 
PPTX
Web Server Controls CS Set
sunmitraeducation
 
PPT
2310 b 04
Krazy Koder
 
PDF
Asp .net web form fundamentals
Gopal Ji Singh
 
PDF
5a329780735625624 ch10
harkesh singh
 
PPT
Intro to asp.net
Information Technology
 
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
12 asp.net session17
Niit Care
 
12 asp.net session17
Vivek Singh Chandel
 
2006 - Basta!: Advanced server controls
Daniel Fisher
 
03 asp.net session04
Vivek Singh Chandel
 
03 asp.net session04
Mani Chaubey
 
UNIT1.pptx Introduction to ASP.NET IN IMR COLLEGE JALGOAN
dnyandip40
 
Session iii(server controls)
Shrijan Tiwari
 
Controls
Iblesoft
 
Controls
teach4uin
 
ASP.NET User Controls - 20090828
Viral Patel
 
ASP DOT NET
Pratik Tambekar
 
03 asp.net session04
Niit Care
 
How to develop asp web applications
Deepankar Pathak
 
Developing an ASP.NET Web Application
Rishi Kothari
 
Web Server Controls CS Set
sunmitraeducation
 
2310 b 04
Krazy Koder
 
Asp .net web form fundamentals
Gopal Ji Singh
 
5a329780735625624 ch10
harkesh singh
 
Intro to asp.net
Information Technology
 
Ad

Visual studio 2008 asp net

  • 1. Visual Studio® 2008: ASP.NET 3.5
  • 2. Module 2: Implementing a User Interface with ASP.NET Server Controls • Consuming Controls to Interact with Users • Creating Custom Controls
  • 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. 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
  • 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. 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
  • 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 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. 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. User Controls and Custom 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 Server Controls • Creating a custom server control in Visual Studio 2008 • Adding metadata to your control • Inheriting from built-in controls
  • 13. 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); }
  • 14. Placing a Custom Server Control in a Web Form MyCustomServerControl.dll
  • 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. 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
  • 17. Module Review and Takeaways • Review Questions • Real-world Issues and Scenarios • Tools