SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.netSireesh K
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsRandy Connolly
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net AjaxJeff Blankenburg
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server controlSireesh K
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controlsRaed Aldahdooh
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controlsGuddu gupta
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling WebStackAcademy
 
Powershell_Basics_Robin
Powershell_Basics_RobinPowershell_Basics_Robin
Powershell_Basics_RobinRobin Aggarwal
 
ASP.NET AJAX Basics
ASP.NET AJAX BasicsASP.NET AJAX Basics
ASP.NET AJAX Basicspetrov
 
Custom controls
Custom controlsCustom controls
Custom controlsaspnet123
 
Custom Controls in ASP.net
Custom Controls in ASP.netCustom Controls in ASP.net
Custom Controls in ASP.netkunj desai
 
ASP.NET Session 6
ASP.NET Session 6ASP.NET Session 6
ASP.NET Session 6Sisir Ghosh
 
Custom control in asp.net
Custom control in asp.netCustom control in asp.net
Custom control in asp.netSireesh K
 

Tendances (20)

2310 b 11
2310 b 112310 b 11
2310 b 11
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 
2310 b 06
2310 b 062310 b 06
2310 b 06
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
Introduction To Asp.Net Ajax
Introduction To Asp.Net AjaxIntroduction To Asp.Net Ajax
Introduction To Asp.Net Ajax
 
Ch3 server controls
Ch3 server controlsCh3 server controls
Ch3 server controls
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server control
 
Web controls
Web controlsWeb controls
Web controls
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
 
Powershell_Basics_Robin
Powershell_Basics_RobinPowershell_Basics_Robin
Powershell_Basics_Robin
 
ASP.NET AJAX Basics
ASP.NET AJAX BasicsASP.NET AJAX Basics
ASP.NET AJAX Basics
 
Custom controls
Custom controlsCustom controls
Custom controls
 
Custom Controls in ASP.net
Custom Controls in ASP.netCustom Controls in ASP.net
Custom Controls in ASP.net
 
ASP.NET Session 6
ASP.NET Session 6ASP.NET Session 6
ASP.NET Session 6
 
Custom control in asp.net
Custom control in asp.netCustom control in asp.net
Custom control in asp.net
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
 

En vedette

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

En vedette (8)

FXML for Structure, CSS for Styling and JavaFX as Standard GUI Library
FXML for Structure, CSS for Styling and JavaFX as Standard GUI LibraryFXML for Structure, CSS for Styling and JavaFX as Standard GUI Library
FXML for Structure, CSS for Styling and JavaFX as Standard GUI Library
 
Exploiting User Comments for Audio-visual Content Indexing and Retrieval (ECI...
Exploiting User Comments for Audio-visual Content Indexing and Retrieval (ECI...Exploiting User Comments for Audio-visual Content Indexing and Retrieval (ECI...
Exploiting User Comments for Audio-visual Content Indexing and Retrieval (ECI...
 
Visual storytelling: Why is it so powerful?
Visual storytelling: Why is it so powerful?Visual storytelling: Why is it so powerful?
Visual storytelling: Why is it so powerful?
 
Chapter 3 — Program Design and Coding
Chapter 3 — Program Design and Coding Chapter 3 — Program Design and Coding
Chapter 3 — Program Design and Coding
 
Overview of Visual Studio Team System 2010
Overview of Visual Studio Team System 2010Overview of Visual Studio Team System 2010
Overview of Visual Studio Team System 2010
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similaire à Visual studio 2008 asp net

The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showSubhas Malik
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828Viral Patel
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCSunpawet Somsin
 
SynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseindiappsdevelopment
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaJignesh Aakoliya
 
Using Java to implement SOAP Web Services: JAX-WS
Using Java to implement SOAP Web Services: JAX-WS�Using Java to implement SOAP Web Services: JAX-WS�
Using Java to implement SOAP Web Services: JAX-WSKatrien Verbert
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17Vivek chan
 
How to develop asp web applications
How to develop asp web applicationsHow to develop asp web applications
How to develop asp web applicationsDeepankar Pathak
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 
User controls
User controlsUser controls
User controlsaspnet123
 
CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!walk2talk srl
 
Qtp not just for gui anymore
Qtp   not just for gui anymoreQtp   not just for gui anymore
Qtp not just for gui anymorePragya Rastogi
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And WalkthroughsBryan Tuttle
 
Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh Kushwah
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04Mani Chaubey
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...SharePoint Saturday NY
 

Similaire à Visual studio 2008 asp net (20)

The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
SynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically developmentSynapseIndia creating asp controls programatically development
SynapseIndia creating asp controls programatically development
 
Asp.net tips
Asp.net tipsAsp.net tips
Asp.net tips
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
 
Using Java to implement SOAP Web Services: JAX-WS
Using Java to implement SOAP Web Services: JAX-WS�Using Java to implement SOAP Web Services: JAX-WS�
Using Java to implement SOAP Web Services: JAX-WS
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
How to develop asp web applications
How to develop asp web applicationsHow to develop asp web applications
How to develop asp web applications
 
ASP DOT NET
ASP DOT NETASP DOT NET
ASP DOT NET
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Controls
ControlsControls
Controls
 
User controls
User controlsUser controls
User controls
 
CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!CCI2019 - I've got the Power! I've got the Shell!
CCI2019 - I've got the Power! I've got the Shell!
 
2310 b 05
2310 b 052310 b 05
2310 b 05
 
Qtp not just for gui anymore
Qtp   not just for gui anymoreQtp   not just for gui anymore
Qtp not just for gui anymore
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And Walkthroughs
 
Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’s
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 

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