Basics of asp.net part 2

14
iFour Consultancy Basics of ASP.Net

description

Training presentation of basics of asp.net part 2. http://www.ifour-consultancy.com

Transcript of Basics of asp.net part 2

Page 1: Basics of asp.net part 2

iFour Consultancy

Basics of ASP.Net

Page 2: Basics of asp.net part 2

Introduction to ASP.Net

What Is ASP.Net?

• ASP.Net is a web development platform, which provides a programming model, a comprehensive software infrastructure and various services required to build up robust web application for PC, as well as mobile devices.

• ASP.Net works on top of the HTTP protocol and uses the HTTP commands and policies to set a browser-to-server two-way communication and cooperation.

• The ASP.net application code could be written in different languages like C#,visual basic .net,Jscript,J#.

• ASP.Net is used to produce interactive, data-driven web applications over the internet.• ASP.NET pages have the extension .aspx, and are normally written in VB (Visual Basic) or C#

(C sharp).

•A markup language is a set of markup tags •A markup language is a set of markup tags

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 3: Basics of asp.net part 2

ASP.Net Web Pages

What is Web Pages?• Web Pages is one of the 3 programming models for creating ASP.NET web sites and

web applications.• Web Pages is the simplest programming model for developing ASP.NET web pages. • Advantages:

Easy to learn, understand, and use. Built around single web pages. Similar to PHP and Classic ASP. Server scripting with Visual Basic or C#. Full HTML, CSS, and JavaScript control.

• It provides an easy way to combine HTML, CSS, JavaScript and server code.

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 4: Basics of asp.net part 2

ASP.Net Web Pages

What is Razor?• Razor is a markup syntax for adding server-based code to web pages.• Razor has the power of traditional ASP.NET markup, but is easier to learn, and

easier to use.• Razor is a server side markup syntax much like ASP and PHP.• Razor supports C# and Visual Basic programming languages. • The Razor code does all the work of determining the current time on the server and

display it.

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 5: Basics of asp.net part 2

ASP.Net Page life cycle

When a page is requested, it is loaded into the server memory, processed and sent to the browser. Then it is unloaded from the memory.

The page life cycle phases are:• Initialization• Instantiation of the controls on the page• Restoration and maintenance of the state• Execution of the event handler codes• Page rendering

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 6: Basics of asp.net part 2

At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle.

Following are the page life cycle events:• PreInit • Init• InitComplete• LoadViewState• LoadPostData• PreLoad• Load• LoadComplete• PreRender• PreRenderComplete• SaveStateComplete• UnLoad

ASP.Net Page life cycle events

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 7: Basics of asp.net part 2

What is an Event?• Event is an action or occurrence like mouse click, key press, mouse movements, or

any system generated notification. The processes communicate through events. For example, Interrupts are system generated events. When events occur the application should be able to respond to it

• In ASP.Net an event is raised on the client, and handled in the server. For example, a user clicks a button displayed in the browser. A Click event is raised. The browser handles this client-side event by posting it to the server

• The server has a subroutine describing what to do when the event is raised; it is called the event-handler. Therefore, when the event message is transmitted to the server, it checks whether the Click event has an associated event handler, and if it has, the event handler is executed

Event Handling in ASP.Net

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 8: Basics of asp.net part 2

All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts:

<form runat="server">

...HTML + server controls

</form>

A form is most often submitted by clicking on a button. The Button server control in ASP.NET has the following format:

<asp:Button id="id" text="label" OnClick="sub" runat="server" />

ASP.Net Web Forms

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 9: Basics of asp.net part 2

You may save a lot of coding by maintaining the ViewState of the objects in your Web Form. When a form is submitted in classic ASP, all form values are cleared. Suppose you have submitted a form with a

lot of information and the server comes back with an error. You will have to go back to the form and correct the information. You click the back button, and what happens.......ALL form values are CLEARED, and you will have to start all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the browser window together with all form values. The ViewState indicates the status of the page when submitted to the server. The status is defined through a

hidden field placed on each page with a <form runat="server"> control. The source could look something like this: <form name="_ctl0" method="post" action="page.aspx" id="_ctl0"><input type="hidden" name="__VIEWSTATE"value="dDwtNTI0ODU5MDE1Ozs+ZBCF2ryjMpeVgUrY2eTj79HNl4Q=" />

.....some code

</form>

Maintaining the ViewState

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 10: Basics of asp.net part 2

The following controls are list controls which support data binding:• asp:RadioButtonList• asp:CheckBoxList• asp:DropDownList• asp:Listbox

The selectable items in each of the above controls are usually defined by one or more asp:ListItem controls, like this:• <html>

<body>

<form runat="server"><asp:RadioButtonList id="countrylist" runat="server"><asp:ListItem value="N" text="Norway" /><asp:ListItem value="S" text="Sweden" /><asp:ListItem value="F" text="France" /><asp:ListItem value="I" text="Italy" /></asp:RadioButtonList></form>

</body></html>

Data Binding in ASP.Net

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 11: Basics of asp.net part 2

The Repeater control is used to display a repeated list of items that are bound to the control.

The Repeater control is used to display a repeated list of items that are bound to the control.

The Repeater control may be bound to a database table, an XML file, or another list of items.

Repeater Control in ASP.Net

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 12: Basics of asp.net part 2

Master Pages in ASP.Net

Master pages provide templates for other pages on your web site. Master pages allow you to create a consistent look and behavior for all the pages

(or group of pages) in your web application. A master page provides a template for other pages, with shared layout and

functionality. The master page defines placeholders for the content, which can be overridden by

content pages. The output result is a combination of the master page and the content page.

The content pages contain the content you want to display.

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 13: Basics of asp.net part 2

Validation server controls are used to validate user-input. A Validation server control is used to validate the data of an input control. If the data

does not pass validation, it will display an error message to the user. The syntax for creating a Validation server control is:

• <asp:control_name id="some_id" runat="server" />

Validation Controls used in ASP.Net:• CompareValidator• CustomValidator• RangeValidator• RegularExpressionValidator• RequiredFieldValidator• ValidationSummary

Validation Controls in ASP.Net

http://www.ifour-consultancy.com

ASP.NET Software company India

Page 14: Basics of asp.net part 2

www.w3schools.com www.tutorialspoint.com

References

http://www.ifour-consultancy.com

ASP.NET Software company India