What is ASP.NET?

bubblemessengerSecurity

Nov 5, 2013 (3 years and 8 months ago)

98 views

MCA
-
V

Lecture 4: Introduction to ASP.NET

ECNET

1

2012
-
13


A.M.Shuka

What is ASP.NET?

ASP.NET is a framework used for development and execution of web based application using MS.NET
framework.

To create a new ASP.NET application:



Open Visual Studio



File
-
> New Website

o

File Stsyem

-
> It uses ASP.NET Development Server and for

every web application a new
instance of ASP.NET Development Server Starts.

o

HTTP

-
> It uses IIS server.

Points to be noted/observed
:



Every Webform has an extension “.aspx”.



A webform doesn’t have action attribute and it always submits to itself. Even if th
e action
attributed is provided to the Server side form it is ignored by the ASP.NET framework.



The default method rendered for the Webform in ASP.NET is “POST”.



Here the UI(aspx) is separated from the Bussiness Code/Event Handlers (aspx.cs).



<%@ Page Auto
EventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default”%>



When an ASP.NET web application is build in VS.NET, we don’t get any output file in the form of
EXE or DLL.



ASP.NET controls uses the same programming model which uses for Windows based ap
plication.



Every sever side control rendered HTML output to the web browser.


Example 1:
TO Understand how to run program in VS

Hello World Application





MCA
-
V

Lecture 4: Introduction to ASP.NET

ECNET

2

2012
-
13


A.M.Shuka

Example 2:

Understanding Form Tag.


ASPX

<
form

id
="form1"

action
="default.aspx"

runat
="server">



<
div
>


<
asp
:
Literal

ID
="ltrMessage"

runat
="server"></
asp
:
Literal
>


<
br

/>


FirstName :
<
asp
:
TextBox

ID
="fn"

runat
="server"

TextMode
="Password"

/>


<
br

/>


LastName :
<
asp
:
TextBox

ID
="ln"

runat
="server"

/>


<
br

/>


<
asp
:
Button

ID
="btnSubmit"

runat
="server"

Text
="Submit"



onclick
="btnSubmit_Click"

/>


</
div
>


</
form
>


CS

protected

void

btnSubmit_Click(
object

sender,
EventArgs

e)


{


ltrMessage.Text =
"Hello"

+ fn.Text +
" "

+ ln.Te
xt;




}



Example 3
:

Understanding AutoPostBack property of Control.

ASPX

<
form

id
="form1"

runat
="server">


<
div
>


<
asp
:
Label

ID
="lblText"

Text
="DDL Example"

runat
="server"></
asp
:
Label
>


<
asp
:
DropDownList

ID
="ddlColor"

runat
="server"

AutoPostBack
="True"



onselectedindexchanged
="ddlColor_SelectedIndexChanged">


<
asp
:
ListItem

Text
="Red"

Value
="red"></
asp
:
ListItem
>


<
asp
:
ListItem

Text
="Green"

Value
="green"

Selected
="True"></
asp
:
ListItem
>



<
asp
:
ListItem

Text
="Blue"

Value
="blue"></
asp
:
ListItem
>


</
asp
:
DropDownList
>


</
div
>



</
form
>

MCA
-
V

Lecture 4: Introduction to ASP.NET

ECNET

3

2012
-
13


A.M.Shuka


CS

protected

void

ddlColor_SelectedIndexChanged(
object

sender,
EventArgs

e)


{


lblText.ForeColor = System.Drawing.
Color
.FromName(d
dlColor.SelectedValue);


}


Example 4:

To understand the first parameter of event handler method

(Object Sender)

ASPX


<
form

id
="form1"

runat
="server">


<
div
>


<
asp
:
Label

ID
="lblText"

runat
="server"

Text
="Hello"></
asp
:
Label
>


<
br

/>



<
asp
:
RadioButton

ID
="rbnRed"

runat
="server"

GroupName
="rbnColor"



oncheckedchanged
="rbnColor_CheckedChanged"

AutoPostBack
="True"

Text
="Red"

/>


<
asp
:
RadioButton

ID
="rbnGreen"

runat
="server"

GroupName
="rbnColor"



AutoP
ostBack
="True"

oncheckedchanged
="rbnColor_CheckedChanged"

Text
="Green"/>


<
asp
:
RadioButton

ID
="rbnBlue"

runat
="server"

GroupName
="rbnColor"



AutoPostBack
="True"

oncheckedchanged
="rbnColor_CheckedChanged"

Text
="Blue"

/>




</
div
>



</
form
>


CS

protected

void

rbnColor_CheckedChanged(
object

sender,
EventArgs

e)


{


//if (rbnRed.Checked)


// lblText.ForeColor = System.Drawing.Color.Red;


//else if (rbnBlue.Checked)


// lblText.ForeColor = System.Dr
awing.Color.Blue;


//else if (rbnGreen.Checked)


// lblText.ForeColor = System.Drawing.Color.Green;



RadioButton

rbn = (
RadioButton
)sender;


lblText.ForeColor = System.Drawing.
Color
.FromName(rbn.Text);


}


Example 5: To u
nderstand the second parameter of event handler method (Eventargs e)

ASPX

MCA
-
V

Lecture 4: Introduction to ASP.NET

ECNET

4

2012
-
13


A.M.Shuka

<
form

id
="form1"

runat
="server">


<
div
>


<
asp
:
ImageButton

ID
="imgbtnDesert"

runat
="server"

ImageUrl
="desert.jpg"



onclick
="imgbtnDesert_Click"

/>


<
br

/>


X Cordinate :
<
asp
:
TextBox

ID
="txtX"

runat
="server"

/>


<
br

/>


Y Cordinate :
<
asp
:
TextBox

ID
="txtY"

runat
="server"

/>


</
div
>


</
form
>


CS

protected

void

imgbtnDesert_Click(
object

sender,
ImageClickEventArgs

e)


{



txtX.Text = e.X.ToString();


txtY.Text = e.Y.ToString();


}



Example 6: To understand IsPostBack property

ASPX

<
form

id
="form1"

runat
="server">


<
div
>




<
table
>


<
tr
>


<
td
>


<
asp
:
ListBox

ID
="lstb1"

runat
="server">


<
asp
:
ListItem
>
ListItem1
</
asp
:
ListItem
>


<
asp
:
ListItem
>
ListItem2
</
asp
:
ListItem
>


<
asp
:
ListItem
>
ListItem3
</
asp
:
ListItem
>


<
asp
:
Lis
tItem
>
ListItem4
</
asp
:
ListItem
>


</
asp
:
ListBox
>


</
td
>


<
td
>


<
table
>


<
tr
>


<
td
>


<
asp
:
Button

ID
="btnF"

runat
="server"

Text
=">"

onclick
="btnF_Click"

/>


</
td
>


</
tr
>


<
tr
>


<
td
>


<
asp
:
Button

ID
="btnB"

runat
="server"

Text
="<"

/>

MCA
-
V

Lecture 4: Introduction to ASP.NET

ECNET

5

2012
-
13


A.M.Shuka


</
td
>


</
tr
>




</
table
>




</
td
>


<
td
>


<
asp
:
ListBox

ID
="lstb2"

runat
="server"></
asp
:
ListBox
>


</
td
>


</
tr
>




</
table
>


</
div
>


</
form
>


CS

protected

void

Page_Load(
object

sender,
EventArgs

e)


{


if

(!IsPostBack)


{


for

(
int

i = 1; i <= 4; i++)


{


ListItem

li =
new

ListItem
(
"item"

+ i);



lstb2.Items.Add(li);



}


}


}


protected

void

btnF_Click(
object

sender,
EventArgs

e)


{


if

(lstb1.SelectedItem !=
null
)


{


ListItem

li = lstb1.SelectedItem;


lstb2.Items.Add(li);


lstb1.Items.Remove(li);



li.Selected =
false
;


}





}




MCA
-
V

Lecture 4: Introduction to ASP.NET

ECNET

6

2012
-
13


A.M.Shuka