Beruflich Dokumente
Kultur Dokumente
NET
NOTE:- ASP application is capable to run in any O.S provided the O.S must have a browser.To run
the application in a network(collection of machines) minimum one machine has to be a windows
server.
HTML code is basically appeared in a client browser whereas CODE BEHIND is actually the
program resided inside the server.
2 types of operations are being done in between client and server i.e. REQUEST and
RESPONSE which are done through HTML & JSCRIPT.
NOTE: Any language compatible with HTML to make the HTML dynamic is known as a scripting
language. 2 different types of scripting languages are available
1. VB SCRIPT Browser dependent
2. JSCRIPT Browser independent
Whenever a program request is made from the client,the request is made to the web server
and a web server has a primary component called IIS(internet information service)
It creates the web process and collects all the resources and connects to the databse if
required.
It send the program to the framework for compilation purpose and making the exe.
Once the exe is created IIS will provide it to the ISAPI for execution.
Once the exe is executed ,the output is again converted to HTML/Jscript and given back to
client.
Once all the above jobs are done the process is de-allocated by IIS.
NOTE:-The time span between the web process start and web process end is known as session.
To start ASP.NET application, from the NEW PROJECT window choose the language as C#
and application as ASP.NET. Then choose webform item and click on ok
Now a new ASP.NET project will start having a default page. The ASP.NET IDE consist of
following components i.e. toolbox, property window, solution explorer etc
To create a new page Right click over the project name from the solution explorer and ADD
NEWITEM and choose WEB FORM. Each webform comprising of 3 views i.e.
1. Design view It is responsible for design to design the page either by putting the controls
over the page or by writing code behinds.
2. Source view using this view user can see the equivalent HTML code of a web form and
controls over it.
3. Split view it’s a combination of design view and source view.
Server controls are those controls which provides events and basically meant for dynamic
effects. This controls are basically executed in the server side.
Whereas HTML controls are otherwise known as static controls neither they provides
events nor they execute in the server.
NOTE:- In other words server controls are responsible for dynamic web page development and
HTML controls are responsible for static web page development.
NOTE:- Asp.net server controls are identified by asp keyword in HTML view whereas HTML controls
are identified by input keyword in HTML view.
</HEAD>
<BODY>
</BODY>
</HTML>
Head …End Head is responsible to hold all the information regarding a page.
Body….End Body hold all the HTML codes for several controls available in the page.
NOTE:- Asp.net provides a major class which is responsible to create individual webforms and i.e.
System. Web. UI. Page
Namespace class
CONTROLS IN ASP.NET
1. LABEL :- It is a server control which is responsible to hold static data. In other words label is
responsible to provide an identification mark to an object.The basic difference between a
label and a textbox is , label holds static data whereas textbox holds dynamic data. The
property of a label can be changed during runtime using an event. Important properties of a
label are
Property Description
NOTE:- To access the Color structure user have to use System.Drawing namespace.
2. BUTTON: Button is otherwise known as a process control which accepts the input in form of
event. ASP.NET provides 3 different types of buttons
Property Description
Create one-one button over the form and change their required properties such as border
color, border style, border width, font etc.
NOTE :- For image button gather all the images ( JPEG/ GIF ) and store them inside a folder within
the same project. To add an image in image buttonRIGHT CLICK OVER PROJECT FROM SOLUTION
EXPLORERADDADD EXISTING ITEMTHEN SELECT THE JPG FILE
protected void Button1_Click(object sender, EventArgs e)
{
Label3.Text = "you clicked on button";
}
3. TEXT BOX:- Text box is otherwise known as input control which accepts the input at
runtime. Its important properties are listed below.
Property Description
4. CHECK BOX AND RADIO BUTTONS: Check box and Radio button are standard controls. The
basic difference between them is checkbox allows the user to choose multiple values from a
list of value whereas radio button allow the user to choose single value from a list of values.
NOTE:- Other than the button, to send the request to the server, user has to make any control’s
AutoPostBack property to True. If it is false then it won’t send the request to the server and the
controls won’t work.
EXAMPLE OF CHECKBOX
EXAMPLE OF RADIOBUTTON
NOTE:- Change minimum 3 properties e.g. GroupName , AutoPostBack , Text. Other than the
button, to send the request to the server, user has to make any control’s AutoPostBack property to
True. If it is false then it won’t send the request to the server and the controls won’t work.
5. DROP DOWN LIST BOX(COMBO BOX):- Combo box is nothing but the extended version of
radio button which allow the user to choose 1 value from a list of values. Combo box always
holds the values in a hidden format. When it is clicked all the values are displayed and user
is allowed to choose one value out of that. User can add values in a combo box in 2 different
manners i.e.
a. During design time
b. During runtime
CODE BEHIND (TO ADD VALUES TYPED IN THE TEXTBOX AND ON CLICKING THE BUTTON)
CODE BEHIND (TO ADD VALUES AND CHANGING THE COLOR OF THE TEXT BOX DYNAMICALLY)
NOTE:- Here if (this.IsPostBack == false) is basically a condition which always treat as if the page is
loaded for the first time. For control AutoPostBack and for form IsPostBack.
NOTE:- SelectedItem selects the index and SelectedValue selects the value of the index.
6. LIST BOX:-List box is a standard control which is treated as the extended version of check
box. Which allow the user to choose multiple values from a list of values. List box is identical
with combo box as far as events and properties are concerned. User can add the values in list
box either in design time or in runtime.
Class loop
Char[ ] str={‘h’,’e’,’l’,’l’,’o’};
foreach(char ch in str)
Console.WriteLine(ch);
9. CHECK BOX LIST :- Check box list is an extended version of check box. Advantage of check
box list is it supports less coding.
Code behind
Table menu is required to design a form in a customized manner with proper alignment. To
design a table click over the table menu in menu bar and click on insert table.
Provide the number of rows, columns, cell spacing, cell padding, border color etc. and click
on OK. Choose individual cell and create controls within the cells. Design the form in the following
manner.
WORKING WITH VALIDATORS
Client side validators doesn’t require any program whereas server side ( custom ) validators
have their own event.
1. REQUIRE FIELD VALIDATOR: This validator acts like NOT NULL in database. This validator
will show error when the control remains blank. Create the control over the form and change the
following properties
a. Error message
b. Fore color
c. Control to validate
2. COMPARE VALIDATOR: This validator is required to compare 2 values and validate. Drag
the control over the form and change the following properties. a. Error message
b. Control to validate
c. Control to compare
d. Type
e. Operator
f. Tool tip text
3. RANGE VALIDATOR: This validator is responsible to check a range of values and validate
it. Drag the control over the form and change the following properties.
a. Forecolor
b. Error message
c. Control to validate
d. Type
e. Max value
f. Min value
4. REGULAR EXPRESSION VALIDATOR: This validator is responsible to check the format such
as mail id, internet URL, pin code etc. Create the control over the form and change the following
properties.
a. Error message
b. Control to validate
c. Validation expression
d. Tool tip text
Here ** Password Mismatched is the only server side validators whereas other are client side
validators.
Double click over the validator and write the following code.
ASP.NET not only allow the user to create control during design time but also allow the user to
create control during runtime. Place Holder is nothing but a container which contains dynamic controls
created during runtime.
Table control is a control required to represent the data in a 2-dimensional manner. Table
control represents data in a read only mode. Create the table control over the form and change the
following properties i.e. cell padding, cell spacing, font, caption, etc. click on ROWS and add the
number of rows .Add number of cells according to the requirement and provide data if required.
Web service is basically a technology or mechanism responsible to make the .Net programs
platform independent. Once a program is created using web service technology it can be operated
on any O.S.
NOTE:- Whenever a program is created using web service it supports the technology of XML. Any
program created through web service has to be a function.
STEP1
Open Visual Studio File New Web Site
Step2
Create “ASP.Net Empty Web Site” and save at the desired location.
STEP3
Right-click on Project folder in Solution Explorer on the right side Add New Item
Step4
Select your language (C# in my case) Web Service (ASMX) Add.
NOTE:- Each function in web service starts with a keyword [WebMethod]. [WebMethod] attribute is
used to specify that this method is exposed to the user/Client to access. If you remove this
attribute, the client will not be able to see the method details, hence they can't implement it.
Example:-
[WebMethod]
public int sum(int a,int b)
{
return a+b;
}
Step5
Step 1 :- Open a fresh web application and design the page as shown below.
Step 2 :- Now go to solution explorer right click on project i.e web application click on add
service reference a window will open. Now click on ADVANCED click on ADD WEB REFERENCE
then on the url provide the
click on add reference now the local host will be added in the solution explorer.
Step 3 :- Now in the button click event write the following coding.
Whenever a web method is invoked from a client , first the request is converted to XML
using a language called WSDL(web service description language).
Then the request is made to the server and the program is executed. Once the program is
executed again the output is converted to XML and given back to the client.
XML data transmitted between the client and the server using a protocol called
SOAP(simple object access protocol).
NOTE:- Adrotator supports a file called XML file , which is responsible to hold the advertisement.
Once the XML file is created tag it to the adrotator.
1. Go to solution explorer and right click on the project and add a new folder called images and
add the desired images in it.
2. From the solution explorer window , right click over the project name add add new
item from the left window select data then select XML file click on open
3. Inside the XML file write the following coding.
<Advertisements>
<Ad>
<ImageUrl>Images/Desert.jpg</ImageUrl>
<NavigateUrl>http://google.com</NavigateUrl>
<AlternateText>please visit google</AlternateText>
<Impression>50</Impression>
</Ad>
<Ad>
<ImageUrl>Images/Jellyfish.jpg</ImageUrl>
<NavigateUrl>http://yahoo.com</NavigateUrl>
<AlternateText>please visit yahoo</AlternateText>
<Impression>10</Impression>
</Ad>
<Ad>
<ImageUrl>Images/Hydrangeas.jpg</ImageUrl>
<NavigateUrl>http://rediff.com</NavigateUrl>
<AlternateText>please visit rediff</AlternateText>
<Impression>20</Impression>
</Ad>
</Advertisements>
Advertisement tag is having several ad tags which holds individual advertisements. Ad tag is
having the following sub tags.
a. ImageUrl which display the advertisement in adrotator
b. NavigateUrl which specifies the hyperlink to a specific page
c. AlternateText which acts as a tooltip text
d. Impression it shows the priority of an advertisement
5. Now open the webform and drag the adrotator and go to its property. Provide the XML file
name in advertise file property.
1. Hyperlink :- This is a method through which user can navigate to another page interactively.
It doesn’t have its own events.
Drag the hyperlink control over the page go to its property and change its following
properties.
a. Text
b. NavigateUrl
c. Tooltip text
d. Backcolor
NOTE :- Through hyperlink control we can navigate to any page of different web server.
2. Response.Redirect :- Redirect method is a method which is identical with hyperlink. But the
advantage of redirect is it can navigate to another page programmatically using events.
NOTE :- The main difference between hyperlink and redirect method is hyperlink can connect to a
html page whereas redirect method can only connect to aspx file.
Drag a link button or an image button over a page. Change its concerned properties. Double
click over the control and write the following coding.
3. Server.Execute :- This method is identical with redirect because both navigate to another
page programmatically.The advantage of execute method is it is responsible to merge the
data of sender page and recipient page and display in one page.
NOTE :- To work with server.execute go to html view of sender page and in the page tag write the
following code
<% @ Page…….Enableviewstate=”False”>
Drag a link button or image button and change the properties and double click over the
control and write the following code.
NOTE :- The major advantage of this type of concept is to reduce the data entry operation.
STEPS
a. In the source page html view write the following code in the page tag.
Enableviewstatemac=”false”
b. Drag a link button or image button change its properties double click over the button
and write the following coding.
NOTE:- The above coding is responsible to transfer the control to webform2 by preserving the data
of webform1.
c. Double click over the destination form(webform2) and write the following coding in page
load event.