asp-day-1basics-140422115104-phpapp02

Upload: shemsedin-shukre

Post on 18-Jan-2016

219 views

Category:

Documents


0 download

DESCRIPTION

er

TRANSCRIPT

  • Introduction to ASP.NETWeek 11, day1

  • ASPActive Server Pages

    ASP.NET is a server side scripting language

  • .NET overview.NET is a framework for developing web-based andwindows-based applications within the Microsoftenvironment. Components of .NETMICROSOFT Intermediate language - all code iscomplied into a more abstract, trimmed version beforeexecution. All .NET languages are compiled to MSIL the common language of .NET

    The CLR- common language runtime; responsible forexecuting MSIL code; interfaces to Windows and IIS

    A rich set of libraries (Framework Class Libraries) available to all .NET languages

  • Components of .NET (Continuation)The .NET languages such as C#, VB.NET etc that conform to CLR

    ASP.NET is how the Framework is exposed to the web, using IIS (internet information system) to manage simple pages of code so that they can be complied into full .NET programs. These generate HTML for the browser (when the page is requested by a client browser).

  • Generate HTML

    Get index.aspx13

    4

    pass index.aspx to .netframework

    5

    WebServer

    Index.aspx in interpreted HTMl form

    Browser

    2Get index.aspx from hard disk

    How IIS takes requests and processes it

    .NET

  • Scripting Languages

    A script is a collection of program or sequence of instructions that is

    interpreted or carried out by another program rather than by the computer

    processor. Two types of scripting languages are

    Client-side Scripting Language

    Server-side Scripting Language

    In server-side scripting, (such as PHP, ASP) the script is processed by the

    server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows.

    Client-side scripting such as JavaScript runs on the web browser.

  • Generate HTML

    Get index.aspx13

    4

    pass index.aspx to .netframework

    5

    WebServer

    Index.aspx in interpreted HTMl form

    Browser

    2Get index.aspx from hard disk

    How IIS takes requests and processes it

    .NET

    ASP.NET is a server side scripting language because the

    code runs on the server and returns the result in html form

    to the client browser

  • Generate HTML

    Get index.aspx13

    4

    pass index.aspx to .netframework

    5

    WebServer

    Index.aspx in interpreted HTMl form

    Browser

    2Get index.aspx from hard disk

    How IIS takes requests and processes it

    .NET

    Client side scripting is something where code runs on client

    side(browser). For eg checking whether a HTML text field contains data or not can be done by running

    a script from browser itself

  • Microsoft Visual StudioMicrosoft Visual Studio is an IDE (Integrated DevelopmentEnvironment) on which .net applications can be createdeasily.

    It is a powerful tool that can expose the features of the.net framework to make the developers work easier

    Applications can be run from within the IDE and hasinbuilt compiler and debugger (no need to install thirdparty servers like WAMP, XAMPP etc. to run the applicationas in case of PHP)

    It exposes a rich design based interface to manage anyaspect of a .net project from design to deployment

  • Creating an asp.net page

  • Create a new asp.net website projectGo to start > all programs > microsoft visual studio 2008 (or whatever version

    you have installed)

  • Create a new asp.net website project

    Click on file > new web site

  • Create a new asp.net website project(for C# select the language as Visual C#)

  • Create a new asp.net website project

  • Create a new asp.net website project

  • Create a new asp.net website project

  • Create a new asp.net website project

  • Create a new asp.net website project Double click on the button control you just created

  • Create a new asp.net website project You can also add handlers for other events of the button

  • Adding connection string to the web.config file

  • Adding a new item to the project

  • Adding a new item to the project

  • Running the project

  • Getting started with ASP.NET programming

  • .Net Controls, Events and Event handlers

    .net Controls There are no. of controls those are available in the toolbox inside visual

    studio. Eg. Button, textbox, dropdownlist etc.

    Each control represents a class extended fromthe System.Web.UI.WebControls class

    Each control has events, properties and methods associated with it

    Each control in an aspx page is identified by a unique id, no two controlson the same page can share an id

    Events Events happen when the user does some sort of action on a control eg.

    Click for a button, changing the text for a textbox etc.

    Event Handlers Event handlers are code blocks that will be executed when events are

    raised

  • .Net Controls, Events and Event handlers (continuation)

    In plain words an event handler for the click of a button that has an idbtn_a will tell the server like

    Do this on the click of btn_a

    There are no. of event handlers associated with each type of .net control

    Custom event handlers can also be registered for certain controls.

  • Commenting

    // comment single line

    /* comment

    multiple lines */

    C#

    //comment single line

    /* Comment

    multiple Lines*/

    VB.NET

    comment single line

    /* Comment

    multiple Lines*/

    C ASP.NET

  • Data Types

  • Data types

    ASP.NET supports many different data types such as

    o Integer

    o String

    o Double

    o Boolean

    o Datetime

    o Arrays

  • Type Casting

    Response.write ((0.1 + 0.7) * 10); //Outputs 8

    Response.write ([cint] ((0.1 + 0.7) * 10)); //Outputs 7

    This happens because the result of this simple arithmetic

    expression is stored internally as 7.999999 instead of 8; when the

    value is converted to integer, ASP.NET simply truncates away the

    fractional part, resulting in a rather significant error (12.5%, to be

    exact).

  • Variables

  • Declaring a variable

    //Declaring a variable

    Int a=10;

    Char c=a;

    Float f=1.12;

    C#

    String a; //variable without initialisation

    String a = Hello; //variable with

    initialisation

    VB.NET

    Dim a as string //variable without

    initialisation

    dim a as string = Hello //variable with

    initialisation

    C ASP.NET

  • Variables

    Variables are temporary storage containers.

    In ASP.NET, a variable can contain any type of data, such as, for example,

    strings, integers, floating numbers, objects and arrays provided the variable

    must be declared in that datatype.

    As in case of PHP which is loosely typed, ASP.NET will not implicitly

    change the type of a variable as needed. ASP.NET languages are strongly

    typed, like C and Java, where variables can only contain one type of data

    throughout their existence.

  • Constants

  • Declaring a constant

    //Declaring a constant using const

    const int a=10;

    int const a=10;

    //Declaring a constant using #define

    #define TRUE 1

    #define FALSE 0

    #define NAME_SIZE 20

    C#

    Const String a = Hello;

    VB.NET

    const a as string = Hello

    C ASP.NET

  • Constants

    Conversely to variables, constants are meant for defining immutable values.

    Compile-time and Run-time ConstantsA compile-time constant is computed at the time the code is compiled, while a run-time constant can only be computed while the application is running. A compile-time constant will have the same value each time an application runs, while a run-time constant may change each time.

  • Control structures

  • Control Structures

    Conditional Control Structures

    If

    If else

    Switch

    Loops

    For

    While

    Do while

    Other

    Break

    Continue

    Exactly the same as on left side

    +

    return

    go to

    C ASP.NET

  • functions

  • Functions

    Int findSum(int a,int b)

    {

    Int c;

    c=a+b;

    Return c

    }

    findSum(10,15);

    function findSum(byVal a as

    integer,byVal b as integer)

    Dim c as integer

    c=a+b

    Return c

    End function

    Dim d as integer = findSum(10,15)

    Response.write(d) output : 25

    C ASP.NET (vb.net example)

  • Functions

    public int findSum(int a, int b) {

    int c;

    c = (a + b);

    return c;

    }

    private int d = findSum(10, 15);

    Response.write(d); //output : 25

    ASP.NET (C# example)

  • Function arguments

    You can define any number of arguments to an ASP.NET function.

    Arguments can be passed by reference(byRef) or by value (byValue)

    o byRef - When an argument is passed by reference, the called procedure can change the value of the variable. The change persists after the procedure is called

    o byValue - When an argument is passed by value, any changes that the called procedure makes to the value of the variable do not persist after the procedure is called.

  • Function return type The function return type can also be defined in the function

    declaration VB.net

    Function findSum(byval a as integer, byval b as integer) as integer

    Dim c as integer

    c=a+b

    Return c

    End function

    C#

    public int findSum(int a, int b) {int c;c = (a + b);return c;

    }

  • Function return type A function without a return value is called as a sub routine

    and is defined as follows in ASP.NET Vb.net

    private sub findSum(byval a as integer, byval b as integer)

    Dim c as integer

    c=a+b

    End sub

    C#

    Protected void findSum(int a, int b)

    {

    int c;

    c=a+b;

    }

  • Strings

    Char a*+=Baabtra;

    Printf(Hello %s,a);

    Dim a as string =Baabtra

    Response.write( Hello + a) //Output:

    Hello baabtra

    Response.write( Hello + a) //Output:

    Hello + a

    Strings will be continued in coming

    chapters

    C ASP.NET

  • Arrays

    Indexed Array

    int a[]={1,2,3,4,5,6,7,8,9,10};

    for(i=0;i

  • Operators

  • Operators

    C

    Arithmetic Operators

    +, ++, -, --, *, /, %

    Comparison Operators

    ==, !=, ===, !==, >, >=, < ,

  • Comparison operators

    Operator description Example Result

    = Equal to 3 = 4 false

    < Less than 4 < 3 false

    > Greater than 4 > 3 true

    = 5 false

    / != Not equal to 4 3 / 4 != 3 true

  • Logical operators

    Operator description Example Result

    And / && Both Must be TRUE True And False false

    Or / || One Must be TRUE True Or False true

    Not / ! Flips Truth Value Not true false

    String operators

    Operator description Example Result

    & / +String Concatenation string4 = Hello" & " world"

    string4 = Hello world"

  • Bitwise operators allow you to manipulate bits of data. All these operators are designed to work only on integer numberstherefore, the interpreter will attempt to convert their operands to integers before executing them.

    Bitwise Operators

    AND Bitwise AND. The result of the operation will be a value whose bits are set if they are set in both operands, and unset otherwise.

    OR Bitwise OR. The result of the operation will be a value whose bits are set if they are set in either operand (or both), and unset otherwise.

    XOR Bitwise XOR (exclusive OR). The result of the operation will be a value whose bits are set if they are set in either operand, and unset otherwise.

    NOT Bitwise NOT. inverts each bit in a sequence of bits. A 0 becomes a 1, and a 1 becomes a 0.

    > Bitwise right shift. This operation shifts the left-hand operands bits to the right by a number of positions equal to the right operand, inserting unset bits in the shifted positions.

  • End of day 1

  • If this presentation helped you, please visit our page facebook.com/baabtra and like it.

    Thanks in advance.

    www.baabtra.com | www.massbaab.com |www.baabte.com

  • Contact Us

    Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 495 40 25 550

    NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 495 40 25 550

    Start up VillageEranakulam,Kerala, India.

    Email: [email protected]