Professional Documents
Culture Documents
Friday, July 23, 2010
3:22 PM
Localization Can be of 2 types:
a. Explicit (requires more design work)
b. Implicit
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);
}
}
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?
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()
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)