Contents of an
ASP.NET Page (.aspx)
- HTML Tags
- Server Side Tags or ASP.NET Controls
- Special tags provided from .NET Framework which are internally classes
- They starts with asp:, mobile: etc.
- All such controls have runat=”server” attribute
- Directives
- Provides instructions to the compiler
- Use <%@ and %> delimiters
i.
Page directive
1. <%@
Page Language=”C#” %>
ii.
Import directive
1. <%@
Import Namespace=”System.Data” %>
- Scriplet
- Merging code of a .NET language into ASP.NET page
- Use <% and %> delimiters
Example
<%
for (int i = 1; i
<= 100; i++)
Response.Write(i+"<br>");
%>
- Expessions
- Use <%= and %> delimiters to show the values of the variables and some expressions
Example
<% int
n = 5; %>
<h1>Square of
<%=n %>
is <%=n*n %></h1>
- Intrinsic Objects or Built-in Objects
- Ready made objects provided by ASP.NET
i.
Request
ii.
Response
iii.
Session
iv.
Server
v.
Application
vi.
ViewState
- Client Side Scripts
- Used for client/side dynamicity
i.
Java Script
ii.
VBScript
iii.
JScript
Example
<script type="text/javascript">
function square()
{
var num=parseInt(document.f.txtNum.value);
alert("Square is "+num*num);
}
</script>
<form name="f" id="f">
<div>
Number
<input id="txtNum" name="txtNum" type="text" /><input id="Button1"
type="button" value="Square" onclick="square()" /></div>
</form>
Working with ASP.NET
Controls
Label control
-
Text
TextBox control
-
Text
-
AccessKey
-
TextMode
-
MaxLength
-
ReadOnly
Button control
-
to create a push button
o Text
ImageButton
control
-
To use an image as button
o ImageUrl
LinkButton
control
-
To use a hyperlink kind of button
o Text
Image control
-
To place an image
o ImageUrl
Hyperlink Control
-
to make the hyperlink as Text or Image
o Text
o ImageUrl
o NavigateUrl
o Target
o ToolTip
Moving a control to
fix position
à Select the control à Format à
Position à
Absolute
à Now use drag and drop
Adding images into a
project
-
Select Viewà Solution Explorer à
Project Properties à Add à New Folder à Give some name to the
folder like images
-
Now select the folder and add existing images
Note: Use Panel
control to make the container and group to controls.
Sample Program 1
Write a web form to create two
label Number and Result. Now create two text
boxes, one to input a number and other to output a number (readonly). Now
create three different buttons as simple button, image button and link button
to show Square, SquareRoot and CubeRoot of give number.
Use Hotkeys on controls (AccessKey)
Creating a GIF file
-
Use GIF Animator
tool to animate the image and make the GIF file
Note: The pages create for web applications are called as
Web Forms. A web form is a class inherited from Page class of System.Web.UI
namespace.
DropDownList
control
-
Allows to select only one item from many items
-
Use Items
collection to add the items
-
Each item is an object of ListItem class
o ListItem(string
text, string value)
-
SelectedItem
o Text
o Value
Note: Use Page.IsPostBack
property to check the post backs
Example
protected
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 1950; i <=
DateTime.Now.Year; i++)
DropDownList1.Items.Add(new
ListItem(i.ToString()));
}
}
0 comments:
Post a Comment