Wednesday, June 25, 2014

asp.net

Contents of an ASP.NET Page (.aspx)

  1. HTML Tags
  2. Server Side Tags or ASP.NET Controls
    1. Special tags provided from .NET Framework which are internally classes
    2. They starts with asp:, mobile: etc.
    3. All such controls have runat=”server” attribute
  3. Directives
    1. Provides instructions to the compiler
    2. Use <%@ and %> delimiters
                                                              i.      Page directive
1.      <%@ Page Language=”C#” %>
                                                            ii.      Import directive
1.      <%@ Import Namespace=”System.Data” %>
  1. Scriplet
    1. Merging code of a .NET language into ASP.NET page
    2. Use <% and %> delimiters
Example
 
       <%
           for (int i = 1; i <= 100; i++)
               Response.Write(i+"<br>");
          
  %>
  1. Expessions
    1. 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>
  1. Intrinsic Objects or Built-in Objects
    1. Ready made objects provided by ASP.NET
                                                              i.      Request
                                                            ii.      Response
                                                          iii.      Session
                                                          iv.      Server
                                                            v.      Application
                                                          vi.      ViewState
  1. Client Side Scripts
    1. 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()));
            }
        }








Related Posts:

  • Remoting.Net vs Web Services Both .Net Web services and .Net Remoting are Microsoft solutions for distributed application. Before choosing one of them for application development, let’s identify the differences between these technologies. Protocol .Ne… Read More
  • Why do we need .Net Web Services? We have a number of heterogeneous technologies available on internet. The demand for reusable components across platforms and programming languages are high. Most of the components have the limitation that they can't share … Read More
  • Define the specifications that help in the discovery of a web service. DISCO DISCO, an abbreviation of discovery, is a file that groups together a list of related web services. A company that offers web services publishes a DISCO file on its server that has links of all the web services it pr… Read More
  • Explain in brief Web Service Standards Following are the standards used by web services: WSDL WSDL is used to create interface definition for a web services. It describes all about methods to the client, i.e. methods available in a web service, their parameters… Read More
  • What are the data types supported by Web Services? .Net web services are built on XML-based standards for exchanging data. This means .NET web services can support only those data types that can be recognized by the XML schema standard. There are many proprietary .Net objec… Read More

0 comments:

Post a Comment