You are on page 1of 27

Module 01 ‐ Advanced Web App Technologies with VS 2005

Friday, July 23, 2010
3:22 PM

2544 - Advanced Web Apps wtih VS 2005 Page 1


2544 - Advanced Web Apps wtih VS 2005 Page 2
2544 - Advanced Web Apps wtih VS 2005 Page 3
2544 - Advanced Web Apps wtih VS 2005 Page 4
Resource file • Each page can have its own default resource file.
• Can be pointed to specific Text items within the page.

Localization Can be of 2 types:
a. Explicit (requires more design work)
b. Implicit

2544 - Advanced Web Apps wtih VS 2005 Page 5


2544 - Advanced Web Apps wtih VS 2005 Page 6
Create Resource File • In VS Goto menu Tools ‐‐> Generate Local Resource
○ It creates the .Net folder App_LocalResources (with Default.aspx.resx)
• The resource file overrides the settings created during development.
• To make a resource file for use by other languages/cultures do the following:
1. Create a copy of an existing resource file (i.e.  Default.aspx.resx).
2. Rename it to Default.aspx.fr.resx. = French Resource Files

2544 - Advanced Web Apps wtih VS 2005 Page 7


2544 - Advanced Web Apps wtih VS 2005 Page 8
Panels & Placeholders • Allows the developer to set where controls will be placed dynamically during run‐time.
Example of Dynamic Control Creation • Default.aspx
Protected void Button1_Click(object sender EventArgs e)
{
int number = int.Parse(txtNumberofExtraTextboxes.Text);

for  (int i = 0; I < number; i++)
{
TextBox textBox = new TextBox();
textBox.ID = "TextBox" + i.ToString();
textBox.Text = "TextBox" + i.ToString();

LiteralControl newLine = new LiteralControl("<br />"); 

form1.Controls.Add(textBox);
form1.Controls.Add(newLine);
}
}

2544 - Advanced Web Apps wtih VS 2005 Page 9


2544 - Advanced Web Apps wtih VS 2005 Page 10
MasterType • Allows you to eliminate the requirement to  define a variable and a reference to the master  page in order 
to gain access to the master pages  properties, methods, and attributes.
• Prevents users from creating an instance of the master page in order to change the look and feel of a web 
form.
•   This enforces that a theme or a look and feel cannot be changed by the developer.

2544 - Advanced Web Apps wtih VS 2005 Page 11


2544 - Advanced Web Apps wtih VS 2005 Page 12
Module 01 ‐ Notes & Review Quiz
Tuesday, July 27, 2010
11:36 PM

Resource file • Each page can have its own default resource file.
• Can be pointed to specific Text items within the page.

Localization Can be of 2 types:
a. Explicit (requires more design work)
b. Implicit
Create Resource  • In VS Goto menu Tools ‐‐> Generate Local Resource
File ○ It creates the .Net folder App_LocalResources (with Default.aspx.resx)
• The resource file overrides the settings created during development.
• To make a resource file for use by other languages/cultures do the following:
1. Create a copy of an existing resource file (i.e.  Default.aspx.resx).
2. Rename it to Default.aspx.fr.resx. = French Resource Files
Panels &  • Allows the developer to set where controls will be placed dynamically during run‐
Placeholders time.
Example of  • Default.aspx
Dynamic Control  Protected void Button1_Click(object sender EventArgs e)
Creation {
int number = int.Parse(txtNumberofExtraTextboxes.Text);

for  (int i = 0; I < number; i++)
{
TextBox textBox = new TextBox();
textBox.ID = "TextBox" + i.ToString();
textBox.Text = "TextBox" + i.ToString();

LiteralControl newLine = new LiteralControl("<br />"); 

form1.Controls.Add(textBox);
form1.Controls.Add(newLine);
}
}
MasterType • Allows you to eliminate the requirement to  define a variable and a reference to 
the master  page in order to gain access to the master pages  properties, 
methods, and attributes.
• Prevents users from creating an instance of the master page in order to change 
the look and feel of a web form.
•   This enforces that a theme or a look and feel cannot be changed by the 
developer.

Review  Quiz 1. In which page event should master pages be changed dynamically?
a. Pre‐init
b. Load
c. Activate
d. Access
2. Which page directive attribute is set to enable localization?

2544 - Advanced Web Apps wtih VS 2005 Page 13


a. Culture
b. Resources
c. Uiculture
d. Uiresources
3. True or false; explicit localization points to a specific property in a resource file?
a. True
b. False
4. True or false; web site may have more than one web.config file?
a. True
b. False
5. Which method is used to add controls dynamically to the controls collection?
a. More
b. Insert
c. Add
d. Additional
6. Which method is used to access the controls of a master page?
a. GetControl
b. FindControl
c. SelectControl
d. It can not be done
7. Which object does not support a Controls collection?
a. PlaceHolder
b. Page
c. Panel
d. Image
8. Localization files are stored in what solution folder?
a. App_Code
b. App_Data
c. App_LocalResources
d. App_GlobalResources
9. True or false; a machine may have more than 1 machine.config file?
a. True
b. False
10. Explicit localization files are stored in which solution folder?
a. App_Code
b. App_Data
c. App_LocalResources
d. App_GlobalResources

2544 - Advanced Web Apps wtih VS 2005 Page 14


Module 02 ‐  Creating Controls for Web Applications
Thursday, July 29, 2010
11:16 PM

2544 - Advanced Web Apps wtih VS 2005 Page 15


2544 - Advanced Web Apps wtih VS 2005 Page 16
2544 - Advanced Web Apps wtih VS 2005 Page 17
2544 - Advanced Web Apps wtih VS 2005 Page 18
2544 - Advanced Web Apps wtih VS 2005 Page 19
2544 - Advanced Web Apps wtih VS 2005 Page 20
2544 - Advanced Web Apps wtih VS 2005 Page 21
2544 - Advanced Web Apps wtih VS 2005 Page 22
2544 - Advanced Web Apps wtih VS 2005 Page 23
2544 - Advanced Web Apps wtih VS 2005 Page 24
Module 02 ‐ Notes & Review Quiz
Tuesday, July 27, 2010
11:36 PM

User Controls  • Does not reference the @Page attribute but the @Control  attribute
• Can be cached for performance
• Can be reused
Add user control  • Can be done thru code
to Web Page • Can be done by dragging from "Solution Explorer"  or the Toolbox.  This will 
create the @Register directive on the page.

Example:
<%  @Register  Src="WbeUserControl.ascx"  TagName="WebUserControl"  
TagPrefix="uc1"  %>

• The user control is registered the to web page
Custom Web  • Differs from user control in that it is managed code, meaning there is no markup 
Server Control to it
• Does not really exist in the solution it is derived from WebControl class or another 
server controls
• Is faster because it is precompiled
• Offers better security
• It is simpler to work with a user control vs a web server control
Custom Server  • Code is placed in the App_Code directory under Web Root
Control Code
Use Custom  • In Page Load Event you must declare a new instance of the control and add to 
Server Control Controls Collection
Example:
Page_Load(...)
{
protected void Page_Load(sender object, EventArgs e)
{
Label  ThisLabel;
this.Controls.Add("ThisLabel");
}
}

• To reuse controls you create a class file (.cs) that inherits from the control class 
that you want to use.  The (.cs) file should be stored in App_Code.
1. To inherit from a class use the reference ":" then the class to inherit from
Example:
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.WebControls;

public  class MyButton : Button
{
public  Mybutton()

2544 - Advanced Web Apps wtih VS 2005 Page 25


{
this.Text = "Click Here"
this.BackColor = System.Drawing.Color.Crimson;
this.ForeColor = System.Drawing.Color.White;
}
}

2. Goto Page_Load Event and create a new instance of the control
Example:
MyButton customButton = new MyButton();
form1.Controls.Add(customButton);

IMPORTANT:  There are 2 ways to define the MyButton class (see below)
i. public  class MyButton : System.Web.UI.WebControls.Button  ‐OR‐
ii. public  class MyButton : Button
(this is possible because the namespace was previously instantiated 
in the "using" clause)
Composite Web  • This is implemented as a class with no HTML markup
Server Control • Usually made up of 2+ controls
• To add controls you have to override the CreateChildControls method of the 
CompositeControls class

Example:
using System;
using SystemComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.WebControls;

namespace compControls
{
public  class UserData : CompositeControl
{
private Button submitButton;
private TextBox nameTextBox;
private Label nameLabel;

public  UserData()
{
this.Text = "Click Here"
this.BackColor = System.Drawing.Color.Crimson;
this.ForeColor = System.Drawing.Color.White;
}
}

Template  • Are special type of composite controls
Controls • Passes the layout modification control over to the developer (ie Repeaters, 
DataList)

2544 - Advanced Web Apps wtih VS 2005 Page 26


• Can modify the layout
• Must implement the System.Web.UI.Template class
• Must expose the System.Web.UI.Control public property
• Must be compile and stored in Bin directory
• Any modifications to the control must be done thru HTML markup within the 
page.  Thus creating another instance of the control
Review  Quiz 1. What directive is created when a user control is dragged to a page?
a. <% register %>
b. <% control %>
c. <% UserControl %>
d. <% RegisterControl %>
2. True or false; user controls can be added from the toolbox?
a. True
b. False
3. True or false; templated controls allow for web page developer modifications?
a. True
b. False
4. Custom web server controls may be found in which solution folder?
a. App_Data
b. App_Code
c. App_localization
d. App_Globalization
5. Which method is overridden to create Composite Web Server Controls?
a. CreateChildControls
b. AddChildControls
c. InsertChildControls
d. NewChildControls
6. Which statement about Custom Web Server controls is false?
a. Written in managed code
b. Compiled as an .exe
c. Faster than user controls
d. Better security than user controls
7. True or false; The directive for a user controls says <%control%>?
a. True
b. False
8. User controls do not have which tag?
a. <form>
b. <body>
c. <html>
d. All the above

2544 - Advanced Web Apps wtih VS 2005 Page 27

You might also like