0% found this document useful (0 votes)
42 views8 pages

Niversity: Abdul Majid Niazai

The document discusses working with objects in ASP.NET. It states that server coding often involves objects, such as the built-in DateTime object or self-defined objects like web pages, text boxes, files, and database records. Objects may have methods to perform actions and properties that describe their characteristics. It provides an example of accessing properties of the DateTime object, such as Day, Hour, Minute, and Second. The document also discusses using if/else conditions to determine what code to execute based on conditions. For example, it shows code to display "Good Evening" if the hour is after 12 and "Good Morning" otherwise.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views8 pages

Niversity: Abdul Majid Niazai

The document discusses working with objects in ASP.NET. It states that server coding often involves objects, such as the built-in DateTime object or self-defined objects like web pages, text boxes, files, and database records. Objects may have methods to perform actions and properties that describe their characteristics. It provides an example of accessing properties of the DateTime object, such as Day, Hour, Minute, and Second. The document also discusses using if/else conditions to determine what code to execute based on conditions. For example, it shows code to display "Good Evening" if the hour is after 12 and "Good Morning" otherwise.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

HE W A D UNIVERSITY

ASP.NET
Abdul Majid Niazai
[email protected]
Working With Objects

Server coding often involves objects.

The "DateTime" object is a typical built-in ASP.NET object, but objects can also be self-
defined, a web page, a text box, a file, a database record, etc.

Objects may have methods they can perform. A database record might have a "Save" method,
an image object might have a "Rotate" method, an email object might have a "Send" method,
and so on.

Objects also have properties that describe their characteristics. A database record might have
a FirstName and a LastName property (among others).
The example below shows how to access some
properties of the DateTime object:

<table border="1">
<tr>
<th width="100px">Name</th>
<td width="100px">Value</td>
</tr>
<tr>
<td>Day</td><td>@DateTime.Now.Day</td>
</tr>
<tr>
<td>Hour</td><td>@DateTime.Now.Hour</td>
</tr>
<tr>
<td>Minute</td><td>@DateTime.Now.Minute</td>
</tr>
<tr>
<td>Second</td><td>@DateTime.Now.Second</td>
</tr>
</td>
</table>
If and Else Conditions

 An important feature of dynamic web pages is that you can determine what to do based on
conditions.
 The common way to do this is with the if ... else statements:
@{
var txt = "";
if(DateTime.Now.Hour > 12)
  {txt = "Good Evening";}
else
  {txt = "Good Morning";}
}
<html>
<body>
<p>The message is @txt</p>
</body>
</html>
ASP.NET Razor - C# Variables

 Variables are used to store data.


 The name of a variable must begin with an alphabetic character and cannot contain
whitespace or reserved characters.

A variable can be of a specific type, indicating the kind of data it stores. String variables
store string values ("Welcome to Hewad Univers"), integer variables store number values
(103), date variables store date values, etc.

Variables are declared using the var keyword, or by using the type (if you want to declare
the type), but ASP.NET can usually determine data types automatically.
Converting Data Types

 Converting from one data type to another is sometimes useful.

The most common example is to convert string input to another type, such as
an integer or a date.
 As a rule, user input comes as strings, even if the user entered a number.
Therefore, numeric input values must be converted to numbers before they
can be used in calculations.
Below is a list of common conversion
methods:
Method Description Example
AsInt() if (myString.IsInt())
Converts a string to an integer.
IsInt()   {myInt=myString.AsInt();}

AsFloat() Converts a string to a floating-point if (myString.IsFloat())


IsFloat() number.   {myFloat=myString.AsFloat();}

AsDecimal() if (myString.IsDecimal())
Converts a string to a decimal number.
IsDecimal()   {myDec=myString.AsDecimal();}

AsDateTime() Converts a string to an ASP.NET myString="10/10/2012";


IsDateTime() DateTime type. myDate=myString.AsDateTime();

AsBool() myString="True";
Converts a string to a Boolean.
IsBool() myBool=myString.AsBool();

myInt=1234;
ToString() Converts any data type to a string.
myString=myInt.ToString();
End of Chapter 03

You might also like