Академический Документы
Профессиональный Документы
Культура Документы
NET
1. Normal application.
2. Web services.
J2EE APPLICATION
.NET APPLICATION
-----
- Class
-----
Oracle Application Business Application
-----
-
3. Ajax [Asynchronous java script and xml] Application:
Request object can be used to read the information comes with client
request
Request Object
xyz@gmail.com
Response Object
Registered successfully
1.) Write
It will send text from server to client.
2.) Redirect
It will perform redirect to other web pages.
3.) End
It will stop page processing [no more response will be given client].
<%
--------
--------
%>
Note:
- Asp.net page extension is ASPX [Active Server Pages Extension].
- The server side codes will procedure towards client browser, this
output will not contain any server side statement, and it contains
only html content.
- Asp.net page execution takes at 2 place:
1.) Web server will execute server side code present in page.
2.) Browser will execute html tags and client side script given by
web server.
- Default language for asp.net is vb.net.
Page Directive:
Directive is an instruction to server; it should be first statement
with in web page.
Page directive can be used to provide different instruction to
server, it can changing language, attaching theme.
Creating Asp.net webpage using C#.NET:
<%@Page Language =”CS” %>
<Html>
<Body>
<% Response. Write (“ASP.NET PAGE USING C#”) ;%>
</Body>
</Html>
Save page as hi.aspx.
Browser http://localhost/hi.aspx.
Browser
Server system requires IIS installation and .net installation
.net instillation will configure IIS with asp net _isapi.dll[asp.net
internet server application programming interface]
asp net _isapi.dll acts like mediator between web server and
.net
Client Request to web server will be received by inetinfo.exe.it
will verify requested file extension ,if it is html the code will be
copied to client browser ,if it is aspx the request will be forward
to asp.net worker process using asp net _isapi.dll.
Asp.net worker process [exe file] can be called as asp.net
engine(or) asp.net run time ,it will encapsulate all the .net
service needed for asp.net page execution.
Asp.net worker process will perform following steps:
It will compile asp.net page into dll file.
Dll will maintain a webpage in the form of class.
Web page object will be created to process page execution and
output will be given to client browser.
Web page dll will be maintained for serving to different clients
requests, this provides better performance.
Location of webpage dll in server system:
A folder will be created with in temporary asp.net files folder to
maintain web pages dll’s
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<h1>
<% Response.Write("WELCOME TO ASP.NET") %>
</h1>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Note :
1. File system:
This website will be managed by FTP server; this is required when the
web server is present in remote location.
The solution provided by asp.net is server side controls. These are not
supported in asp 3.0.
The control object created within the server side processing is called
server side control. This makes developer job easier.
HTML server controls will provide similar syntax of client side controls
to make migration easier.
Providing ruanat =”server” to client side control becomes server side
control. This makes conversion easier.
HTML server controls are provided based on number client side
controls, this area does not have any changes from asp.net 1.0 to
asp.net 4.0
Web server controls:
Web server controls provides very rich functionality compared to html server
controls. These are very advanced controls.
1. Standard controls
2. Validation controls:
3. Data controls
4. Navigation controls
Webpartzone….
6. Login controls
Script manager…
Web server control supports extensibility (extensibility means MS
introduce new controls from one version to another version and
developer can create user defined web server controls.
Examples on controls:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 218px; width: 928px">
First
Number &nbs
p;
<asp:TextBox ID="TxtFirst" runat="server"></asp:TextBox>
<br />
<br />
Second Number
<asp:TextBox ID="txtSecond" runat="server"></asp:TextBox>
<br />
<br />
Result
 
;
<asp:TextBox ID="txtResult" runat="server"></asp:TextBox>
<br />
<br />
 
; &nbs
p;
<asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click"
Text="Add" />
</div>
</form>
</body>
</html>
using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAdd_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(TxtFirst.Text);
int b = Convert.ToInt32(txtSecond.Text);
int c = a + b;
txtResult.Text = c.ToString();
}
}
Button control:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
uname
<asp:TextBox ID="txtUid" runat="server"></asp:TextBox>
<br />
<br />
password
<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
<br />
<br />
<br />
 
;
<asp:Button ID="Button1" runat="server"
PostBackUrl="~/Welcome.aspx"
Text="Button" />
</div>
</form>
</body>
</html>
Create welcome.aspx and write the code in source
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% string uname = Request.Form["txtUid"];
string pwd = Request.Form ["txtPwd"];
Response.Write("welcome to " + uname);
%>
</div>
</form>
</body>
</html>
Press F5
Web server
Raju Welcome.aspx
SUBMIT Uname=raju
WELCOME TO RAJU
Output
WELCOME TO RAJU
Analyzing page submission:
Arrangement of data:
The data will be arranged with in The data will be arranged with in
http message body http header
The button will perform arrangement based on method type for sending to
server.
<body>
<form id="frm_get" action="Default2.aspx" method="get" >
<table>
<tr>
<td>Name: </td> <td><input type="text" id="txtName" name="name"
/></td>
</tr>
<tr>
<td>Address: </td> <td><input type="text" id="txtAddr" name="addr"
/></td>
</tr>
<tr>
<td></td> <td><input type="submit" value="Send Using Get" /></td>
</tr>
</table>
</form>
</body>
<body>
<table border=”2″ cellpadding=”7″ cellspacing=”2″ >
<tr>
<th>Name</th> <th>Address</th>
</tr>
<tr>
<td><% Response.Write(Page.Request.QueryString["name"]); %></td>
<td><% Response.Write(Page.Request.QueryString["addr"]); %></td>
</tr>
</table>
</body>
Note:
Among collection of check boxes user can select more than one check
box.
Among collection of Radio button user can select only one Radio
button.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<p>
COSTMER NAME
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
NO OF DAYS
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
<p>
ROOM TYPE</p>
<p>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="g"
Text="A/C" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="g"
Text="NON A/C" />
</p>
<p>
FACILITIES</p>
<p>
<asp:CheckBox ID="CheckBox1" runat="server" Text="T.V" />
<asp:CheckBox ID="CheckBox2" runat="server"
Text="COMPUTER" />
</p>
<p>
1. In page technique
2. Code behind technique
In page technique:
Placing design part and logic part into aspx file is called “In page
technique”.
.Asp
Design Logic
Placing design part coding into aspx file and logic part code into
cs/vb file is called” Code behind technique”.
The code behind file will be attached to aspx file using page directive.
Design Logic
+
Web Design Web Developer
Image control:
Hyperlink Control:
<body>
<h1>
This is a html page
</h1>
</body>
Note:
Server.Transfer (): it will perform redirection from one page to another page
with in server side processing without information to browser.
Web server
Web page 1
------
------
}
else
{
Response.Write("<script>alert('invalid ')</script>");
}
User.aspx
----
Login.aspx -
Admin.aspx
----
----
-
-
List control:
List control will provide rich functionality towards web page creation. These
controls are required in maximum websites.
ListBox Control:
Index Value
Listbox is collection of list items each list item is identify with unique index.
List item will represent text and value, text will be visible to user and value
can be used with in programming.
1.) Add (): by using this method add items into the list control.
Syn <list control name>.Items. Add (value);
Ex DropDownList1.Items.Add (1);
2.) Insert (): by using this method add items into the list
control at a specific position.
Ex listbox1.Items.Remove (1);
4.) Remove At (): by using this method remove items from the
list control based on index value.
5.) Clear (): by using this method clear all items from the list
control.
The control which can be performing Post back submission is called “Post
back control”.
The control which cannot perform Post back submission is called as non Post
back control.
Non post back control can be converted to post back control by setting auto
Post back property is true
When user select list items selected index changed subprogram will be
executed on server
Dropdownlist control:
Dropdownlist is similar to Listbox control it will display only list items by
default and doesn’t allow multiple items selection
{
int total = 0;
for (int i = 0; i < lstTwo.Items.Count; i++)
{
total = total + Convert.ToInt32(lstTwo.Items[i].Value);
}
Label1.Visible = true;
Label1.Text = "Total cost " + total;
}
Wizard Control:
Step 1
Steps
Step 2
Next
Wizard
Control
Wizard control collection of steps each step will represent certain
information.
Place a wizard control on the default page go to properties for wizard control
select wizard steps properties and add the step as student details, contact
details, show details
And right click on show Details step select properties do to events tab double
click on Active step Changed event:
Fileupload control:
Sending file from client system to server system is called file uploading.
Properties:
1.) HasFile: this property is used for checking while file is selected or
not. I.e. file is posted are not.
2.) Content Type: this property is used for checking the format of the
posted file.
The format like below
Text/plain normal text file.
Text/XMl XMl file
Image/gif
Image/jpeg
3.) Filename: this property used for assign the filename for posted
file.
Method:
1.) Save As (): using this method save the files into the
server from client location.
Server.mappath:
It will return physical path of web site, this approach provides better
maintenance.
Directory of class:
Directory info class can be used to read files present in particular folder.
Using System.IO;
BulletedList1.DataSource = Directory.GetFiles(Server.MapPath("."),
"*.jpg");
BulletedList1.DataBind();
}
Adrotator control:
Browser
Ad 1 web page
Ad 2 Ad1
---
Ad 2
---
<Advertisements>
<Ad>
<ImageUrl>ad image name</ImageUrl>
<NavigateUrl>ad information page</NavigateUrl>
<AlternateText> tool tip text</AlternateText>
<Height>---------</Height>
<Width>---------</Width>
</Ad>
</Advertisements>
ImageUrl: this tag used to specify the advertisement image name.
<body>
New sports bike
</body>
Validation control:
Validation summary:
This control is used to print the entire error messages at a single
place that are providing by other Validator control.
2.) Text :
This requires content to be displayed with validation control if
validation falls.
3.) Error Message:
This requires content to be displayed with validation summary control
if validation fails.
4.) Set Focus on Error: True (or) False
True Cursor will be placed into textbox control to validate.
Creating Registration web page towards online polling this web page will
perform different validations using validation controls?
Create Function For Custom Validator write the code in head tag.
<script language="JavaScript">
function validateNumber (oSrc, args)
{
args.IsValid = (args.Value % 2 == 0);
}
</script>
StateManagement :
Go:
Get:
Forget:
1. Context
2. Query String
3. Cookies
4. Session
5. Application Memory
6. Cache
7. View State
Context:
The user information can be maintained from one webpage to
another webpage using context memory.
Content object will be accessible to different web pages only for the re
direction with Server.Transfer.
Query String:
The personal information can be username, session id, and security token.
1. In memory Cookie
2. Persistent Cookie
In memory Cookie:
The cookie placed within browser process memory is called
Inmemory cookie.
It is a temporary cookie; once browse is closed cookies will be
erased.
Asp.net is providing HttpCookie class to work with cookies.
obj.Value=100;
Response.AppendCookie (obj);
Reading cookie
Browser request to web server will submit cookies. Cookies will be accessible
in all the WebPages of website towards client request.
Browser Webpage1
N=100 webpage2
Webpage3
HttpCookie obj=null;
Obj=Request. Cookies [“N”];
If (obj.Value! =”null”)
{
Cookies data submitted by the client;
}
Else
{
Cookies data is not submitted by the
client;
}
Creating website towards online examination:
Disable back button of browser, so that user cannot get back to previous
questions:
----
<head runat="server">
<title>Untitled Page</title>
<script language="javascript">
function f1()
{
window.history.forward()
}
</script>
</head>
<body onload="f1()">
Note:
Browser will maintain user navigated web pages with in history object
internally.
Back and forward buttons of browser will provide navigation
between web pages using history object.
Windows.history.forward method will inform browser not to maintain
webpage name with in history.
This does not allow displaying previous page with back button.
Persistent cookie:
The cookie placed on hard disk of client system is called “persistent cookie”.
Obj.value=”…”
Response.AppendCookie (obj);
[Providing remembers my login with login page, server will use Persistent
cookies to remember login parameters]
Add webform:
}
else
Response.Write("invalid username and password");
}
Uname#orbit
Password#orbit
Browser will read cookies information from text file for submitting to web
server [website].
Note:
In our case the client will not be authenticated for 2 days. After 2 days
client system will erase cookies.
Cookies supports maximum of 4kb data, it should be in the form of
string.
Cookies does not provide security, client can modify cookie value or
client can remove cookie or deleting text file.
Browser will create separate text file to each website to maintain
cookies.
<>@gmail.txt
<>@msn.txt
Browser supports maximum of 20 cookies towards a website
Browser supports maximum of 300 cookies towards different websites.
One browser stored cookies will not be used by another browser.
Tv…
Cookie is not applicable to above requirement for following reasons
Session Memory:
2. Remove (varname)
Add wbform
Coding:
int n = 0;
protected void btnWrite_Click(object sender, EventArgs e)
{
n = 0;
Session["n"] = 0;
}
protected void btnRead_Click(object sender, EventArgs e)
{
n = n + 1;
Session["n"] = (int)Session["n"] + 1;
//session["n"] returns value in the form of object,it should be
type casted to int type.
Response.Write("page var n=" + n);
Response.Write("session var n="+ Session["n"].ToString());
}
Note:
ADO.NET
System.data.dll
System.data.sqlclient.dll
System.data.oracleclient.dll
……..
2. Dataset.
Ex:
Connection class
Command class
…….
Other companies provided .net data providers are called “third party .net
data providers”.
……
Each database will have its own set of rules for communication,
This is called database protocol.
TDS [tabular data stream] is a protocol of sqlserver.
TNS [tabular network substrate] is a protocol of oracle.
Provider [Oledb provider] and odbc driver is a o/s specific
programming [com based programming]to implement native protocol
programming of databases.
.net data provider implementing native protocol programming is called
“managed .net data provider”.
.net data provider implementing Oledb provider/odbc driver
programming is called “unmanaged .net data provider”.
Conclusion:
Connecting sqlserver<7.0
Connecting to oracle<8i
----
System.data.oledb namespace
Oledbconnection class
Sql statement
Ex:
Provider name
Msdaora.1 oracle
Sqloledb.1 sqlserver
Data source will specify the system name in which database is running.
Ex:
1.ExecuteScalar():
Ex:
2. ExecuteReader ():
This is required when select statement returns more than one value.
This method will return data reader object to read records into application.
3. ExecuteNonquery ():
It will fetch record by record into application process, it will consume only
one record memory at a time with in application process, this will reduce
memory burden on application process.
1. read:
It will fetch record into application process by moving record pointer to next
record.
Dr.get<datatype>(columnindex)
Ex:
dr[“prodid”] or dr[0]
3.close
dr.close()
4.Fieldcount
Access:
Accno number
Nametext
Balnumber
Phnonumber.
Code:
using System.Data.OleDb;
public partial class Display : System.Web.UI.Page
{
protected void btnDisplay_Click(object sender, EventArgs e)
{
OleDbConnection con = new
OleDbConnection("provider=Microsoft.Jet.Oledb.4.0;Datasource=H:\bank.m
db");
OleDbCommand cmd = new OleDbCommand("select
Accno,Name,Bal,PhoneNo from Customer where Accno=" + TextBox1.Text,
con);
OleDbDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
TextBox2.Text = dr["Name"].ToString();
TextBox5.Text = dr["Bal"].ToString();
TextBox6.Text = dr["PhoneNo"].ToString();
}
else
Response.Write("<h2>invalid account no....</h2>");
dr.Close();
con.Close();
}
protected void btnModify_Click(object sender, EventArgs e)
{
OleDbConnection con = new
OleDbConnection("provider=Microsoft.Jet.Oledb.4.0;Datasource=H:\bank.m
db");
OleDbCommand cmd = new OleDbCommand("update customer set
PhoneNo=" + TextBox6.Text + " where Accno=" + TextBox1.Text, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
Response.Write("<h2>record modified</h2>");
}
}
System.Data.Sqlclient
Sqlconnection class
Sqlcommand class
------
Control to validate—t3
Control to compare—t2
Operator—equal
Text—incorrect
Code:
using System.Data.SqlClient;
Add webform
RegisteredSuccess.aspx
Navigate url—Login.aspx
Add webform
Login.aspx
Navigateurl—Register.aspx
Coding:
using System.Data.SqlClient;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new
SqlConnection("uid=sa;pwd=prasad;database=raju");
SqlCommand cmd = new SqlCommand("select count(*) from login
where UserName='" + TextBox1.Text + "' and Password='" + TextBox2.Text
+ "'", con);
con.Open();
int n = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
if (n == 1)
Server.Transfer("welcome.aspx");
else
Response.Write("invalid..");
}
}
F5[login.aspx]
Requirement:
Webpage should read particular table data more number of times,in this
case datareader requires more number of database communications,this will
effect performance of webserver.
Product.aspx Product
dataReader ------
100 requests
Dataset
Product
--------
1 connection
System System
---- -----
C
----
XML Sqlserver
P
Product
----
------
Data reader is not applicable to above requirement for following reasons.
Dataset:
Coding:
using System.Data.SqlClient;
Note:
Name—dabaselib
Goto class1.cs
using System.Data.SqlClient;
using System.Data;
namespace databaselib
{
public class Mycomponent
{
public DataSet getdata(string s)
{
SqlConnection con=new
SqlConnection("uid=sa;pwd=prasad;database=raju");
SqlDataAdapter da = new SqlDataAdapter(s,con);
System.Data.DataSet ds = new DataSet();
da.Fill(ds,"d");
return ds;
}
}
Ispostback site
Add webform
Note:
Grid view allows sorting implementation based on column header click, this
requires two steps.
Allow sorting—true
Code:
Allowpaging—true
Pagesize—3
Pagersettings
Mode-nextprevfirstlast
Firstpagetext-First
Nextpagetext--Next
Prevpagetext--Prev
Lasttpagetext—Last
Dropdownlist properties
Autopostback—true
Code:
Using System.Data.SqlClient;
using System.Data;
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
fillgrid(0);
Label1.Text = "1 out of" + GridView1.PageCount;
for (byte i = 1; i <= GridView1.PageCount; i++)
DropDownList1.Items.Add(i.ToString());
}
}
protected void GridView1_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
Response.Write(e.NewPageIndex);
fillgrid(e.NewPageIndex);
Label1.Text = (e.NewPageIndex + 1) + "out of" +
GridView1.PageCount;
}
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
fillgrid(DropDownList1.SelectedIndex);
Label1.Text = (DropDownList1.SelectedIndex + 1) + "out of" +
GridView1.PageCount;
}
}
Bound Field: it will display normal text based on dataset table column
values, this is considered as default field for grid view.
Properties:
Header text—it will represent column heading
Data field—it will represent dataset table column name.
Template Field:
This field acts like container for placing web server control into grid view.
This comes with item template.
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="c1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Sid sname
Rows[0] 1 s1 c1
Rows[1] 2 s2 c1
Rows[2] 3 s3 c1
cells[0] cells[1]
Grid view row is providing “find control” method to access control present in
template field, this returns control type, and it should be type casted to
required control type.
Code:
using System.Data.SqlClient;
using System.Data;
Gridview properties
datafield—sid
Note: autogenerate columns false will inform grid view not to generate
columns automatically; in this case grid view will consider columns specified
by developer.
Database designing:
1. Image field:
This will display image with in grid view reading image name from
dataset table column, the image file should be present with in website.
Ex:<asp:imagefield dataimageurlfield=”prodimage”/>
command field:
this will provide special typeof buttons into gridview[i.e select button,edit
button].
In our requirement “add to cart” requires select button.
Select button click will execute selected index changed event of grid view.
Hyperlink field:
This will place hyperlink with in gridview, hyperlink creation requires text
and webpage name [navigateurl page].
Creating website for online shopping using different types of grid view fields:
Girl.html
<body>
<h1>girl picture</h1>
</body>
Baby.html<body>
<h1>baby picture</h1>
</body>
Add webform default.aspx
Showcart[hyperlink]
Navigateurl—cart.aspx
Code:
using System.Data;
using System.Data.SqlClient;
}
}
Autogeneratecoumns – false
Columns—
Select imagefield—headertext—prodimage
Dataimageurlfield—prodimage
Controlstyle
Height—100
Width—100
Note:height and width will be applied to all the images with in gridview.
Headertext—proddesc
Datafield—proddesc
Headertext—prodprice
Datafield—prodprice
Button type—link
Header text—moreinfo
Datatextfield—prodtext
Datanavigateurlfields—prodpage
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="t1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
Right click on gridview and select auto format option.
r["desc"] = desc1;
r["price"] = price1;
r["qty"] = qty1;
ds.Tables["trans"].Rows.Add(r);
Session["ds1"] = ds;
}
Note:
Selected row property of gridview will provide access to row selected by user
by clicking on add to cart button.
DataSet ds = (DataSet)Session["ds1"];
if (ds != null)
{
GridView1.DataSource = ds.Tables["trans"];
GridView1.DataBind();
}
}