Professional Documents
Culture Documents
NET
It represents an exciting new platform for creating web sites with the .net framework, using any
.net language. The benefits are,
1 | Page
10) Web Services : ASP.NET also provides the web service infrastructure. It is possible to
create a web service with very few lines of code.
Web Forms
It is an exciting part of the ASP.NET platform. It gives the developer the ability to drag and
drop the ASP.NET server controls onto the form and easily program the events that are raised by
the control. Web Forms have the following benefits:
Rendering: Web forms are automatically rendered in any browser. In addition, Web Forms can be
tweaked to work on a specific browser to take advantage of its features.
Programming: Web Forms can be programmed using any .NET language, and Win32 API calls
can be made directly from ASP.NET code.
.NET Framework: Web Forms are part of the .NET framework; therefore web forms provide the
benefits of the .NET framework, such as performance, inheritance, type safety, structured error
handling, automatic garbage collection, and xcopy deployment.
Extensibility: User controls, mobile controls, and other third-party controls can be added to extend
Web Forms.
WYSIWYG: VS.NET provides the WYSIWYG editor for creating web forms by dragging and
dropping controls onto the web forms.
Code Separation: Web Forms provide a code-behind page to allow the separation of HTML
content from program code.
State Management: Provides the ability to maintain the view state of controls across web calls.
c:\inetpub\wwwroot
2 | Page
1) Single file for each page. In this type the server code and the client-side tags and code are
placed in the same file with an .aspx file extension.
2) Two file for each page This model offers the ability to use an .aspx page for the clientside presentation logic and a C# code-behind file with a .aspx.cs file extension for the
server-side code.
Server Controls
A Server control is a control that is programmable by writing server-side code. They automatically
maintain their state between calls to the server. Server controls can be easily identified by their
runat =server attribute. A Server control must have an ID attribute to be referenced in code.
ASP.NET provides two types of server controls; HTML and Web.
HTML Controls
These are traditional HTML controls, except they have a runat=server attribute. This type of
control is used when migrating older ASP pages to ASP.NET.
Common Properties :
Textbox
Button
PostBackURL:Specify FileName to go. It submits the form data and sends to control
specified file.
3 | Page
Link Button
Image Button
HyperLink
To create hyperlinks.
ImageUrl : Specify image filename.
NavigateUrl : Specify the .aspx or .htm filename.
Text : Specify text to be displayed as hyper text.
CheckBox
Text:
TextAlign:- Left/ Right
AutoPostBack:- true/false : If True, it Submits Form.(Refreshes the Page)
Checked : true/false.
4 | Page
Text:
TextAlign:- Left/Right
GroupName:- specify common name (variable) for all the radiobuttons.
AutoPostBack:- true/false : If True, it Submits Form.(Refreshes the Page)
Response.Write(RadioButton1.Text);
string a= RadioButton1.Text;
DropDownList
AutoPostBack : True/False. If it is set to True the form will be submitted as soon as you
select any item from it, also its event SelectedIndexChanged shall be fired. If it is set to
False, its selected value will be displayed upon submitting form.
5 | Page
SelectedValue : To read selected value from dropdownlist. To be used when you connect
with database.
6 | Page
AutoPostBack : True/False. If it is set to True the form will be submitted as soon as you
select any item from it, also its event SelectedIndexChanged shall be fired. If it is set to
False, its selected value will be displayed upon submitting form.
SelectedValue : To read selected value from listbox. To be used when you connect with
database.
Response.Write(ListBox1.SelectedIndex);
Response.Write(ListBox1.SelectedItem);
// Response.Write(ListBox1.Items[a].Text + "<br>");
b=b+ ListBox1.Items[a].Text+ ;
}
}
Response.Write(b=+b);
CheckBoxList/RadioButtonList
AutoPostBack : True/False. If it is set to True the form will be submitted as soon as you
select any item from it, also its event CheckedChanged shall be fired. If it is set to False, its
selected value will be displayed upon submitting form.
RepeatDirection : Horizontal/Vertical.
RepeatLayout : table/flow.
string b=;
protected void button1_Click(object sender, System.EventArgs e)
{
int a;
for (a=0;a<CheckBoxList1.Items.Count;a++)
8 | Page
{
if (CheckBoxList1.Items[a].Selected)
{
// Response.Write(CheckBoxList1.Items[a].Text + "<br>");
b=b+ CheckBoxList1.Items[a].Text+ ;
}
}
Response.Write(b=+b);
}
Response.Write(RadioButtonList1.Text);
c=RadioButtonList1.Text;
Image
Image1.ImageUrl = "cyan-ball.gif";
Table
Rows: To add rows (Click on Add Button -> Click on Cells ->Add->type coloumn data in
text property (Repeat) ->OK
9 | Page
For second row: (Click on Add Button -> Click on Cells ->Add type coloumn data in text
property (Repeat).Ok.
We can create table also from Table Menu->Insert Table and give all the settings(row,
col.)->O.K.
We can also insert a ready-made table in the form which looks like a frame(No Border).A
hyperlink can be included. Its target and NavigateURL properties can be given so that the
file opens in a iframe in the table.
Bulletedlist
in
items
property
for
bullet
ImageMap
It displays a image, and divides the image into various areas so that we can use that area as a
hyperlink.
HotSpots:- To specify the area /portion of the image to be treated as hyperlink. They are
Circle, Rectangle, Polygon Hotspots.For Circle Hotspot, specify the X,Y coordinates and
the radius. For the rectangular hotspots, specify the top,left,bottom,right coordinates. For
the Polygon hotspots, type the X,Y axis Coordinates separated by comma, in even no in
Coordinates Property.
10 | P a g e
HiddenField
To send data from one page to another page w/o showing it. The data will go to subsequent page
when postback event occurs. Using Request.Form[] we can read.
FileUpLoad
It will display a textbox, button (Browse). Upon clicking on the button open file dialog box will
appear, from there you can select any file, that file name will appear in the textbox.
{
string a, b;
int p;
a = FileUpload1.PostedFile.FileName;
p= a.LastIndexOf("\\");
if (p > 0 )
{
b = a.Substring(p + 1);
}
else
{
b=a;
}
FileUpload1.PostedFile.SaveAs(Server.MapPath(b));
FileUpload1.PostedFile.SaveAs("d:\\neha\\" + b);
}
Panel
To group components. After grouping we can hide/show all the components. Also to specify
backgroundcolor or backgroundimage to a particular portion of area.
In page_load event :
PlaceHolder
It is used as a container to store web server controls on the web page that were added at run-time.
In page_load event :
AdRotator
Advertisement Rotator. It displays various images one by one just like how advertisement appears
in a TV. Upon clicking on the image the particular specified web site is opened.
Procedure :
1) Create an .xml file (called avertisements file). Click on WebSite->Add New Item->XML
File->Type filename->Add. (ads.xml)
2) Take Adrotator control->Set Width, Height.
3) Specify the .xml file in AdvertisementFile property.
Creating Advertisement file.
<Advertisements>
<Ad>
<ImageUrl>Follow.jpg</ImageUrl>
13 | P a g e
<NavigateUrl>http://www.rediff.com</NavigateUrl>
<AlternateText>Rediff</AlternateText>
<Impressions>100</Impressions>
</Ad>
<Ad>
<ImageUrl>autumn.jpg</ImageUrl>
<NavigateUrl>http://www.Google.com</NavigateUrl>
<AlternateText>Google</AlternateText>
<Impressions>50</Impressions>
</Ad>
<Ad>
<ImageUrl>Ascent.jpg</ImageUrl>
<NavigateUrl>http://www.yahoo.com</NavigateUrl>
<AlternateText>yahoo</AlternateText>
<Impressions>10</Impressions>
</Ad>
</Advertisements>
Calendar control
To display calendar.
Single Date :
string a;
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
14 | P a g e
Response.Write(Calendar1.SelectedDate.ToString());
a= Calendar1.SelectedDate.ToString();
}
Multiple Dates :
Restricting a Date :
15 | P a g e
All are basically label controls, if error occurs they will appear.
RequiredFieldValidator : It checks for the given value if it is equal it will display error message.
InitialValue : Specify text to be compared with the textbox data. If you leave it blank then it
checks textbox data for blank or not. If blank error will be displayed. If you type any data in
this, it will compare textbox data with this data if both are same then it gives error
otherwise no error.
CompareValidator : It compares data of textbox with the specified value at design time.
16 | P a g e
RegularExpressionValidator : For comparing e-mail address, url, phone number, postal code,
social security code etc.
17 | P a g e
<script language=VBScript>
function test(source,args)
if (args.value=10) then
args.IsValid=true
else
args.IsValid=false
end if
end function
</script>
Also we can write the code in the CustomValidator_ServerValidate event. At that time dont set
ClientValidationFunction property. For this double click on the CustomValidator control.
Even though error occurs page will be submitted but other validation control does not
Submit page if error occurs.
Sample custom validation for checking whether textbox contains no. 10 or not :
else
{
args.IsValid = false;
}
}
string check;
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
string a = args.Value;
int l = a.Length,j,b,f=0;
char c;
for (j = 0; j < l; j++)
{
c = Convert.ToChar(a.Substring(j, 1));
b = (int)c;
if ((b > 64 && b < 91) || (b > 96 && b < 123))
{
f = 1;
}
else
{
f = 0;
break;
}
}
if (f == 1)
19 | P a g e
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
ValidationSummary : It displays all the errors occurred either in bulleted list, ordinary list or in
paragraph style.
DisplayMode : Bulleted/List/Paragraph.
Menu
To create menus. Click on Edit Menu Items->Add Root(set its properties Text, Popoutimageurl,
Separator image url) or click on Child->Set Navigate URL, ImageURL, , Text, Tooltip, Target
(_new/_blank to open in new browser)->Ok.
Orientation : Horizontal/Vertical.
Also we can specify SiteMap as Data Source for Menu. For this create a web.sitemap enter all the
urls which you like to use as hyperlinks, create SiteMapDataSource using web.sitemap then
specify SiteMapDataSource as DataSource for the menu.
Treeview
20 | P a g e
Click on Edit Nodes or Nodes (from properties window)->Click on Add root node->Click
on add child node->Type node text in text property, select image file name for ImageUrl
property, select filename for navigation in NavigateUrl property, Select true/false from
ShowCheckbox property, Select true/false from Checked property, Type _blank in Target
property for opening the file in new window, Select true/false from Expanded property (for
root item).
Also we can specify SiteMap as Data Source for treeview. For this create a web.sitemap enter all
the urls which you like to use as hyperlinks, create SiteMapDataSource using web.sitemap then
specify SiteMapDataSource as DataSource for the treeview.
t11.Target = "_new";
TreeView1.Nodes.Add(t1);
TreeView1.Nodes[0].ChildNodes.Add(t2);
TreeView1.Nodes[0].ChildNodes.Add(t3);
TreeView1.Nodes[0].ChildNodes[0].ChildNodes.Add(t11);
TreeView1.Nodes[0].ChildNodes[1].ChildNodes.Add(t12);
TreeView1.Nodes[0].ChildNodes[0].ChildNodes[0].ChildNodes.Add(t13);
22 | P a g e
If (! Page.IsPostBack)
{
}
SitemapPath
It displays navigation structure of website. To use this control first of all we have to create sitemap.
Site map is a file which contains urls, titles of the pages available in your web site. Using this
urls, titiles sitemap path displays navigation structure of the web page. For this it displays the title
on navigation bar containing current page title and previous pages titles.
1) Click on website -> add new item -> select site map -> click on add.
2) Type URL name, in URL property, page title in title property in the file created(Websitemap
in step1).
3) Double click on site map datasource to create sitemapdatasource.
4) Double click on sitemappath control, it immediately displays the navigation structure on the
page.
Sample Navigation structures :
Style 1 :
For the above structure we have to create sitemap file like below :
Style 2 :
Here main is the home page title, first and second are sub pages of main, aaaa, bbbb are sub-sub
pages of first, aaa, bbb are sub-sub pages of second.
</siteMapNode>
</siteMapNode>
</siteMap>
25 | P a g e