Académique Documents
Professionnel Documents
Culture Documents
Ram
Sri Sai
ASP.Net -INTRODUCTION
Dt: 29-03-2010
What is .Net?
.Net is a Framework, which is collection of libraries and Runtime.
More over all languages can use these libraries.
Why .Net?
To develop different types of applications any type of applications can be
Srikrishna
Page1
Naga Raju
Ram
Sri Sai
ASP.Net --
Every .Net language is designed to consume .Net libraries and produce code
own runtime.
C#
No Libraries
No Runtime.
(C# has no Libraries and no runtime because its have .Net languages and
Dt: 30-03-2010
universal applications.
The other types of applications that we have are desktop applications, which
are called standalone applications. Desktops are more rich in features like
performance, security, user interface, etcBut they are accessible locally
web applications are by default lowing features but accessible everywere.
Today most of the application development is web development, because of
accessibility.
Srikrishna
Page2
Naga Raju
Ram
Sri Sai
ASP.Net --
While developing web apps programming remains same or with little changes
but of their architecture/ concept they are universal.
What is that concept or architecture or setup?
Web architecture are infrastructure is involved with following:
1. Server Model of Operating System.
Server: - A program which is return to serve requests and to manage
resources effectively for multiple users is called server program.
Ex:-DB Servers, Operating System, Application Servers, Integration Server.
Client:-A program which is return to make requests and gets results or which
is written to run as standalone is called Client Program.
Ex:- windows XP, MS-Office, Inventory packages.
i. For web some Operating System suitable.
Windows Server 2003
Windows Server 2008
Linux Server.
Solaris Server.
2. Web Server
- It is software which as a service under operating system and which
-
All web servers take request only from their client softwares.
HTTP-Hyper Text Transfer Protocol.
Protocol is a set of rules, itsnot software.
Srikrishna
Page3
Naga Raju
Ram
Sri Sai
ASP.Net --
Note:-Google run in any application, we give HTTP request then we responded it.
Because of this HTTP Protocol web applications are universal, any device and
any OS can request web app and get results. All that they have to do is write
a program which generates request in the form of HTTP or use a tool which
can generate HTTP request for them like Browser.
Srikrishna
Page4
Naga Raju
Ram
Sri Sai
ASP.Net --
2.
Srikrishna
Page5
Naga Raju
Ram
Sri Sai
ASP.Net --
To check whether IIS is currently running or not open Browser & type
http://localhost (or) http://<systemname>
My Computer computer name (properties).
Result: - if a welcome page or some message showing about IIS is display
then the server is running otherwise we need to check or install IIS.
(Q). How to install IIS?
Control panel Add/Remove programs Add/Remove Windows Components
select IIS.
After we select IIS & click next asked OS cod.
(Q). How to create a web site?
Once IIS is installed go to control panel Administrative Tools Internet
Services Manager (or) Internet info Services.
Start this program & we will get IIS console.
Select default web site (right click) & choose New Virtual Directory.
Enter Virtual Name (site name) followed by physical directory in the display
window.
Result: - the site is created.
DT: 03-04-2010
Explore the .Net Framework:
The .Net framework allows developers to use the same set of skills to rapidly
Srikrishna
Page6
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page7
Naga Raju
Ram
Sri Sai
ASP.Net --
accessed using Browsers only. All Browsers understand only HTML for
inputs & outputs.
HTML is not a powerful language for programming- it provides few tags
using which we can take inputs as well produce outputs.
HTML cannot provide any functionality which means we can design static
content or non-interactive content.
The only advantage with HTML is with very few tags we can produce good
design.
Conclusion: Using HTML alone we cannot design todays wanted dynamic
web pages.
Srikrishna
Page8
Naga Raju
Ram
Sri Sai
ASP.Net --
Note:
http
localhost
yahoo
demo.html
:
:
:
:
protocol
it is a current system
is website
is program
*** END OF THE DAY ***
Dt: 05-04-2010
---------------------------------------------------------------------------------------------------
Srikrishna
Page9
Naga Raju
Ram
Sri Sai
ASP.Net --
If IIS port no. is changed from 80 to other no. then we most specified port No.
also.
If we dont given the new port no. it will be taken default port no. 80
------------------------------------------------------------------------------------------------- IIS .NET
For html/JavaScript (www.w3schools.com)
For ASP.Net BOOKUnleashed ASP.Net --- Stephen Walther(Author)
Sitehttp://www.asp.net (official site)
In this side we have videos/articles/ demos
One are more (alternative site)--- www.codeproject.com
Class room slides & some articles http://nbende.wordpress.com
(for NIT students).
HTML Forms:-
Srikrishna
Page10
Naga Raju
Ram
Sri Sai
ASP.Net --
http://nit10/virtualdirectory/programname
Srikrishna
Page11
Naga Raju
Ram
Sri Sai
ASP.Net -*** END OF THE DAY ***
Dot: 06-04-2010
In web application when we refer a file from any of the program. Then the
referred file is called as resource. When we consume this kind of resource
they must be present in our project only or our directory only. We must not
specified nay c:/ or d:/ & soon the only alternate is we can use publicly
accessible URL (Uniform Resource Located).
Since URI = Uniform Resource Identifier.
<img name=m1 src=hai.jpg>
(Q). what is the directory structure of your project?
Ans: - We have categorized out content into following folders explain each folder &
its content.
SCRIPTING:
(Q).Why Scripting?
Ans:-using HTML alone we can design Non-interactive & static pages. If we
want pages we must add scripting support to it i.e., to HTML.
HTML + Scripting = Dynamic Web Page.
Scripting is divided into two forms,
1. Client side Scripting
2. Server side Scripting
(Q).What is Client side Scripting? *******
A program which is written for any other source is called script, unlike other
programs where we write independently also execute then as standalone.
Code that is executed or written to run as standalone is called program.
Code that is written for another source is called Script.
Client side script means which will be executed by an interpreter present in
Browser. Browser means nothing but client.
Srikrishna
Page12
Naga Raju
Ram
Sri Sai
ASP.Net --
Language =<language> or
Type=<text/language> is an attribute of script tag to specify particular
language.
We must close the opened script tag otherwise all content will be taken as
script only.
Inside <script>tag we must write only relevant language code but not any
other code.
Srikrishna
Page13
Naga Raju
Ram
Sri Sai
ASP.Net -<body>
<h1>Java Script Demo</h1>
<h2>This is HTML</h2>
<script language=javascript>
Document.Write(this is javascript);
</script>
<h2>Back to HTML</h2>
</body>
</html>
Output:-
Example:-2.<html>
<head><title>JavaScript Demo</title></head>
<body>
<h1>Java Script Demo</h1>
<h2>This is HTML</h2>
<script language=javascript>
Document.Write(<h1>this is javascript</h1>);
</script>
<h2>Back to HTML</h2>
</body>
</html>
Output:-
Example:-3. <html>
<head><title>JavaScript Demo</title></head>
<body>
<h1>Java Script Demo</h1>
<h2>This is HTML</h2>
<script language=javascript>
<h1>This is also JavaScript</h1>
Document.Write(this is javascript);
</script>
<h2>Back to HTML</h2>
</body>
</html>
*** END OF THE DAY ***
Dt: 07-04-2010
Naresh Tech. Class Notes
Srikrishna
Page14
Naga Raju
Ram
Sri Sai
ASP.Net --
JavaScript is the most recommended client side scripting language for any
type of web application.
All browsers today that support interpreters for client side scripting support
JavaScript as their scripting language.
Firefox: Support JavaScript.
Safari: Support JavaScript.
( Firefox, safari both are web Browsers).
Internet Explore: JavaScript+VBScript+Jscript+
The best web application is which runs on all browsers same.
Java Script is open source & free.
Good on Java Script: Java Script can perform any client side activity.
Not Good on Java Script: Its not user friendly (it is not easy to develop).
Weak typed System(Data type system is very weak).
int a;
var a;
a=Hello;
a=10; //int
b=true; //bool
c=hello; //string
d=a+10;
//20(a is integer a=10)
d=a+10; //1010
d=a+b;
//11
d=b+c;
//truehello
All JavaScript concerns (not good issues) are intentional. This weak support to
minimize
the
execution
time
by
keeping
the
interpreter
size
very
small*******.
With very less amount of memory JavaScript can run its code. To mobile
Browsers also have JavaScript is only the proof for our discussion.
--------------------------------------------------------------------------------------Method-2:- Writing JavaScript.
To write JavaScript code in the form of functions.
int Add(int a, int b)
function Add(a,b)
{
{
return Hello;
(or)
}
return a+b;
}
- No return type.
- We can return any value.
- Arguments can be declared.
- But with no data types.
- Can take any type of values.
Srikrishna
Page15
Naga Raju
Ram
Sri Sai
ASP.Net --
Ex:- If we write code in the form of function then it should be explicitly called.
(Unlike our first JavaScript program which executed without any call).
Example-1:<html>
<head><title>JavaScript Demo</title></head>
<body>
<h1>Java Script Function</h1>
<script language=javascript>
function simple()
{
Document.Write(<h2>javascript output</h2>);
}
</script>
<h2>Back to HTML</h2>
</body>
</html>
Output:-
Example-2:<html>
<head><title>JavaScript Demo</title></head>
<body>
<h1>Java Script Function</h1>
<script language=javascript>
function simple()
{
Document.Write(<h2>javascript out put</h2>);
}
Simple(); //call function
</script>
<h2>Back to HTML</h2>
</body>
</html>
Output:-
Example-3:- <html>
<head><title>JavaScript Demo</title></head>
<body>
<h1>Java Script Function</h1>
<script language=javascript>
Naresh Tech. Class Notes
Srikrishna
Page16
Naga Raju
Ram
Sri Sai
ASP.Net -function simple()
{
Document.Write(<h2>javascript out put</h2>);
}
</script>
<h2>Back to HTML</h2>
<script language=javascript>
simple();
</script>
</body>
</html>
Output:-
Dt: 08-04-2010
Srikrishna
Page17
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page18
Naga Raju
Ram
Sri Sai
ASP.Net -</html>
OutPut:-
Ex:-2:
-------------------------------------------------------------------<html>
<body>
demo2.html
<h1>JavaScript Events</h1>
<form name=frm>
User Name<input type=text name=t1>
<br>
Emain Id<input type=text name=t2>
<br>
<input type=button name=b1 value=Submit onclick=ShowMsg()>
<input type=button name=b2 value=Help onclick=ShowHelp()>
<script language=JavaScript>
function ShowMsg()
{
alert(Thank you for Submitting);
}
functionShowHelp()
{
alert(Sorry No Help);
}
</script>
</form>
</body>
</html>
OutPut:-
Note: - Objects---2
Events--- 2
Functions---2
Since Help has one event the is onclick(ShowHelp)
Since Submit has one event the is onclick(ShowMsg)
Naresh Tech. Class Notes
Srikrishna
Page19
Naga Raju
Ram
Sri Sai
ASP.Net --
Ex:-3:
<html>
<body>
demo3.html
<h1>JavaScript Events</h1>
<form name=frm>
User Name<input type=text name=t1>
<br>
Emain Id<input type=text name=t2>
<br>
<input type=button name=b1 value=Submit onclick=ShowMsg(Welcome)>
<input type=button name=b2 value=Help onclick=ShowMsg(No-Help)>
<script language=JavaScript>
function ShowMsg()
{
alert(x);
}
</script>
</form>
</body>
</html>
OutPut:-
Note: - Objects---2
Events--- 2
Functions---1
We can call functions with different objects and different events also. They
need not be similar object/similar events.
Srikrishna
Page20
Naga Raju
Ram
Sri Sai
ASP.Net --
To write multiple Events for single objects just write it another attribute i.e.,
provide space after one event and write another event.
Ex:-4
<html>
<body onload=ShowMsg(10)>
demo4.html
<h1>JavaScript Events</h1>
<form name=frm>
User Name<input type=text name=t1>
<br>
Emain Id<input type=text name=t2>
<br>
<input type=button name=b1 value=Submit onclick=ShowMsg(Welcome)>
<input type=button name=b2 value=Help onclick=ShowMsg(No-Help)
onmouseover=ShowMsg(cannot-click-Me)>
<script language=JavaScript>
function ShowMsg()
{
alert(x);
}
</script>
</form>
</body>
</html>
OutPut:-
Note: - Objects---3
Events--- 4
Functions---1
*** END OF THE DAY ***
Dt: 09-04-2010
Method-4 of Java Script: WritingJavaScript in a separate .Js file.
By default we are writing JavaScript & HTML in a single file. That means
design & code combined. This increases complexity of writing program&
more difficulty in debugging the program. For small program we can write
single file but for big programs have to separate them. JavaScript provides
this option by allowing users to write code in a separate .Js file. That is with
Naresh Tech. Class Notes
Srikrishna
Page21
Naga Raju
Ram
Sri Sai
ASP.Net --
extension .Js. In side .Js file we must write only JavaScript statements not
event script tag & other tag. Inside HTML file we have to write script tag with
SRC attribute pointing to .Js file.
Srikrishna
Page22
Naga Raju
Ram
Sri Sai
ASP.Net --
i.
<html>
<body>
<h1>Java Script DOM</h1>
<form name=frm>
<img name=m1, src=coworker.jpg>
<br>
UserName<input type=text name=t1>
<br>
<input type= button name=b1 value=Demo onclick=f1()>
<script language=javascript>
function f1()
{
window.Document.frm.t1.value=very Good;
document.m1.src=children.jpg;
}
</script>
</form>
</body>
</html>
<img name=m1, src=coworker.jpg onmouseover=f1()>
Dt: 10-04-2010
Current version of HTML is XHTML 1.0 (in before 1.0/2.0/3.0/4.0/then after
XHTML 1.0).
DOM Versions
Timer in JavaScript
Table/Div Tags in HTML
1. DOM Versions:Naresh Tech. Class Notes
Srikrishna
Page23
Naga Raju
Ram
Sri Sai
ASP.Net --
The first release of DOM is called version 0. This version is supported by all
Browsers. Next DOM version 1 & version 2 are also release to simplify
JavaScript, apart from that many new features are also added DOM version 2
is not supported by the current Browsers.
Maximum support for 1 & minimum support for 2 is provided by latest
Browsers one of the important features in DOM version 1 is to get the
element reference based on its ID (or) Name.
document.frm.t1.value
var x=document.getElementById(m1);
x.src=;
Very simple to use.
No need to follow the hierarchy.
2. Timer in JavaScript:(Q). what is a Timer?
It is a component, which executes code at regular intervals. Its run this
as a support process.
In javaScript there is no Timer object but there is a method called
setTimeout(<fn>,<interval>).
This
function
executes
the
given
<table>.
<div> is like a container for other controls & can be used to place
based on x, y positions of Browser.
<table> is for tabular presentation of data. i.e., Rows/Columns.
<div>or <table> or <div>+<table>.
Ex:- animate.html
<html>
<head>
Naresh Tech. Class Notes
Srikrishna
Page24
Naga Raju
Ram
Sri Sai
ASP.Net -<title>JavaScript animation:Demo</title>
<script language="javascript">
var x=null; //object
function doMove(){
x.style.left=parseInt(x.style.left)+1+'px';
setTimeout(doMove,50);
}
function init(){
x=document.getElementById('xObject');
x.style.left='10px'; //set is initial position to 10px
doMove(); //start animating
}
window.onload=init; //2ndmethod java script events
</script>
</head>
<body>
<h1>javascript animation:Demo</h1>
<div id="xObject" style="position:absolute">
Hello
<img name=m1 src="a11.jpg" onclick=f1()>
</div>
</body>
</html>
Out Put:-
Dt: 15-04-2010
Server Side Programming: -
Srikrishna
Page25
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page26
Naga Raju
Ram
Sri Sai
ASP.Net --
Ans: - Based on file extension*. Handlers are programs that reside with server &
are responsible to redirect the file to its related process / engine. All Handlers are
based on extension.
(Q). How to write an asp/aspx programs? What these programs can have?
Ans: -We can use any Simple editor like NOTEPAD for writing aspx programs. For
RAD (Rapid Application Development) we can use many tools available for
developing aspx applications like word class VS.NET, MS Expression, Dreamweaver
etc
Inside a program we can write html, JavaScript & aspx code. Aspx engine will
parse only aspx code & process it. Rest all will be redirected as it is.
(Q). How Engine will parse only aspx code&process it.Rest all willbe
redirected as it is?
Ans:-We have to write aspx code in a separate block <% %>
==== > called server side block.
Ex:<html>
<head><title>ASPX Demo</title></head>
<body>
<h1>Welcome to ASPX Programs</h1>
<%
Response.Write(This is ASP.NET output)
%>
<h2>Back to HTML</h2>
</body>
Naresh Tech. Class Notes
Srikrishna
Page27
Naga Raju
Ram
Sri Sai
ASP.Net -</html>
File SaveAs demo.aspx
http://localhost/shopsite/demo.aspx
Ex:
(i).
<%
<H!> that is HTMLH!>
Response.Write(This is ASP.NET output)
%>
(ii).
Save As as demo.aspx to demo.html
(iii). Remove <%........%>part and Save as demo.aspx
*** END OF THE DAY ***
Dt: 16-04-2010
Srikrishna
Page28
Naga Raju
Ram
Sri Sai
ASP.Net --
staring
from
developing
application,
debugging
application,
testing
Srikrishna
Page29
Naga Raju
Ram
Sri Sai
ASP.Net --
8. Design the page using intelligence & execute it using start button. We
can also use Design view in the bottom of Screen to get WYSIWYG
approach.
9. WYSIWYG means What You See It What You Go
(Q). What Start Button does?
Ans: - Starts a new Browser & types the URL of the page as a request & gets the
result.
Dt: 17-04-2010
Cassini isa StandaloneServer (Independent).
Srikrishna
Page30
Naga Raju
Ram
Sri Sai
ASP.Net --
Problem: - XML page cannot be displayed cannot view XML input using XSL style
sheet.
Solution: -Go to VS.NET command prompt & type ASPNET_REGIIS -i
VS.NET
provides
web
development
server
(Cassini)
which
makes
(web
Srikrishna
Dt: 19-04-2010
Page31
Naga Raju
Ram
Sri Sai
ASP.Net --
Every ASP.NET control is design in user friendly manner. Which makes every
level of user produces good outputs.
HTML controls are hardly 10+ where are ASP.NET controls are around 100 &
most of the controls are highly features we do not have any HTML equalent
to perform those control tasks.
Ex:-1
Srikrishna
Page32
Naga Raju
Ram
Sri Sai
ASP.Net --
Browser understands only HTML controls but not ASP.NET controls. So every
ASP.NET control after completing its processing at server, it gos another
process called Rendering.
What is Rendering?
Ans: - the process of converting ASP.NET states in to HTML (or) Browser
understandable format is called Rendering. This Rendering will be done
based on the type of client who makes the request.
Srikrishna
Page33
Naga Raju
Ram
Sri Sai
ASP.Net --
All web application are stateless & stateless means where every request is
identified as a new request. To day applications need high level state
management. Which is perform with lot of code/logic. All ASP.Net controls are
provided which state Management code. Which means ASP.NET controls are
State-full& Repair their values during round trips mode between client &
Server.
Dt: 20-04-2010
Writing Code for ASP.NET Controls: For HTML controls the only choice we have to write code using JavaScript.
For ASP.NET controls we can write code using JavaScript as well as using
C# at server side. Most of the coding is done at server side for ASP.NET
Control. We write the server side code using event of ASP.NET controls.
Once we write code at server side for an ASP.NET control then, when
client submit the form to server code is executed. For any reason if we
cannot submit the form then server side code will not be executed.
Another important point is when form is submitted to server it checks all
the control events & executes the relevant or fired events.
Srikrishna
Page34
Naga Raju
Ram
Sri Sai
ASP.Net --
Default.aspx(design)
Then we select View button and double click that button write following code:
- protected void Button1_click(object sender EventArgs e)
{
if(checkBox1.Checked)
Label1.Text=TextBox1.Text+is Employed;
else
Label1.Text=TextBox1.Text+is not Employed;
}
// we remove above if condition code part and write same code billow checkbox
area.
And Add one more checkbox & Label in the above design part.
Srikrishna
Page35
Naga Raju
Ram
Sri Sai
ASP.Net --
Note: - for controls like checkbox, listBox & RadioButton, we have a property
called AutoPostBack property which makes a control perform PostBack (or)
Submit server. According to requirement we can set this true or false.
*** END OF THE DAY ***
Dt: 21-04-2010
4*5,..&
background
Srikrishna
Page36
Naga Raju
Ram
Sri Sai
ASP.Net -}
elseif(RadioButton2.Checked)
{
Label1.Text=payment mode selected : + RadioButton2.Text;
Image1.imageUrl=yyy.jpg;
}
elseif(RadioButton3.Checked)
{
Label1.Text=payment mode selected : + RadioButton3.Text;
Image1.imageUrl=aaa.jpg;
}
elseif(RadioButton4.Checked)
{
Label1.Text=payment mode selected : + RadioButton4.Text;
Image1.imageUrl=zzz.jpg;
}
}
Output: -
in above example we have used html image control as well as aps.net image
control. Html image cannot be used in code window of server side. Whereas
asp.net image can be use in code window.
Add a new web item default4.aspx
in design page write welcome web site.
Naresh Tech. Class Notes
Srikrishna
Page37
Naga Raju
Ram
Sri Sai
ASP.Net --
drag& drop image button in toolbox and select that image button double click
write code.
Code: -
Srikrishna
Page38
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page39
Naga Raju
Ram
Sri Sai
ASP.Net --
<image>
=
html
<asp:Image>
=
static image
<asp:ImageButton> =
single image
<asp:ImageMap>=
Multiple Image
(Rich control) using lot of time.
List Controls:
Among all basic input, output controls, list controls provide lot of dynamic
behavior. At Runtime we can add elements & get results a control which is lot
useful for application.
ASP.NET provides 5 list controls in its standard set. It also provides Menu,
TreeView as advanced list controls using which we can build good
Presentations.
5 list controls:
1. ListBox
2. DropDownList
3. CheckList
4. RadioButtonList
5. BulletedLsit
We can use these list controls in design time using its properties. It provides
items collection where we can add our elements.
Go
to
solution
explorer
C:///website/(Right
Srikrishna
Page40
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page41
Naga Raju
Ram
Sri Sai
ASP.Net -}
else if (ListBox1.SelectedValue==20)
{
Label1.Text=.Net language: prepared;
}
else if (ListBox1.SelectedValue==30)
{
Label1.Text=.Net language;
}
else
Label1.Text=ListBox1.SelectedValue;
}
Srikrishna
Page42
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page43
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt:23-04-2010
Handling List Controls with dataBinding Content: (Q). what is DataBinding Concept?
Ans:-It is a process where we prepare data object with data in side it & Bind the
control with create data object. Controls provide properties to bind them selves.
.NET
has
many
classesto
support
dataBinding
data
object.
It
has
data.
It also has System.Data.* for various database related data.
It also has good service oriented concepts which can get data from Non.NET
environments.
In our example we will start with a class called ArrayList present in
System.Collections namespace.
This an outdated and not recommended class for storing data. Its drawback
is it performs Boxing/ UnBoxing of data for every storage & retrieval. To
replace this we have System.Collections.Generics which are good in
performance & also simple to program. We have List<T> in this
namespace where T is any database.
Design:-
Srikrishna
Page44
Naga Raju
Ram
Sri Sai
ASP.Net --
Code:using System;
using Syste.Collections.Genaric;
..
.
.
(Add)
using System.Collections; //public partial class default
---------------------------------------------------------------------------------------protected void Page_Load(object sender, EventArgs e)()
-----------------------------------------------------------------------------------------protected void Button2_Click(object sender, EventArgs e)
{
ArrayList Courses=GetCourses(); //courses is DataObject
ListBox1.DataSource=Courses;
ListBox1.DataBind();
DropDownList1.DataSource=Courses;
DropDownList1.DataBind();
CheckBoxList1.DataSource=Courses;
CheckBoxList1.DataBind();
RadioButtonList1.DataSource=Courses;
RadioButtonList1.DataBind();
BulletedList1.DataSource=Courses;
BulletedList1.DataBind();
}
publicArrayListGetCourses() //prepared
{
ArrayList obj=new ArrayList();
obj.Add(ASP.NET 4.0);
obj.Add(C#.NET 3.0);
obj.Add(VB.NET 3.0);
obj.Add(SQL Server);
obj.Add(Biztalk Server);
return obj;
}
OutPut:-
Srikrishna
Page45
Naga Raju
Ram
Sri Sai
ASP.Net --
EX-2:-
Code:-
(Add)
using System;
using Syste.Collections.Genaric;
..
.
.
using System.Collections; //public partial class default
---------------------------------------------------------------------------------------protected void Page_Load(object sender, EventArgs e)()
-----------------------------------------------------------------------------------------protected void Button2_Click(object sender, EventArgs e)
{
List<string> Courses=GetCourses(); //courses is DataObject
ListBox1.DataSource=Courses;
ListBox1.DataBind();
DropDownList1.DataSource=Courses;
DropDownList1.DataBind();
CheckBoxList1.DataSource=Courses;
CheckBoxList1.DataBind();
RadioButtonList1.DataSource=Courses;
RadioButtonList1.DataBind();
BulletedList1.DataSource=Courses;
BulletedList1.DataBind();
}
public List<string> GetCourses() //prepared
{
List<string> obj=new List<string>();
obj.Add(ASP.NET 4.0);
obj.Add(C#.NET 3.0);
obj.Add(VB.NET 3.0);
obj.Add(SQL Server);
obj.Add(Biztalk Server);
return obj;
Srikrishna
Page46
Naga Raju
Ram
Sri Sai
ASP.Net -}
of control.
We also get relation between control & data i.e., if we reflects with that
& viceversa..
Some advanced List controls are TreeView &Menu under Navigation tab.
This controls also support same behavior like List controls i.e. Design time,
runtime, dataBinding .
Add new item Webform home.aspx
Go to ToolBox Navigation Menu(Drag & Drop)- edit Menu Item
We add items click (+) button added item billow process.
We add sub items also select contact Us and click (+) button added sub item
same as process.
After we select Auto format:
Srikrishna
Page47
Naga Raju
Ram
Sri Sai
ASP.Net --
<programname>?name=value&name=value.255 characters.
?..........> separating program name and values.
&> separating name = value pairs.
Response.Redirect(default9.aspx?acno=+TextBox1.Text);
To read the passed value from QueryString we will use another object
of ASP.NET called Request.
For Ex:- Request[acno]will read the value called acno. In our
Srikrishna
Page48
Naga Raju
Ram
Sri Sai
ASP.Net --
in default9.aspx click load page & double click write following code:
Srikrishna
Page49
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page50
Naga Raju
Ram
Sri Sai
ASP.Net --
-------------------------------------------------------------------------------------------- In Defalut9.aspx?acno=1001&acname=SCOTT
We can redirect to other website also.
Response.Redirect(http://www.google.co.in)
-------------------------------------------------------------------------------------------- Default8.aspx (Design page) added one more button Help.
of querystring.
Add a new item webform default10.aspx
Code:
Naresh Tech. Class Notes
Srikrishna
Page51
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page52
Naga Raju
Ram
Sri Sai
ASP.Net --
Write the code from default8.aspx page select Page_Load & double click,
write code:
Srikrishna
Page53
Naga Raju
Ram
Sri Sai
ASP.Net --
Other options are Hyperlink of ASP.NET, Hyperlink of html & also with some
other controls like Menu, TreeView, and ImageMap.
MultiView Control (Rich Controls): It is used to Display multiple Views within a single page. Normally if we
have 2 pages content we have to design them in 2 pages. Using
Srikrishna
Page54
Naga Raju
Ram
Sri Sai
ASP.Net --
Place
Place
Place
Place
view.
Login
MultiView1.ActiveViewIndex=0;
Shopping
MultiView1.ActiveViewIndex=1;
EEE Way
MultiView1.ActiveViewIndex=2;
www.ebay.in is the world number one site for e-commers sites.
Srikrishna
Page55
Naga Raju
Ram
Sri Sai
ASP.Net -
Dt: 28-04-2010
Dynamic Validator is not there in Visual Studio 2008 we want this option in
VS 2008 we install SPI for VS 2008 & also .NET 3.5 (800mb).
In Visual Studio 2010 we can direct use Dynamic Validator.
1. RequiredFieldValidator:
Used to check for null values among all validation controls only this
control performs null value checking. Rest of the controls perform
validation if value is entered otherwise they ignore validation only.
Srikrishna
Page56
Naga Raju
Ram
Sri Sai
ASP.Net --
JS Complex
- Time consuming
- ASP.NET Validation controls generates JavaScript for users, so that we
need not write explicitly JavaScript.
Srikrishna
Page57
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page58
Naga Raju
Ram
Sri Sai
ASP.Net --
All Validation controls are initially treated as invisible controls when error
occurs then they display error message & also step user in submitting the
form.
On successful validation they remove error massage & allow stop user in
submit the form.
2. RangeValidator:
Used to check for range of values. Very use full for numeric &
date type of data. Dont use it for string type of data.
- MinimumValue
- MaximumValue
- Type:Integer/Date/.
Srikrishna
Page59
Naga Raju
Ram
Sri Sai
ASP.Net --
There is one common property for all validation controls called display.
Display: static (d)/dynamic/none.
Static means the place for displaying error message will be
reserved.
Dynamic means only when error occurs, it creates place for
3. CompareValidator:
Used to perform validations which are comparison based 3 types compression
can be done.
a) Control with another control
ControlToValidate
ControlToCompare
ErrorMessage
Naresh Tech. Class Notes
Srikrishna
Page60
Naga Raju
Ram
Sri Sai
ASP.Net -
Operator
Type
b) Control-Value:
- ControlToValidator:Text
- ValueToCompare : 10
- Type : Integer
- Operator : Greater then
- ErrorMessage : Min 10 (or) above 10
Srikrishna
Page61
Naga Raju
Ram
Sri Sai
ASP.Net --
4. ValidationSummary:
This doesnt perform any validation instead it collects all validation error
messages& displays them in one place as a summary.
Srikrishna
Page62
Naga Raju
Ram
Sri Sai
ASP.Net --
6. CustomValidator:
Naresh Tech. Class Notes
Srikrishna
Page63
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page64
Naga Raju
Ram
Sri Sai
ASP.Net --
Server side means code which will be executed @ server after submitting the
form.
Place CustomValidator & set the following properties,
ControlToValidator:
ErrorMessage:
Go to Events & Select ServerValidate*event. As we select this VisualStudio
automatically adds a function in code window. We have to write validation
code here to perform our validation.
protected
void
CustomValidator1_ServerValidate(object
source,
ServerValidateEventArgs Args)
{
if(int.Parse(args.Value)%5==0)
args.IsValid=true;
else
args.IsValid=false;
}
Srikrishna
Page65
Naga Raju
Ram
Sri Sai
ASP.Net --
else
Label1.Text=please correct the errors;
}
ValidationGroup**
- Added in ASP.NET 2.0 used to make different validation groups in a
single form. When we want different validation sets in as single from
then we have to use this group property.
Srikrishna
Page66
Naga Raju
Ram
Sri Sai
ASP.Net --
Client Targeting:
Srikrishna
Page67
Naga Raju
Ram
Sri Sai
ASP.Net -*** END OF THE DAY ***
Dt: 04-05-2010
EnableClientScript true/false:
Client target will apply validation settings for entire page. If we want to perform only
for control then we can use EnableClientScript property of Validation control.
Srikrishna
Page68
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page69
Naga Raju
Ram
Sri Sai
ASP.Net --
ASP.NET DataBinding
In List Controls DataBinding example was shown. In DataBinding we prepare
2 objects.
1. Data object: data from various data Sources.
2. Bound Control: presentation Control.
Data object + Bound Control = DataBinding (Effective presentation).
ASP. NET has data Tab in ToolBox which exclusively displays all dataBinding
related controls. In this we have controls that prepare data objects & also
controls that provide presentation.
Apart from this we have one exclusive concept in ASP.NET 4.0 onwards called
Dynamic data. This concept is also for dataBinding with RAD & Rich features.
AJAX, Silver light, WCF are new Concept which are today most used in
application development. All these concepts also provide dataBinding with
their Controls.
In data Tab the controls that prepare data objects are called DataSource
Controls. In data Tab the controls that present data are called Bound Controls.
We can prepare data objects in 2 important ways,
1. Programmatically with N-Tier model.
2. Using DataSource controls in little RAD style.
Different DataSource controls are available for different type of data Sources.
SqlDataSource
- This control is used to prepare data object from all databases that
prepared.
Place GridView control which is bound control & specify its DataSource
Srikrishna
Page70
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page71
Naga Raju
Ram
Sri Sai
ASP.Net -Dt: 06-05-2010
Srikrishna
Page72
Naga Raju
Ram
Sri Sai
ASP.Net --
i. SqlDataSource
ii. LinqDataSource
iii. EntityDataSource
SqlDataSource is used to get data from databases directly. Which is not
prepared model today from working with databases.To data all applications
like .NET, Java & other follow a model called ORM (object Relational Model).
The main idea behind ORM is to represent data & objects as same. We must
have presented object with represent backend tables. In .NET we have two
Srikrishna
Page73
Naga Raju
Ram
Sri Sai
ASP.Net --
required table.
Create GridView & assign it to LinqDataSource.
Srikrishna
Page74
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page75
Naga Raju
Ram
Sri Sai
ASP.Net --
Steps:1
Add new item from App_code folders and select Ado.Net entity Data Model.
This is used to create classes or object in the form of Entities. Once we add
automatically connection to database followed by tables are displayed for
selection. After giving the inputs we will get a designer where we can see as
model.
Add Gridview and set its DataSource to created Entity DataSource.
Assembly
.exe
executable
App_Data:
This folder is used for storing data related files.
Ex: - XML
How to Add them?
Just Right Click in solution explorer Add ASP.NET Folder (Required folder)
Srikrishna
Page76
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page77
Naga Raju
Ram
1. Go
Sri Sai
ASP.Net -to
App_code&create
class
called
DataHelper.Add
New
ItemDataHelper.
2. Write code in this class which can get data from database as well as send the
data to database. In general this code is written in generic style which
means works for multiple users.
3. Create another class called BLJobs. This will be business layer in our
Example. Write methods in this also to get data from dll & other activities.
Naresh Tech. Class Notes
Srikrishna
Page78
Naga Raju
Ram
Sri Sai
ASP.Net --
Code page:
protectedvoid page_Load()
{
}
protected void Button1_click(object.)
{
BLJobs obj=new BLJobs();
GridView1.DataSource=obj.GetJobs();
GridView1.DataBind();
}
*** END OF THE DAY ***
Srikrishna
Page79
Naga Raju
Ram
Sri Sai
ASP.Net --
Linq to Sql & EDM are 2 concepts that are available in .NET to develop ORM
type of applications. In this Linq to Sql is limited to Sql Server & provides
mapping of Database tables to frontend objects.
Where as entity data model works with all databases as it follows provider
model like ADO.NET 2.0
EDM provides not just mapping the DB tables but also allows user to provide
conceptual model implementation.
If we can implement a conceptual model then we can do mapping also in
more rich manner, like creating one or more entities in frontend and map
them to single table/ object in DB-similarly objects in frontend mapping to
multiple tables of backend
ADO.NET Linq to Sql EDM
EDM gives conceptual model means starting Manual Design.
Srikrishna
Page80
Naga Raju
Ram
Sri Sai
ASP.Net --
Steps:1
2
Start a new website & Create EDM using the template provided.
Add new item Entity Data model
Design the model as required.
Go to App_code create a class called BLJobs which is our business layer
& write code using Linq(other also) to get data from crated objects.
Go to form crate button GridView & as UI usual write code to get data
from b1.
Srikrishna
Page81
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page82
Naga Raju
Ram
Sri Sai
ASP.Net --
(preferred
data
types
for
almost
all
purposes)
(System.Collections.Generic).
pubsModel.Job means a type called Job created in namespace called
pubsModel. EDM always creates its objects in a separate namespace unless
specified & unlike Linq to Sql which by default creates in dame namespace.
This when used List<T> it is collection of objects.
string a;
//namespace is a logical collection of object.
List<String>b;
----------------pubsModel.Job a;
List<pubsModel.Job>b; //b is collection of job
// no datasets/datardrs
Once return type is a collection of simple or complex type inside method we
have to write code to fill this collection with values & return it. Normal code to
do this job takes lot of lines so from .NET 3.5 we can use LINQ (Language
Integrated Query) & prepare our data easily. In our Example we have return
Linq Query to work with entities & get one or more records.
var x = from n in obj.jobs
selectn;
where obj is EDM & from n.is Linq Query.
X is implicitly declared variable which is provided from C# 3.0 in this
example contains all jobs records. (but not in List formats)
So we have to use ToList<T> method to convert the values into list format as
our return type is List<T>.
return x.ToList<pubsModel.job>();
--------------------------------------------------------------------------------------------------------public static List<string>GetCourses()
{
var x=from n in Courses select n.CourseName;
return x.ToList<string>();
}
Srikrishna
Page83
Naga Raju
Ram
Sri Sai
ASP.Net --
2 Windows Right click on edm on edm screen & select Mapping Details. We
can crate multiple entities & also handle current entities mapping with
storage.
Model Browser lets user View all the current entities & their storage entities.
Programmatically using ADO.NET 2.0 & Most Important with EDM (our above
examples).
Different presentation control added in .NET 4.0 for presenting data using
Data Binding.
- Chart Control.
This control provides all types of charts for our data. Moreover with data
binding style.
(Q)How is that possible?
Ans: - .NET uses graphics code & draws a chart on ply & saves it as an image or
stream. We can simply present the data to control & ask it to render as page
content. (Normally it is week days module to do in a project like this).
-------------------------------------------------------------------------------------------------------------------C://demo/.(right click) new form default2.aspx
---------------------------------------------------------------------------------------------------------------------
Srikrishna
Page84
Naga Raju
Ram
Sri Sai
ASP.Net --
GridView
In all over previous examples we have learn how prepare data objects in
simple ADO.NET 2.0 method and also much prepared e have to plane for
presentation requirements. Among all data Bound controls GridView &
ListView are feature-Rich controls these controls provide Maximum support
for providing affective presentation.
Srikrishna
Page85
Naga Raju
Ram
Sri Sai
ASP.Net --
Chart
DataList
DetailsView
FormView
GridView
ListView
Repeater
Srikrishna
Page86
Naga Raju
Ram
Sri Sai
ASP.Net --
Ex:-<asp:BoundField DataFiled=job_id
HeaderText=Code/>
-
Take new form place Button & GridView inside it. In button write code
Srikrishna
Page87
Naga Raju
Ram
Sri Sai
ASP.Net --
<asp:GridViewID=GridView1
runat=Server
AutoGenarateColumns=False>
<Columns>
<asp:BoundField=job_id HeadText=code/>
<asp:BoundField=job_desc HeadText=Description/>
<asp:BoundField=Min_lvl HeadText=MinLevel/>
<asp:BoundField=Max_lvl HeadText=MaxLevel/>
</Columns>
Go to Design Page:
Srikrishna
Page88
Naga Raju
Ram
Sri Sai
ASP.Net -A Template is like container or place holder where we can place any
type of content.
Different templates are available to fulfill different requirements,
a. HeaderTemplate: To Display the heading for a column.
b. FooterTemplate: To Display Footer information for a Column.
c. ItemTemplate:ToDisplay the content of GridView we have to use
this template, it will be repeated for every row of data object. This
template like others can have only content inside it i.e., both data
object related as well as independent content.
Other Templates also:
TemplateField
-Collection of Templates
-Header Template
-Footer Template
-Item Template
DataBinding Expressions: TemplateField has to no attribute or property to display data object data. To
get data from any other bound object in template field we
have to use
Srikrishna
Page89
Naga Raju
Ram
Sri Sai
ASP.Net --
Will invoke the GetRating function written in code window. Whatever this functions
returns it will display in this place.
TemplateField Example:
Add Newform- place Button & GridView in the form.
In button write code to bind data to GridView.
Go to GridView & set AutoGenerateColumns: false
Go to SourceView & write Columns information using TemplateField this
time.
Go to Source:
<asp: GridView ID=GridView1 runat=server/>
<Columns>
<asp: TemplateField>
Naresh Tech. Class Notes
Srikrishna
Page90
Naga Raju
Ram
Sri Sai
ASP.Net --
<HeaderTemplate>
Job
</HeaderTemplate>
<ItemTemplate>
//(Goto TooBox Drag & Drop CheckBox on this place)
<asp:CheckBox ID=checkBox1 runat=server/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
(i)<HeaderTemplate>Description<br></HeaderTemplate>
//After <Br> Drag & Drop one Image I Solution Explorer
(OR)(ii)<HeaderTemplate>Description<br/>
<img src=image42.jpg height=70 width=70/></HeaderTemplate>
<ItemTemplate>
<%# Eval(job_desc)%>
</ItemTemplate>
</asp: TemplateField>
<asp:TemplateField>
<HeaderTemplate>MaxLevel</HeaderTemplate>
<ItemTemplate>
//Drag &Drop HyperLink& Remove HyperLink Message Data
<asp:HyperLink text=<%# Eval(Max_lvl)%>>
NavigateUrl=~Default.aspx
Target=w1
ID=HyperLink1 <img src=img45.jpg/>runat=Server
</ItemTemplate>
Naresh Tech. Class Notes
Srikrishna
Page91
Naga Raju
Ram
Sri Sai
ASP.Net --
</asp:Template>
</Columns>
Exercises:1. Using BoundField display job id, description, Min level, Max level & one more
column diff. which is MaxLevel MinLevel(using BLJobs & EDM only)
2. Using BoundField (or) TemplateField (any one)display additional column called
Rating for all max_lvl above display a 5 star image.(for above 40 display 4
stars, 30 display 3 stars, 20 display 2 stars).
*** END OF THE DAY ***
Dt: 17-05-2010
3) CommandField of GridView & GridView Editing:
GridView not only presents the data but also provides good editing
support. It has not one field called CommandField which is used to
display edit, update, Delete & Cancel Button.
GridView supports editing of data using all its fields like BoundField,
TemplateField, CommandField, etc it has a property called EditIndex.
Whosedefault value is -1 & provides Edit Table Row based on the given
value.
How GridView editing is supported?
Ans:-The key for editing data in GridView is edit index. When we
specify EditIndex value to n, then nth record is set to be Editable
record. All GridView fields react to EditIndex property.
How BoundField React to EditIndex?
Naresh Tech. Class Notes
Srikrishna
Page92
Naga Raju
Ram
Sri Sai
ASP.Net -Ans:- when EditIndex is -1 which is its default value BoundField
displays all records with simple text (as we have seen)when EditIndex
is set to sum record number then nth record will be display with
TextBoxes for editing & remaining all rows will be displayed in simple
text format.
How TemplateField react?
Ans:-TemplateField is also dependent on EditIndex property. It displays
item template content for all the rows & EditItem template for nth row
that is, when EditIndex is changed.
Ex:
publicList<ns.class> GetJobs()
{
ns. entities obj=new..();
var x=from n in obj. table select n;
}
---------------------------------------------------------------------------------------------------------Note:1. What is the important of EditIndex?
2. How BoundField, TemplateField is Dependent on EditIndex?
3. What is the use of CommandField?
------------------------------------------------------------------------------------------------------- CommandField also reacts of EditIndex value it will display edit &
delete buttons when EditIndex is -1 & displays update Cancel for nth
row.
We must provide editing of GridView using the entire above concept.
Demo:1. Assuming our EDM objects & BLJobs are present in the project (if not present
create them)add new form & placeButton, GridView inside it.
2. Write code in button to get data from BLJobs & Bind it to GridView.
3. Go to GridView & set AutoGenerateColumns to false. Go to SourceView &
write code for GridView this time along with editing support****. Including
BoundField, TemplateField & CommandField. (New: Read only, EditItem
Template, CommandField).
Srikrishna
Page93
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page94
Naga Raju
Ram
Sri Sai
ASP.Net -ShowCancelButton=true
ShowDeleteButton=true/>
4) All CommandField controls have their own events with GridView. It is must to
handle them otherwise they will raise an unhandled exception.
Edit
RowEditing
Update
RowUpdating
Cancel
RowCancelingEdit
Delete
RowDeleting
All the above event also have Completed task event. i.e., RowDeleted which fires
after deleting the row whereas Row Deleting when user click on Delete.
Select GridView
Srikrishna
Page95
Naga Raju
Ram
Sri Sai
ASP.Net --
GridView1.Rows[0]
-
GridView1.Rows[0].Cells
-
GridView1.Rows[0].Cells[0]
-
GridView1.Rows[0].Cells[0].Text
Naresh Tech. Class Notes
Srikrishna
Page96
Naga Raju
Ram
-
Sri Sai
ASP.Net -1st Row 1st Cell text provided that Cell Contains simple text.
GridView1.Rows[0].Cells[0].Controls
-
GridView1.Rows[0].Cells[0].Controls[0]
-
Ex:1 GridView1.Rows[1].Cells[1].Text
3GridView1.Rows[2].Cells[0].Control
This type of retrieval is used when BoundField implicitly creates a control
because we dont know the name of that implicitly created controls.
If we want to retrieve data from explicitly created controls like in
TemplateField case then we have to use one common method of page object
called FindControl(<id>)***.
This method searches for the given control in the given context & returns
reference. It returns null when there is no control with the given id.
Ex:- GridView1.Rows[0].FindControl(ListBox1);
Searches for ListBox1 in the first row of GridView and returns its reference.
This reference can be used to access the control directly.
GridView1.Row[0].Cells[2].Controls[0]
GridView1.Row[0].FindControl(GridView2).Cells[2].FindContr
ols(Tb2).
GridView
x=GridView1.Rows[0].Cells[2].FindControl(GridView2);
ListBox y=x.Rows[0]. FindControl(LB1);
Srikrishna
Page97
Naga Raju
Ram
Sri Sai
ASP.Net --
GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
ListBox lb1=(LsitBox)
GridView1.Rows[e.RowIndex].FindControls(ListBox1);
//preparing values to pass for Business Layer (BL) .
DB3PMModel.job mjobrec=new DB3PMModel.job();
mjobrec.job_id=int.Parse(mjobid);
mjobrec.job_desc=tjobdesc.Text;
mjobrec.Min_lvl=int.Parse(lb1.SelectValue);
mjobrec.Max_lvl=40;
BLJobs obj=new BLJobs();
Obj.UpdateJob(mjobrec);
GridView1.EditIndex=-1;
LinkButton1_Click(Sender, e);
}
publicBLJobs()..
public List<DB3PMModel.job>GetJobs()
public void UpdateJob(DB3PMEntities obj=new DB3PMModel
DB3PMEntities();
Srikrishna
Page98
Naga Raju
Ram
Sri Sai
ASP.Net --
is
dataBinding&how
dataBinding
is
feature
in
application
development?
How BoundControl id different than on DataSource control?
How to present data in GridView which is added on-fly?
What type of outputs we cannot produce using GridView?
What will happen if AutoGenerate Columns:true& we provide manually some
Columns?
Ans:-AutoGenerate will display & our Cols also get display.
6. Can we place if button in GridView Columns? Explain?
Ans:-No, only GridView Fields are allowed.
7. Which property of GridView provides Editing of data & how it is related to
GridView Fields?
8. Can we access we have Nested GridViews & if passible how to access outer &
InnerGridViews?
*** END OF THE DAY ***
Dt: 19-05-2010
More GridView Tasks: GridView has different classes to represent its rows, columns & other things.
It has collections like rows/columns etc which can be navigated using its
types like GridViewRow, GridViewColumn etc
In our editing example we have retrived the current row of gridview & most of
the cases we need to retrieve complete GridView & some selected rows in
GridView. In such cases we have to use some events which firefor every row
or we have to use soe logic for navigation.
Srikrishna
Page99
Naga Raju
Ram
Sri Sai
ASP.Net --
Example-1:
In Source page:
<asp: GridView ID=GridView1 runat=server AutoGenaration..>
<Columns>
<asp:TemplateField HeaderText=Choose>
<ItemTemplate>
Drag & Drop CheckBox
<asp: CheckBox ID=CheckBox1 runat=server/>
</ItemTemplate>
</asp:Template>
<asp:BoundField=Job_desc HeaderText=Description>
<asp:TemplateField HeaderText=Difference>
<ItemTemplate>
<%#Convert.ToInt32(Eval(Max_lvl))-Convert.ToInt32(Eval(Min_lvl))%>
</ItemTemplate>
</asp:Template>
<asp:TemplateField HeaderText=Level>
<itemTemplate>
<%#GetLevel(Eval(job_desc))%>//on GetLevel Right click watch CODE
</ItemTemplate>
</asp:Template>
-----------------------------------------------------------------------------------------------------Go to Code page window:
Srikrishna
Page100
Naga Raju
Ram
Sri Sai
ASP.Net --
{
//place to write code & generate output
if(jobdesc.ToString.ToUpper().Contains(PROGRAMMER))
return Technical;
elseif(jobdesc.ToString().ToUpper()==MANAGER))
return Manager;
else
return others;
}
protectedvoid Button2_Click()
{
ListBox1.Items.Clear();
foreach(GridViewRow rec in GridView1.Rows)
{
CheckBox c1=(CheckOut)
rec.FindControl(CheckBox1);
if(c1.Checked)
ListBox1.Items.Add(rec.Cells[1].Text);
}
}
protectedvoid Button2_click(..)
{
ListBox1.Items.Clear();
foreach(GridViewRow rec in GridView1.Rows)
{
checkBox c1=(CheckOut)
rec.FindControl(CheckBox1);
if(c1.Checked)
ListBox1.Items.Add(rec.Cells[1].Text);
}
}
Modification of Example-1:
In Source page:
<asp: GridView ID=GridView1 runat=server AutoGenaration..>
<Columns>
<asp:TemplateField HeaderText=Choose>
<ItemTemplate>
Drag & Drop CheckBox
<asp: CheckBox ID=CheckBox1 runat=server/>
</ItemTemplate>
</asp:Template>
<asp:BoundField=Job_desc HeaderText=Description>
<asp:TemplateField HeaderText=Difference>
<ItemTemplate>
Naresh Tech. Class Notes
Srikrishna
Page101
Naga Raju
Ram
Sri Sai
ASP.Net --
<%#Convert.ToInt32(Eval(Max_lvl))-Convert.ToInt32(Eval(Min_lvl))%>
</ItemTemplate>
</asp:Template>
<asp:TemplateField HeaderText=Level>
<itemTemplate>
<%#GetLevel(Eval(job_desc))%>//on GetLevel Right click watch CODE
</ItemTemplate>
<FooterTemplate>
<%#GetTotal()%>
</FooterTemplate>
</asp:Template>
Go to Code page window:
Output:
Srikrishna
Page102
Naga Raju
Ram
Sri Sai
ASP.Net --
in default4.aspx
protectedvoid Button2_Click()
{
ListBox1.Items.Clear();
foreach(GridViewRow rec in GridView1.Rows)
{
/*for(int i=0; i<GridView1.Count -1; i++)*/
CheckBox c1=(CheckOut)
rec.FindControl(CheckBox1);
if(c1.Checked)
ListBox1.Items.Add(rec.Cells[1].Text);
}
}
protectedvoid Button2_click(..)
{
ListBox1.Items.Clear();
foreach(GridViewRow rec in GridView1.Rows)
{
checkBox c1=(CheckOut)
rec.FindControl(CheckBox1);
if(c1.Checked)
ListBox1.Items.Add(rec.Cells[1].Text);
}
}
public string GetTotal()
3
{
Srikrishna
Page103
Naga Raju
Ram
Sri Sai
ASP.Net -returnTotal:+1.ToString();
}
Srikrishna
Page104
Naga Raju
Ram
Sri Sai
ASP.Net --
in presenting data.
No builting layers for designing are provided with this control.
No features like sorting, paging & editing is supporting by repeater. If
required we have to manually & logically performed these tasks.
Repeater data list are available from first version of .NET & they have
On Example:
-
Go to Source Page:
<asp:Repeater ID=Repeater1 runat=Server>
<HeaderTemplate>
JOB ID
Description
MinLevel
MaxLevel
</HeaderTemplate>
<ItemTemplate>
<%#Eval(job_id)%>
<%#Eval(job_desc)%>
<%#Eval(Min_lvl)%>
<%#Eval(Max_lvl)%>
</ItemTemplate>
<SeparaterTemplate>
-----------------------------------------------------------------------Naresh Tech. Class Notes
Srikrishna
Page105
Naga Raju
Ram
Sri Sai
ASP.Net -</SeparaterTemplate>
</HeaderTemplate>
<ItemTemplate>
<tr>
//<td>drag&drop checkBox</td>
<td>
<asp:CheckBox ID=checkBox1
Text=<%#Eval(job_id)%> runat=server/>
</td>
<td>
<%#Eval(job_desc)%>
</td>
<td>
<%#Eval(Min_lvl)%>
</td>
<td>
<%#Eval(Max_lvl)%>
</td>
Naresh Tech. Class Notes
Srikrishna
Page106
Naga Raju
Ram
Sri Sai
ASP.Net --
SiteInfo
SiteName
Description
RelatedSite1
RelatedSite2
Rating
Design a web form exactly like Google search screen. When user clicks on go take
the keywords typed in textbox & display the relevant sites information same like
Google result.
Srikrishna
Page107
Naga Raju
Ram
Sri Sai
ASP.Net --
3)
4)
control*.
Grate Images folder and place all images which are mentioned in the records.
Right Click New Folder ShImages
Create a form and place Button, DataList.
In button write code to read data from xml file and bind it to DataList.
Srikrishna
Page108
Naga Raju
Ram
Sri Sai
ASP.Net --
Note:- Map path will cannot logical directory to physical directory and provides the
real path. It is useful method because our files are accessed with virtual name.
C:\\NitApp\EDMBE\Items.xml
Ex:- DataSet Shift+ Alt+ F10 It is used for working class with automatically
namespace is added of that class.
Using System.Data
protected void LinkButton1_Click()
{
DataSet ds=new DataSet();
ds.ReadXml(MapPath(Items.xml));
DataList1.DataSource=ds;
DataList1.DataBind();
}
5) Go to DataList Source View and write code to display image followed by other
information.
<asp:DataList ID=DataList1 runat=server>
<ItemTemplate>
<asp:ImageButton ID=m1 runat=server
ImageUrl=<%#Eval(Image)%> Height=150 Width=150/>
<br/>
<asp:LinkButton ID=link1 runat =server
Text=<%# Eval(description)%>>
</asp:LinkButton>
<br/>
<img src=ShImages/bin.gif/>
<%#Eval(Price)%>
</ItemTemplate>
</asp:DataList>
6) Go to DataList backend set some auto format followed by some properties to
control the layout. CellSpacing, CellPadding, RepeatColumns, RepeatLayout,
RepeatDirection, etcare some useful ones.
Cell Spacing = 2
Cell Padding = 4
RepeatColumns = 3
RepeatDirection= vertical/horizontal.
Repeat Column is unique features of DataList and when we set it to 3 it displays in
a row 3 records RepeatDirection provides the order in which the records should be
displayed.
Naresh Tech. Class Notes
Srikrishna
Page109
Naga Raju
Ram
Sri Sai
ASP.Net --
&
CommandArgument**
which
communicates
with
Srikrishna
Page110
Naga Raju
Ram
Sri Sai
ASP.Net --
</form>
</body>
Go to DataList & select ItemCommandevent & write the following code:
o protected void DataList1_ItemCommand(object.)
{
if(e.CommandNmae==m1)
Response.Redirect(Show.aspx?img= e.CommandArgument.toString());
else if(e.CommandName==l1
Response.Redirect(details.aspx?id= +e.CommandArgument.ToString());
}
}
Based on selection mode inside GridView or DataList we have called diff.
pages carrying the current page selection. For ImageButton we have pass the
name of image & for Linkbutton we have pass primary key of table. So that
we can retrieve data from database a way in the new page using primary key
value.
When want to interpret data binding process then we can use the events
which are provided the bound control. This requirement is unique & solution
to this also performed in unique way with supported events.
DataList has an event called ItemDataBound & ItemCreated which can be
used to perform this type of action. In our example select DataList & choose
ItemDataBound followed by code to Highlight the total row & also create
control at runtime.
Shop.aspx.cs:
protectedvoid DataList1_ItemDataBound(object sender,
DataListItemEventArgs e)
{ // for every row -- v v Important
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem )
{
Label l1 = (Label)e.Item.FindControl("lp1"); // price
if (Convert.ToDouble(l1.Text) < 5000)
{
e.Item.BackColor = System.Drawing.Color.LightGreen;
ImageButton i1 = newImageButton();
// i1.Height=....
i1.ImageUrl = "~/picture1.gif";
e.Item.Controls.Add(i1);
}
}
}
In our demo replace
<%#Eval(price)%> with <asp:Label ID=lp1 runat=server
Text=<%Eval(price)%>/>
Naresh Tech. Class Notes
Srikrishna
Page111
Naga Raju
Ram
Sri Sai
ASP.Net --
FormView & DetailsView: GridView, Repeater & DataList doesnt provides any inserting option for
adding records. (Which not a drawback).
Normally insert in done using standard & other controls. ( Foster, un-structure
Unique Features)
Still in ASP.NET 2.0 to support inserting for data in DataBinding style we are
provided with FormView & DetailsView.
Both these controls are unique in providing inserting options.
Both these controls are derived from GridView base classes which mean they
support GridView tasks like editing of data, paging of data, etc
Why 2 controls to provides inserting?
Ans:- DetailsView is based OnFields like GridView & FormView is based on
templates like repeaters like Repeater & DataList.
Based on Requirement i.e., if unstructured requirement then FormView
otherwise DetailesView.
Ex:These controls are most used with DataSource controls not programmatically. In
some cases we can even use programmatically.
Palce SqlDataSource or any other datasource in the form & configure the
database/ table for it. Ensure that Generate Insert, update & Delete
statements is selected in advanced button option.
Place DetailsView or FormView control & assign DataSource to the created
Control.
In Details View/FormView go to smart tag & enable all the required options
like editing, inserting *, etc
Srikrishna
Page112
Naga Raju
Ram
Sri Sai
ASP.Net --
We can use smart tag EditTemplates options also in order design the layout.
This feature is available for DataList, GridView & these 2 controls.
Ex-2:- A form with all CRUD operations including all types of view.
Srikrishna
Page113
Naga Raju
Ram
Sri Sai
ASP.Net --
Ex:-DetalisView:-
Srikrishna
Page114
Naga Raju
Ram
Sri Sai
ASP.Net --
Master / Details output using GridView (can be done with other controls also)
Jobs master table
Employee child table
C: //... (Right click) add a new form webform default3.aspx
Srikrishna
Page115
Naga Raju
Ram
Sri Sai
ASP.Net --
OUTPUT:-
Srikrishna
Page116
Naga Raju
Ram
Sri Sai
ASP.Net --
ListView Control
ListView Control:- (Its new control from 4.0)
ListView Goals:o Template list control completes the ASP.NET 2.0 data bound control
o
o
o
o
o
o
family.
Allows developers to completely control the rendered markup.
CSS & scripting friendly.
Full support for data source capabilities.
Satisfies common client requests.
Rich design time experience.
Finally simple to use.
In .NET 4.0 we can use ListView without a layout template which is another
feature that it provides.
Conclusion:ListView can work like all other Controls***.
ListView can be Templated ***.
ListView need not be Templated ***.
Srikrishna
Page117
Naga Raju
Ram
Sri Sai
ASP.Net --
VS.NET 2010 design time view will really make user develop ListView outputs
easily. Because writing layout template for structured & unstructured may not
be very easy for a developer & this is what the design time view helps user. It
helps user to generate layout template for almost all types of presentations.
Note: - we select one by one then the preview Box see the coding of that particular
task.
Srikrishna
Page118
Naga Raju
Ram
Sri Sai
ASP.Net --
ASP.NET Configuration
Dt: 27-05-2010
ASP.NET Configuration: For any application configuration base development is more preferred.
The only reason to avoid configuration is when we have to write lot of
additional code & maintenance.
Most part of .NET is designed based on configuration. CLR based on
configuration & most of the libraries are also based on configuration settings.
Srikrishna
Page119
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page120
Naga Raju
Ram
Sri Sai
ASP.Net --
These are simple text files & can be edited using any simple text editor.
These are xml formatted (case sensitive) & any xml programs can use these
files or they can be directly edited because xml is human readable.
* They are automatically cached on memory for faster retrieval of settings
(Cache memory programmed memory area).
* Processed in hierarchical manner which means every configuration file
inherits its parent configuration file settings. The root for all these files is
Machine.Config.
Also called as configuration inheritance apart from this configuration is also
hierarchical as xml is hierarchical.
Machine.Config points:
It is called per-server basis file. Only one machine.config is allowed for one
runtime/server.
Located .NET framework folder not on our project & all settings are common
to all websites running in that system. * 4 MB (default)(more than 4.0 go to
machine.config one file- change)
Most of the settings are maintained by administrator but not by application
developers.
Web.Config points:
It is called as application Configuration file.
our project.
*** END OF THE DAY ***
Dt: 28-05-2010
Configuration Structure:<configuration>
<section>
<subsection>
..
Naresh Tech. Class Notes
Srikrishna
Page121
Naga Raju
Ram
Sri Sai
ASP.Net --
</configuration>
A user should know the setting importance the section under which it comes and its
syntax.
i). <appSettings>
In ASP.NET one excellent method to create application wide static variables is
using <appSettings>tag.
In ASP.NET static variables are not recommended dont use them. This setting
comes under configuration i.e., <root>tag.
Syntax:<appSettings>
<add key=a value=100/>
..
</appSettings>
System.Configuration is the namespace where all configuration relevant
classes are present in assembly (System.Configuration.dll)
ConfigurationManager(old.ConfigurationSettings) is the class which is used to
retrieve ConfigSettings.
Ex:-create a form and place image/label. Write code in page_load to read
appSettings using the relevant class and its collection.
Add a new aspx.cs
usingSystem.Configuration;
public partial class Default7:System.web.UI.page
{
protected void page_load(object.e)
{
Image1.ImageUrl=configurationManager.AppSettings[logo];
Label1.Text=ConfigurationManager.AppSettings[Title];
}}
A child web.Config file can by default overwrite the parent settings****.
for Ex: Create admin folder and create web.config;
Add title appSettings again inside it. All admin pages will get admin
web.config title value but not root value.
We can use appSettings and some other web.Config settings directly in
markup without any coding. (this is a big advantage).
Syntax:<%$ Section:key%>
<body>
Naresh Tech. Class Notes
Srikrishna
Page122
Naga Raju
Ram
Sri Sai
ASP.Net --
All browsers started supporting this type of communication. By user 2005 all user/
browsers with drawback also started implementing AJAX..
AJAX------ Asynchronous Communication partial page outputs/processing.
Dis-Advantages:1.
2.
3.
4.
Srikrishna
Page123
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page124
Naga Raju
Ram
Sri Sai
ASP.Net -<add name=sql con
connectionString=Data Source=..;
Initial Catalog=DBSPM;
Integrated Security=True
ProviderName=System.Data.SqlClinet
Once defined we can use in the program again with configuration Manager
class.
Example to use it:protected void Button1_Click(object..)
{
String constr=ConfigurationManager:ConnectionStrings[sqlcon].ConnectionString;
SqlConnection cn=new SqlConnection(cn str);
cn.open();
Label1.Text=Connnected
}
(Q). what is the difference b/w defining cnstr in appSettings and in
ConnectionStrings?
****iii).<Compilation>
o
Srikrishna
Page125
Naga Raju
Ram
Sri Sai
ASP.Net --
To set a different default language for all runtime code and for entire project we can
use default language attribute of <compilation> tag.
*** END OF THE DAY ***
Dt: 01-06-2010
<system.web>
<system.net>
<mailsettings>
----------------------SMTP Specification
(Simple Mail Transport Protected) an open standard protected.
HTTP is for request/response
SMTP is for sending mails.
Irrespective of type of application all must follow SMTP for sending mails.
SMTP servers are those which implements SMTP specification and which are
softwares used to send mails.
As a .NET user our job is to arrange an SMTP server (or) design our own SMTP
server use .NET SMTP Client Libraries in order to send mail to recipient using
SMTP Server.
IIS which is well known as HTTP server also provides SMTP and FTP
functionality.
As a user after arranging an SMTP server we have to write program by
preparing message and other required things and submit it to SMTP server.
Simple Architecture Diagram:-
Mail Message
To prepare complete mail content.
SMTPClient**
To communicate as client to SMTP server.
To send message prepared to SMTP server.
Srikrishna
Page126
Naga Raju
Ram
Sri Sai
ASP.Net --
using System.Net;
using System.Net.Mail;
public partial class_Default:system.Web.UI.page
{
MailMessage msgobj;
protected void ImageButton1_click(object..)
{
//send button code
SmtpClient serverobj=new SmtpClient();
serverobj.Credentials =new NetworkCredential(TextBox1.Text,TextBox2.Text);
serverobj.port=587; //25 is default for SMTP
serverobj.Host=smtp.gmail.com;
serverobj.EnableSsl=true;//default is false, secure socket layer
msgobj=new MailMessage();
msgobj.From = new MailAddress
(TextBox1.Text,NIT INFO,System.Text.Encoding.UTF8);
msgobj.To.Add(TextBox3.Text);
//..other properties //msgobj.priority =MailPriority
msgobj.Subject=TextBox4.Text;
msgobj.Body=TextBox5.Text;
msgobj.Attachments.Add (new Attachment(MapPath(bg3.jpg)));
msgobj.deliveryNotificationOptions=DeliveryNotifications.Onfailure;
serverobj.Send(msgobj);
Label6.Text=Mail Sent Successfully;
}
}
*** END OF THE DAY ***
Dt: 02-06-2010
Naresh Tech. Class Notes
Srikrishna
Page127
Naga Raju
Ram
Sri Sai
ASP.Net --
Web.config:
<system.net>
<mailSettings>
<smtp from=nbende@gmail.com>
<network
host=smtp.gmail.compassword=secret
port=587
username=nbende/>
</smtp>
</mailSettings>
</configuration>
Note:- by writing settings in web.config we can avoid all the value related in our
program, it is useful because for a project most of the time they are common.
Website Configuration Utility:Visual Studio .NET provides a tool or utility called website Administration tool (WAT).
Rich simplify the process of handling Configuration file. We can invoke the tool from
solution Explorer or from website menu option ASP.NET configuration.
..
<trace>tag
It will display or generate all the runtime process information for a request
can be used during debugging as well as after deploying.
It includes lot of information staring from client till server execution
everything can be traced.
By default trace is disabled at application level that at root web.configure can
use <trace>to enable it.
Ex:-<trace Enabled=true/>
protectedvoid Button1_click(object)
{
1).response.write(welcome);
//statement level traceing(OR)
Naresh Tech. Class Notes
Srikrishna
Page128
Naga Raju
Ram
Sri Sai
ASP.Net --
(OR)
3). if(Trace.IsEnabled)
{
for(int i=0;i<10;i++)
{
Trace.Write(i.ToString());
}}}
Go to Web.Config
================
<Configuration>
<appSettings>
<addKey=Title value=E.Learning Application123/>
<appSettings>
<system.Web>
i). <trace enabled=truepageOutput=false/>
ii). <trace enabled=truepageOutput=false requestLimit=5/>
iii). <trace enabled=truepageOutput=true WriteToDignosticsTrace=true/>
<compilation debug=true targetFramework=4.0/>
</system.Web>
Other important attributes are:
pageOutput=true/false
o default is false & when set to true appends trace results to the page
o
output.
If false the meaning is trace is generated but should be viewed with trace
trace.axd
requestLimit=<n>
default is 10
o which means 10 times trace output will be generated after other that no
trace is generated.
localOnly=true/false
o true menas only in localhost system tracing will be generated for other
users only output will be given.
Naresh Tech. Class Notes
Srikrishna
Page129
Naga Raju
Ram
Sri Sai
ASP.Net --
System.Diagnostics*****(refer)
writeToDiagnosticsTrace=true
o Will redirect all trace result to the mentioned diagnostics file for later
o
viewing.
All above trace settings are called Application Level tracing & we have
tracing for the current page this is called page level tracing.
In statements we have Trace object which will allow our outputs to be app
Data Security
Hackers Security
Public / private content
Transport level
OS windows server 2008-----1
IIS web server-----------2(Data Security, Hackers Security, Transport level)
ASP.NET CLR----------3(Public / Private Content)
(.NET)
Srikrishna
Page130
Naga Raju
Ram
Sri Sai
ASP.Net --
At ASP.NET / Project level we need to implement security with the provided support
(Good for developer).
..
1. Authentication:
o The process of verifying user credential again a data source is called
Authentication. This process after completing the verification creates &
identity which is also called as security ticket (at browser level it is called
Cookie).
2. Authorization:
o The process of allowing or denying a Requested resource based on users
identity is called authorization.
Both these are provided by ASP.NET & ***As a user we have to understand
their methods/support & implement security.
i.
Windows Authentication:
Srikrishna
Page131
Naga Raju
Ram
Sri Sai
ASP.Net --
|
IIS takes the request & check for identify. If identify is not found stops the
|
IIS Checks the given credentials against the O/S configured location & on
successful verification it creates an identity which is called Windows
Identity. It then redirects user to ASP.NET & ASP.NET redirects the secured
page to user.
Anonymous windows / IIS Authentication:
o We can configure a website users as anonymous users @ IIS level. The
meaning of setting Anonymous for a website is when unauthenticated
o
user makes a request IIS will itself create identify & send user to ASP.NET.
This is compulsory when we want to implement any other authentication
than windows.
At IIS Level we will have scope to implement Kerberos, MD5(Message
Digest) & SHA (Secure Hash Algorithm)..Windows authentication.
Windows Authentication
Basic Digest
None
Ans:- None
Because ASP.NET support above 1st 3 options.
Srikrishna
Page132
Naga Raju
Ram
Sri Sai
ASP.Net -*** END OF THE DAY ***
Dt: 04-06-2010
ii.
Passport Authentication:
o
FLOW:
window authentication.
|
User enters in to ASP.NET & ASP.NET redirects user to passport website.
o
o
Srikrishna
Page133
Naga Raju
Ram
Sri Sai
ASP.Net --
Note: Once passport identity is created then access may be granted to other
websites also which is passport identity.
iii.
Forms Authentication:*****
o
instructions (developer)
This authentication is most suitable for commercial & portal type of
applications. In other cases user accounts are kept with windows/passport
but not with our site. In this case all user info will be with our site only &
we can sue it for every business idea that we can implement.
Srikrishna
Page134
Naga Raju
Ram
Sri Sai
ASP.Net --
o
o
identified as authenticated.
In project intranet type of apps ----windows.
Internet
---Forms.
*** END OF THE DAY ***
Dt: 05-06-2010
In .NET 4 we have asp.net website template instead of empty website
template which automatically create all the security related content like user
Naresh Tech. Class Notes
Srikrishna
Page135
Naga Raju
Ram
Sri Sai
ASP.Net --
interface, security tags & other required things. We can use this for security
implementation in our website as it is provided with complete standards only.
Anyhow for complete customized security implementation we can even start
empty website & implement complete security.
(Q). How to implement forms Authentication?
Ans: - A plan is required to implement or add security to the project. In our
example we want to create publicly accessible content i.e., for every user who
enters into our site & private access content also***.
STEPS: Start a new website (.NET 4.0) & create homepage i.e., a web form with name
default.aspx
Create a folder called Admin So that we can store registered users or admin
users accessible content here (private).
Create forms in admin folder & design them according to requirement say
add.aspx, delete.aspx as samples.
Go to home page that is default.aspx in page in root & create hyperlinks to
admin page content i.e., 2 hyperlinks for Add & Delete pages.
Imp Point:-At this point of time if we execute our project user will get address
to all the pages of site which is not our requirement.
Why?
Because no security is implemented & default is windows authentication with
access to all files as authorization.
Go to root web.config & use <authentication mode = <forms /passport/
windows>>tag to specify forms authentication.
Go to Admin folder & create another web.config using add new item option. In
this web.config we have to change <authorization>using authorization tag.
This tag contains collection of <allow>&<deny> tags, where we can specify
which user is allowed for this resource & which user is denied for the
resource.
Syntax:<authorization>
<deny Users=<usernames/*/?/>>
<allow Users=<usernames/*/?>/?
..
..
Naresh Tech. Class Notes
Srikrishna
Page136
Naga Raju
Ram
Sri Sai
ASP.Net -</authorization>
? Represents unauthenticated user/Anonymous user
* Means all users
Ex:i)
<authorization>
<deny users=?/>
<allow users=Scott, Smith/>
</authorization>
ii)
<authorization>
<allow users=*/>
<allow users=Scott, Smith>
</authorization>
Srikrishna
Page137
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page138
Naga Raju
Ram
Sri Sai
ASP.Net --
Now once DataBase is ready with all requirements we have to prepare our
layers BL, DL &UI. So prepare EDM object for users & other tables (if already
EDM object are present then ensure that users tables are also present).
Add BL for users & write the required methods & code for it.
App_code/DLUsers.cs
pubilic class BLUsers
{
(+) public BLUser()....
(-) public void ValidateUser(DB3PMModel.user userdetails)
{
DB3PMModel.DB3PMEntities obj=new DB3PMModel.DB3PMEntities
var x=(from n in obj.users
where n.UserName==userdetails.UserName
&& n.Password==userdetails.Password
select n).FirstOrDefault();
if(x!=null)
return true;
else
Naresh Tech. Class Notes
Srikrishna
Page139
Naga Raju
Ram
Sri Sai
ASP.Net -return false;
}
public void AddUser(DB3PMModel.user userdetails)
{
//code to add the record in entities
}
Srikrishna
Page140
Naga Raju
Ram
Sri Sai
ASP.Net --
only-sometimes
in
our
logics
we
provide
groupname,
foldername, filename and also as our identity and write allow denys
accordingly***.
Ex:-Users
Username password
group/role
Scott
tiger
manager
Smith
123
manager
Ram
123
call Center
Srikrishna
Page141
Naga Raju
Ram
Sri Sai
ASP.Net --
Even when we close our browser & system the identity remains on the dick.
For next visit no login page is displayed because the identity will be sent
along with the request.
If false then also the identity is created & sent to client but stored in memory,
not in disk & persistent as long as user is working with website.
Srikrishna
Page142
Naga Raju
Ram
Sri Sai
ASP.Net --
</authentication>
Web.config
<configuration>
<system.web>
<authentication mode=Forms>
<forms loginUrl=valid.aspx defaultUrl=inbox.aspx>
</forms>
</authentication>
Using these options we can change the name of file as well as the location of
file.
*** END OF THE DAY ***
Dt: 09-06-2010
SignOut() Method of FormsAuthentication:This method removes the created authentication ticket (both persistent & in
memory) we can use it to SignOut or forget user credentials from our site.
We can use user, identity, Name & other properties can be used to display
the user authenticated ticket name. we can also use separate category
controls called login in ToolBox for some of security implementations.
Srikrishna
Page143
Naga Raju
Ram
Sri Sai
ASP.Net --
For example LoginName is one control in login category & it also displays
logged in user name.
In Admin/Add.aspx.cs
Public partial class Admin_add:System.web.UI.page{
protected void page_Load(object..){
Label1.Text=user.Identity.Name; // (or)
Label1.Text=Hi,+Identity.Name;
}}
Srikrishna
Page144
Naga Raju
Ram
Sri Sai
ASP.Net --
Out Put:-
Srikrishna
Page145
Naga Raju
Ram
Sri Sai
ASP.Net --
Next
In default.aspx.cs
protected void..
{
if(User.Identity.IsAuthenticated)
}
Login controls:
Login Name
Login Status
Login View
All login controls are originally design for a diff. security concept called
MemberShip. We have use those controls of login which are based on
authentication & can be used for both members ship as well as for request
some manual handling for example login control of login category.
Srikrishna
Page146
Naga Raju
Ram
Sri Sai
ASP.Net --
In login.aspx.cs
{
DB3PMModel.User
objuser.UserName=Login1.UserName;
objuser.Password=Login1.Password;
}
In Login.aspx.cs
protected void Linkbutton1_Click(object..)
{
Response.Redirect(~/login.aspx);
}
Note:- C://(RightClick) Add new item web form Register.aspx
Srikrishna
Page147
Naga Raju
Ram
Sri Sai
ASP.Net --
{ // register
DB3PMModel.User objuser=new DB3PMModel.user();
objuser.UserName=TextBox1.Text;
objuser.Password= TextBox2.Text;
objuser.Remarks=textBx3.Text;
BLUsers blobj=new BLUsers();
blobj.AddUser(objuser);
LinkButton1.Text=Registered Successfully-click to Login;
}
}
Open App_code BLUsers.cs (go to BLUsers)
public void AddUser(DB3PMModel.User Userdetails)
{
DB3PMModel.DB3PMEntities obj=new DB3PMModel.DB3PMEntities
// obj.AddToUsers(userdetails);
obj.users AddObject(userdetails);
obj.SaveChanges();
OutPut:-
try
{
DB3PM..
}
//catch (Exception)
Catch (Exception e)
{
//throw new Exception(user always Exist);
Label1.Text=e1.Message;
}
}
In Register.aspx
Srikrishna
Page148
Naga Raju
Ram
Sri Sai
ASP.Net --
In our users table add hintqn, hintan, email columns & provide same while
registering.
In admin folder create another page called changepassword.aspx design it &
accordingly write code user EDM layers.
In login page provide forgot password then Recover Linkbutton & Design
separate form where user can recover password based on hintqn & answer.
Password should be sent to registered emailid.
*** END OF THE DAY ***
Dt: 10-06-2010
Identity/Ticket will travel between every request & response. It is very
important to understand how it travels & in what mode the identity travels.
By default server uses HTTP Cookies to make this identity travel because
cookies
have
the
functionality
of
making
values
travels
between
request/response.
(Q). Why forms Identity is created as Cookie by Server?
Ans: -Because identity needs to travel between request/response which cookies
has.
Problem here is Cookies are owned/maintained by browser & browser can
reject/disable cookies. In such cases our authentication will not work server is
dependent on click Browser.
Internet Browser Tools Internet options
1. security custom level default levelmedium to drag high.
2. Pri. change to block all cookies OK.
One option is to ask user for enabling cookies & display the content normally.
Other option is maintaining identity without cookies. In ASP.NET version 2.0
CookieLess sessions & Cookieless authentication is provide. Using this we can
Naresh Tech. Class Notes
Srikrishna
Page149
Naga Raju
Ram
Sri Sai
ASP.Net --
pass identity information with URL of Browser, but it will be visible to the user.
To do this we have one attribute for forms tag called Cookieless.
<forms Cookieless=>
Where we can specified how authentication ticket should be maintained.
Note:1. HTTP Traffic Tools.
2. Internet browser Tools web development helper
Open new web form web location:HTTP selected.
Web.config
<authentication mode=Forms>
<forms Cookieless=UseUri>
</forms>
</authentication>
Srikrishna
Page150
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 11-06-2010
Web.config
<authentication mode=Forms>
<formscookieless=AutoDetect require SSL=true></forms>
<authentication>
Cookieless=autoDetect
o Use cookies if enabled or use URI.
RequireSSL=true/false
o http://...
o http-SSL
Srikrishna
Page151
Naga Raju
Ram
Sri Sai
ASP.Net --
requireSSL=true/false
o Means the communication for security should be performed in SSL mode
for which both client & server should support SSL.
Protection =All(d)/Encrypted/validated
<forms requireSSL=true protection =All>
o Protection by default forms Authentication identity is encrypted and
validated. If we want to reduce this level of security we can say only
encryption or totally avoid it none. It is highly recommended to use All
only.
Note:- web.config
<forms
requireSSL=true
protection=>//(.it
will
be
taken
default all)
o
All the aboveoptions transport level security options that ASP.NET, IIS
integratedlly provide to user. These all security mechanisms are popular
& provided successfully in web security with all these we can make our
Srikrishna
Page152
Naga Raju
Ram
Sri Sai
ASP.Net --
Empty website as its name says doesnt create any file and everything user
must configure which is more recommended.
For an Empty website also we can ass membership manually on our own also.
For this we have to use ASP.NET configuration tool & security tab in it. This is
also well known as ASP.NET Membership.
Note: - SQL Server Express Edition.
QUERYS:1.
2.
3.
4.
5.
6.
What is Rendering?
Why Rendering?
Types of Authentication? Passport Authentication?
Static Constructor?
C#
Backup?....Ado.Net 2.0,.
Types of inheritance? Explain two?
Ans:- interface inheritance, implementation inheritance
7. Abstract class?
8. About Singleton?
9. What is stored procedure? (Execution process)
10.
SQL Server?
Srikrishna
Page153
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 14-06-2010
Srikrishna
Page154
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page155
Naga Raju
Ram
Sri Sai
ASP.Net --
QueryString
Server.Transfer
CrossPage PostBack
ViewState Object****
CookiesHTTP Concept****
Sessions/Profiles***
Application***
Cache**
WebServices/WCF***
Velocity***
All above concepts/ objects are support provided by ASP.NET to fulfill state
requirements & some of them are implicitly maintained. Where our job is just to
understand them & some of them are explicitly implicitly for business
requirements.
o
Server.Transfer(<page>, true).
Srikrishna
Page156
Naga Raju
Ram
Sri Sai
ASP.Net --
These concatenated values are converted into base 64 format***. These base
64 values are stored in one or more hidden fields*** by server sent to client
along with other from contents.
User adds/modifies the content & resubmits the form to server. Server first
reads the hidden field values so that it retains the last given values (act as
stateful) &responds the same process with new repeated as long as user is
working with current page....
Some controls doesnt need state only some controls few properties only
need state very few controls need complete set as state.
All these are maintained by ASP.NET only.
This work is done onlyfor ASP.NET controls but not for variables & objects
that we declare in code window of the page.
Every page one property called ViewState using which we can store our data
also as partof asp.net concatenated string.
ViewState is of type called StateBag class which is of type object.
Because of type object ViewState can store any type of data inside it- the
only condition is the content should be Serializable***.
Srikrishna
Page157
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page158
Naga Raju
Ram
Sri Sai
ASP.Net --
Default.aspx.cs
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //1st Request
ListBox1.Items.Add("JAVA");
protectedvoid TextBox1_TextChanged(object sender, EventArgs e)
{
}
Output:-
Srikrishna
Page159
Naga Raju
Ram
Sri Sai
ASP.Net --
publicpartialclassDefault2 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //1st Request
ListBox1.Items.Add("JAVA");
TextBox1.Text = "Hello";
}
publicpartialclassDefault2 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //1st Request
ListBox1.Items.Add("JAVA");
TextBox1.Text = "Hello";
Label1.Text = "Welcome";
}
in source:
Naresh Tech. Class Notes
Srikrishna
Page160
Naga Raju
Ram
Sri Sai
ASP.Net --
Design-
When we execute this form we will get new values add at run time in page
load first Request. When we past back the form newly added values are loss
because we have set view state mode property to disable.
The default value for view state mode is inherited which means it will take
the setting of its parent control. Because of this option we can really handle
view state data according to our versions. This property also makes ASP.NET
control more valuable as in old cases they were pointed out as Heavy data &
traffic control.
More Advanced options of ViewState:
Naresh Tech. Class Notes
Srikrishna
Page161
Naga Raju
Ram
Sri Sai
ASP.Net --
When set to true every value will be encrypted & sent between
Srikrishna
Page162
Naga Raju
Ram
Sri Sai
ASP.Net --
}
*** END OF THE DAY ***
Dt: 17-06-2010
HTTP Cookies
A concept of HTTP which every web related user can use.
(Q). what is a Cookie?
It is a name=value pair just like variable which travels automatically
between every request & response.
Srikrishna
Page163
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page164
Naga Raju
Ram
Sri Sai
ASP.Net --
Client, server will be closed then the CK Result(stored hard disk) will be
available
.
(Q). Websites developed using Cookies are dependent on client (Y/N)?
Ans: YES.Because Browser has the right to deny Cookies.
(Q). Can we create any No. of Cookies per domain? Is there a limitation
on size of Cookies and type of data?
Ans:- NO, -- Browsers limit the no. of Cookies per domain (20) 1MB.
Only simple type of data can be stored not complex types like dataset,
employee etc
Username, preferred color, shopping cart items etc are the most used
Cookies.
Srikrishna
Page165
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page166
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page167
Naga Raju
Ram
Sri Sai
ASP.Net --
OutPut:-
Srikrishna
Page168
Naga Raju
Ram
Sri Sai
ASP.Net --
Cookies are not safe is one reason to avoid cookies for eritial information
like credit cord details, bank details, passwords etc
Because cookies travel in plain textual format in the form of Http headers.
In Change.aspx
Labels.Text=Request.Cookies[country].value;
Srikrishna
Page169
Naga Raju
Ram
Sri Sai
ASP.Net --
system.web.Security.formsAuthentication...
but again it want be accurate. The only way to check whether browser
supports cookies are not is to create and read cookie. If unable to read
Srikrishna
Page170
Naga Raju
Ram
Sri Sai
ASP.Net --
of application.
Any project we start, when we put under it, then IIS is automatically start,
and automatically shutdown of applications.
Ex:- consol, cloud
(Q).Which application?
Ans:-Any type of application.
(Q).Imp Question:- Can we restrict the Cookie for particular portion of
a project?
Ans:-YES,
ckobj.path=dir1
(. Path=string)
Srikrishna
Page171
Naga Raju
Ram
Sri Sai
ASP.Net --
Here O/S doesnt know there is one app is there. But is maintain by CLR.
Here one App didnt crash then CLR kills that App and restart same app newly
but not affect other applications.
In that time media player run under COM when problem occursthen also here
CLR also affected. So rectify this problem media player also developed
under .NET.
Srikrishna
Page172
Naga Raju
Ram
Sri Sai
ASP.Net --
One App domain is not communicating with other App Domain; this is only
done by Virus.
So CLR rectify this problem do remotting means communicating two
AppDomain.
(Q).Any application split into many app domain Yes or No?
Ans:- YES,
(Q). When ASP.NET application (appdomain)starts?
Ans:- When first user makes a request for a resource in application then starts for
further users same application email be served which means it want start again for
every user.
Srikrishna
Page173
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page174
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 21-06-2010
Application/Session objects use: Which developing a web application we can use that objects in 3 diff. ways (in .NET
4.0)
1. In use form of events:-these are provided by ASP.NET only & help greatly &
also uniquely to write some tasks of application.
2. For state Management: -To store data @ server in the form of private as
well as public we can use these objects.
Srikrishna
Page175
Naga Raju
Ram
Sri Sai
ASP.Net --
3. Configuring the default behaviors (4.0): All applications/ session events cannot be written in any location that we
want whereas application/session data can be created/used in any part of
executable statements.
Special file called GLOBAL.aspx is provided by asp.net to handle
app/session events primarily.
This file is not assed by default in empty website & in some other web sites
but in most of the new topics / concepts this file is automatically added like
MVC, Dynamic Data etc
In is highly recommended to use this file & write some logics related to
application.
A project can have only 1 global.aspxfile only.
It is configured to reject direct requests.
For any request this file is executed first & then the other process. (reason to
call it as application file).
Srikrishna
Page176
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page177
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page178
Naga Raju
Ram
Sri Sai
ASP.Net --
Accessible to all users of application, irrespective of the user who created it.
3. What type of data can be stored in application variables?
Any type of data because they are of type object.
4. Any limitation in app variables & its size?
No limitation but load on server should be considered.
(idle
timeout)
using
configuration
settings
as
well
as
Srikrishna
Page179
Naga Raju
Ram
Sri Sai
ASP.Net --
Example figure:
Srikrishna
Page180
Naga Raju
Ram
Sri Sai
ASP.Net --
Ex:-2in default.aspx
OutPut:-
Srikrishna
Page181
Naga Raju
Ram
Sri Sai
ASP.Net --
OutPut:-
Note:-Before 1 min we will refresh that. It cannot change, but also it will be
taken 1 min again.
Go to web.config
<configuration>
<system.web>
<SessionState timed=10></SessionState>
<compilation debug=true targetFramework=4.0/>
</system.web>
</configuration>
Srikrishna
Page182
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 23-06-2010
Srikrishna
Page183
Naga Raju
Ram
Sri Sai
ASP.Net --
---------------------------------------------------------------------------------------------------------------------
In process means sessions are crated within the application process. This is
default in ASP.NET & Fastest, because data will be located in single server
only. When heavy load is faced by server then it would affect the execution.
Note:- Sessions are stored within the application it will be called InProcess.
ASP.Net provides 2 out process options. Out Process means storing sessions
in a separate process. Application can be located in other process or in other
system. To maintain sessions in a separate process we can use.
1. ASP.NET State Server Service.
2. SQL Server.
Srikrishna
Page184
Naga Raju
Ram
Sri Sai
ASP.Net --
Ans:-Go to services & start ASP.NET State Server. This Service is installed along with
.NET only & no separate installation is required.
(CP(control Panel) Admin Tools Services)
(Net start <service name> from cmd prompt)
Start Run cmd
C:..>
C:/>net start aspservice
C:/>net stop aspservice
o
Go to the project where we want to maintain Out Process & add configuration
to implement Out Process sessions.
<sessionState>
Web.Config
<configuration>
<system.web>
<sessionState
mode=StateServer>stateNetworkTimeout=120
stateConnectionString= 192.168.100.1:42424>
</sessionState>
Note: - Because system server is bezy then Hoe long will be wait that will be
declared stateNet WorkTimeout(network time out).
<configuration debug=true targetFramework =4.0/>
</system.web>
</Configuration>
Ex:<sessionStatemode:StateServer
StateConnectionString=127.0.0.1></SessionState>
Note: - 127.0.0.1 our system act as another system
Note: - LoopBack Adapter IP Address =127.0.0.1
Srikrishna
Page185
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page186
Naga Raju
Ram
Sri Sai
ASP.Net --
<sysyetm.web>
<SessionState
mode=SQLServer
SqlConnectionString=dataSource.>
SqlCommandTimeout= ></SessionState>
<compilation debug=true targetFramework=4.0/>
</syste.web>
In sessionState change mode & other required things.
StateServer fast
Uninstallsqlstate.sql is another file which will cleanup all tables/procedures
from sqlserver to state.
Problems with Out Process Environment:Serialization / Deserialization In Out Process Session data needs to
move from one place to other place because they are in web-form
environment or in multiple systems.
In .NET 3.5 & below the only solution for this was to reduce complex types
and plan some other logic.
In .NET 4.0 a new compression feature is asses using which we can
compress/decompress data during travelling with this feature we can
maximum use complex type of data & also give good performance.
Web.config
<configuration>
<system.web>
<SessionState
mode=SQL
Server
compressionEnabled
=true
Srikrishna
Page187
Naga Raju
Ram
Sri Sai
ASP.Net --
</system.web>
</configuration>
Shop.aspx
Using System.IO.Compression;
CookieLess Sessions
Will Session Id Travel yes/No Yes. (Client identified that only).
Will Session Data travel Yes/NO No.(it should not travel).
Srikrishna
Page188
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page189
Naga Raju
Ram
Sri Sai
ASP.Net --
Other options like VaryByHeader, VaryByCustom etc are also used to cache based
to cache based on these parameters.
Note: Velocity is a Service exclusive for .NET
memcached -this people 2rd party people using business caching.
In .NET 4.0 we can customize the caching provider so that we can cache our
data not only in ASP.NET environment but also in separate environment.
Srikrishna
Page190
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page191
Naga Raju
Ram
Sri Sai
ASP.Net --
Data Caching:
Dt: 28-06-2010
Implemented using cache object & can store any type of data.
Both application & cache store data with same scope i.e., accessible to all.
Cache is more recommendedbecause it gives more features than application
object & also eliminates the problems of application object.
Both application & code may lead to inconsistency when accessed
simultaneously.
To overcome this application variables & other will be in queue till unlock is
issued.
Advantage: -Consistent.
This results in other problems are,
Srikrishna
Page192
Naga Raju
Ram
Sri Sai
ASP.Net --
Locking all variables with Lock. Restricts user to create few variables with
application with application scope.
The time between Lock() & UnLock() should be less & it is dependent on
programmer or developer.
Ex:Application.Lock();
..
Application.UnLock();
Cache data is self-locking data(Time gaps are reduced)
Cache locks only specific consumed data but not all the data inside it.
Some more features of Cache,
Time Based Expiry
o In this time we create cache data on time. Once time elapses the cache
data will be expired. We can also specify lease-based time or relative
mode of time.
Dependency Based Expiry
In this mode we can create one object based on other object which can be
expired.
Ex: o Create one web form & place GridView with Button.
o Crate one .xml file Say scores.xml
Open new website (right click) add a new item web Form
(name:scores.xml)
<?xmlversion ="1.0"encoding="ASMO-708"?>
<scoredata>
<score>
<over>1</over>
<runs>4</runs>
</score>
<score>
Naresh Tech. Class Notes
Srikrishna
Page193
Naga Raju
Ram
Sri Sai
ASP.Net -<over>2</over>
<runs>1</runs>
</score>
<score>
<over>3</over>
<runs>9</runs>
</score>
<score>
<over>4</over>
<runs>12</runs>
</score>
<score>
<over>5</over>
<runs>15</runs>
</score>
<score>
<over>7</over>
<runs>9</runs>
</score>
<score>
<over>8</over>
<runs>10</runs>
</score>
</scoredata>
In Button write code to read data from scores.xml & present it in GridView.
C://.(Right click) add a new item web form name:default.apsx
Srikrishna
Page194
Naga Raju
Ram
Sri Sai
ASP.Net --
{
DataSet ds;
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid LinkButton1_Click(object sender, EventArgs e)
{
if (Cache["dsscore"] != null) //present
{
ds = (DataSet)Cache["dsscore"];
}
else
{
ds = new DataSet();
ds.ReadXml(MapPath("scores.xml"));
Cache["dsscore"] = ds;
}
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
Out Put:- open default.aspx & run it
Go to saving folder and select scores file (right click open in notepad add one
more over & score and save it).
Ex:-
<?xmlversion ="1.0"encoding="ASMO-708"?>
<scoredata>
<score>
<over>1</over>
<runs>4</runs>
</score>
<score>
Naresh Tech. Class Notes
Srikrishna
Page195
Naga Raju
Ram
Sri Sai
ASP.Net -<over>2</over>
<runs>1</runs>
</score>
<score>
<over>3</over>
<runs>9</runs>
</score>
<score>
<over>4</over>
<runs>12</runs>
</score>
<score>
<over>5</over>
<runs>15</runs>
</score>
<score>
<over>6</over>
<runs>20</runs>
</score>
<score>
<over>7</over>
<runs>9</runs>
</score>
<score>
<over>8</over>
<runs>10</runs>
</score>
<score>
<over>9</over>
<runs>25</runs>
</score>
</scoredata>
Open default.aspx run it but output will not be change & open one more
internet explorer paste default.aspx path and run it out put not be changed.
Naresh Tech. Class Notes
Srikrishna
Page196
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page197
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page198
Naga Raju
Ram
Sri Sai
ASP.Net --
2. Design the control according to requirement & write code the same. We can
design a control like page only no difference in working.
Srikrishna
Page199
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page200
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page201
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page202
Naga Raju
Ram
Sri Sai
ASP.Net --
The other way we can create we user control is using ASP.NET server
template in File New Project web.
This control is difficult to design as it has to build from scratch with good
component concepts.
This control can have all user friendly features & can be deployed to client as
a .NET assembly instead of file. All AJAX controls are developed as server
controls using this template only. This control is also called as custom
control.***
In normal projects we design a web user control & consume it within our
project.
Srikrishna
Page203
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 30-06-2010
new
item
web
user
control
name:TopMenu.ascx
2. Design the control according to requirement.
Srikrishna
Page204
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page205
Naga Raju
Ram
Sri Sai
ASP.Net --
<ItemTemplate>
<table>
<td><asp:HyperLink ID=h1 runat=server
Text=<%#Eval(Title)%>
NavigateUrl=<%#Eval(loc)%>></asp:HyperLink>
</td>
Srikrishna
Page206
Naga Raju
Ram
Sri Sai
ASP.Net --
Web.config
<configuration>
<appSettings>
<add key=Title value=E-Learning/>
<add key=Logo value=logo.jpg/>
<add key=Banner value=banner.jpg/>
Srikrishna
Page207
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 02-07-2010
Srikrishna
Page208
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page209
Naga Raju
Ram
Sri Sai
ASP.Net --
This idea is old but because of many considerations like Bandwidth, Security
& other infrastructure SOA came into market in year 2000.
Successfully implemented thru another open standard specification called
XML Web Services around 2003-2005.
(Q). What is an XML Web Service?
Ans: - This is also defined by W3 org which provides an implementation of service
oriented applications. Any language can follow these rules to result their
applications as service oriented applications.
SOAP Simple Object Access Protocol.
Program my own idea SOAApp WCF
WCF Window communication Foundation.
Mobile Applications
In frontend parts of application one of the most important & also essential is
mobile application.
Naresh Tech. Class Notes
Srikrishna
Page210
Naga Raju
Ram
Sri Sai
ASP.Net --
.NET has any good (little confused) environment for developing mobile
applications.
Form starting version there is always some mobile development in .NET.
Taking all of them we can say mobile applications as of today (july-2010) in
.NET in 2 ways.
1. Server Side Mobile Applications.
2. Client Side Mobile Applications.
Server Side Mobile Applications:
(Q).What are Server Side Mobile Apps?
Ans: These are just like Web Applications & they reside @ Server as mobile web
pages.
Normal web pages target a rich browser in all aspects.
Mobile web pages target a down level (lowing features Ex: - JavaScript, HTML,
etc.) Browser where features are limited.
These applications are accessible to all types of mobiles which contain a
browser & which has a means to connect with web.
Note:- A Server side app doesnt expect any resources from client starting from
a lower level user to higher level user So develop server side applications so
that they are accessible by one who can & also today BlackBerry, Apple iphone,
Android (Google), windows Phones are providing full fledged browsers.
Srikrishna
Page211
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 05-07-2010
Start VS 2005
New website
Delete default.aspx which is web page
Add a new item mobile web form
Design the form just like any other form & write code in similar way
(unified model).
o Start Microsoft Mobile Explorer & type the address of website
3rd party mobile Explorers
o openwave.com
o wap.nokia.com nokia wap toolkit
Naresh Tech. Class Notes
Srikrishna
Page212
Naga Raju
Ram
Sri Sai
ASP.Net --
o blackberry.com
etc
Start File New website ASP.NET web site OK.
File system, C:\\demos\mobiledemo
Default.aspx
Srikrishna
Page213
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page214
Naga Raju
Ram
Sri Sai
ASP.Net --
Server Side Example:Start File New website ASP.NET web site OK.
C:\\demos\demomobile
Srikrishna
Page215
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page216
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page217
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page218
Naga Raju
Ram
Sri Sai
ASP.Net --
Note:-Http://www.simpletraining.net
Naresh Tech. Class Notes
Srikrishna
Page219
Naga Raju
Ram
Sri Sai
ASP.Net -*** END OF THE DAY ***
Dt: 06-07-2010
Srikrishna
Page220
Naga Raju
Ram
Sri Sai
ASP.Net --
Out put:-
Srikrishna
Page221
Naga Raju
Ram
Sri Sai
ASP.Net --
Output:-
Srikrishna
Page222
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 07-07-2010
Srikrishna
Page223
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page224
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page225
Naga Raju
Ram
Sri Sai
ASP.Net --
OutPut:-
OutPut:-
Srikrishna
Page226
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page227
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page228
Naga Raju
Ram
Sri Sai
ASP.Net --
OutPut:-
Example-2:-
Srikrishna
Page229
Naga Raju
Ram
Sri Sai
ASP.Net --
OutPut:-
Srikrishna
Page230
Naga Raju
Ram
Sri Sai
ASP.Net -Dt: 08-07-2010
Srikrishna
Page231
Naga Raju
Ram
Sri Sai
ASP.Net -Proxy ) which should be prepared by client based on the web service.
Proxy should know about webservice otherwise it cannot be created.
Proxy coding will be to own without a tool is very very complex.
Note: - ORB Object Request Broker
(Q). Why is Serialization>
(Q). what is Serialization?
2. Proxy takes the request & converts the request into SOAP Message.
(Q). what is SOAP?
Ans: -Simple Object Access Protocol
The most initial & starting protocol which was designed by MS, IBM
mainly for communication purpose. The same is used by webservices for
communication. SOAP is derived from XML means it is XML itself (Refer XML &
XML derived techmologies).
Note: -JSON JavaScript Object Notation
AJAX No SOAP Only JSON
One of the draw of SOAP is its Size.
3. Web service takes the SOAP takes the SOAP request & converts it into
native object format. Executes the same request & produces result.
This result is send back to client after converting it as SOAP response
format.
4. Proxy takes it & provides it to application & application formats &
displays the results to its client.
....
Microsoft /Oracle/Sun has followed these rules & provided,
MS
--- ASP.NET Web Service libraries
Oracle
--- PL/SQL Web Service libraries
JAVA
--- J2EE Web Services /XML Web Services
As a .NET user we use ASP.NET web service libraries class to develop
services.
System.Web.Services is the namespace which ishaving WebService class &
WebMethod class. To build we have to create a class extending WebService
class & writing WEbMethods* inside it.
This is lost supported in .NET 3.5
VS 2008 everywhere we can see ASP.NET Web Service. VS 2010 NET 3.5 &
below only because .NET 4.0 CLR under stands WEF XML Web Service model.
Using VS2010 start new website select .NET 3.5 from versions & choose
ASP.NET Web Service. A sample WebMethod is also written just check it.
*** END OF THE DAY ***
Naresh Tech. Class Notes
Srikrishna
Page232
Naga Raju
Ram
Sri Sai
ASP.Net -Dt: 09-07-2010
Srikrishna
Page233
Naga Raju
Ram
Sri Sai
ASP.Net --
ds.Fill(ds,jobs);
return ds;
}
[WebMethod(BufferREsponse=true,CacheDuration=30,EnableSession=true)]
public Job GetJobInfo(int Jobid)//good method in SOA
{
SqlConnection cn=new SqlConnection(@Data Source=ROHIT-PC\SQLINDIA;Initial
Catalog=pubs;.)
cn.Open();
SqlCommand cmd=new SqlCommand(select*from jobs where job_id=jobId,cn);
SqlDataReader dr=cmd.ExecuteReader();
Job obj=new Job();
if(dr.Read())
{
obj.JobId=Convert.ToInt32(dr[0]);
obj.Description=dr[1].ToString();
obj.MinLevel=Convert.ToInt32(dr[2]);
obj.MaxLevel=Convert.ToInt32(dr[3]);
}
else
{
obj.JobId=-1;
}
cn.Close();
return obj;
}
In solution Explorer
|
C:\\......
|
App_Code (RightClick) Add a New item (name: Job.asmx)
|
Job.asmx
In App_Code/Job.cs** (Job.cs)
public class Job
{
public Job()(..)
//Pro & Tab
public int JobId{get;set;}
public int Description{get;set;}
public int MinLevel{get;set;}
public int MaxLevel{get;set;}
}
Note:- (@ page.Buffer=false..)
Then the output not stop, it will be run fast.
(@ page.Buffer=True..)
Till the method is completed for the form.
Naresh Tech. Class Notes
Srikrishna
Page234
Naga Raju
Ram
Sri Sai
ASP.Net --
EnableSession=true
Using List<Job>Multiple Jobs
Dt: 10-07-2010
Srikrishna
Page235
Naga Raju
Ram
Sri Sai
ASP.Net --
Another type.
Srikrishna
Page236
Naga Raju
Ram
Sri Sai
ASP.Net --
Proxy is ready and knows we can consume design the form according to the
method that we want to use. On our 1 st example we will consume GetAllJobs
so we will create button & GridView.
In button write code to use the created proxy & fill the GridView with data.
C://demo/(Right Click) Add a new item Webform
default.aspx
Srikrishna
Page237
Naga Raju
Ram
Sri Sai
ASP.Net --
Run it
OutPut:-
Srikrishna
Page238
Naga Raju
Ram
Sri Sai
ASP.Net --
EX-3:
OutPut:-
Srikrishna
Page239
Naga Raju
Ram
Sri Sai
ASP.Net -*** END OF THE DAY ***
Dt: 12-07-2010
extension
.master
(for
example,
Srikrishna
Page240
Naga Raju
Ram
Sri Sai
ASP.Net --
Example:
Srikrishna
Page241
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page242
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page243
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page244
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page245
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page246
Naga Raju
Ram
Sri Sai
ASP.Net --
Dt: 13-07-2010
ASP.NET DEPLOYMENT
Naresh Tech. Class Notes
Srikrishna
Page247
Naga Raju
Ram
Sri Sai
ASP.Net --
for
web
&
other
applications.
(Visual
Studio
2010
more
recommended).
Publishing style of deployment is what we do & we publish our app to show many
but some important locations are these 3.
1
2
3
For all type of deployments only one requirement is set the project debug mode to
false**.
Compile the project correct error & select publish project from build menu or right
click on Solution Explorer & select publish.
Note:
Znetindia.com
Pucharging Domain only Name 500/Purchage space for Domain (Hosting) 500/- to 1
lakh(annum)
Control Panel Details
ftp details
sitename: ftp://simpletraining.net
Srikrishna
Page248
Naga Raju
Ram
Sri Sai
ASP.Net --
Srikrishna
Page249