Docstoc

IS 445 - ASP

Document Sample
IS 445 - ASP Powered By Docstoc
					                                    IS 445 - ASP.NET Notes

What software do you need to create and view ASP.NET pages?
1. To view your ASP.NET pages, Microsoft Internet Information Services (IIS)
   will need to be installed and running on your Server PC. IIS is a web server application.
   IIS is not available in Windows 95, Windows 98 or Windows XP Home Edition.

2. To develop ASP.NET applications you will need one of the following Operating Systems:
    Windows 2000 (Professional or Server editions) with IIS 5.0 installed
    Windows XP (Professional edition) with IIS 5.1 installed
    Windows 2003 (Standard, Enterprise, Datacenter or Web editions) with IIS 6.0 installed


3.    To compile and view your ASP.NET pages, the Microsoft .NET Framework SDK version 1.1
      must be installed you your PC. The .NET Framework includes a Visual Basic compiler.

4.    To write your ASP .NET code you will need a text editor such as Notepad,
      Textpad or Visual Studio .NET

5.    To view your ASP.NET pages, you will need a Browser such as Internet Explorer or Netscape

6.    For Database projects you will need Microsoft Access or Microsoft SQL server



     Microsoft’s .NET Framework (in a Nutshell)
        Supports multiple programming languages (Visual Basic, C#, C++, JScript, etc)

        Visual Basic is the default programming language for ASP.NET

        Contains over 3,400 classes to handle every conceivable programming task for working with files,
         databases, images, graphics, text and more. You can access any of the .NET classes when
         building an ASP.NET page

        The .NET classes are organized in logical groupings called “namespaces”.
         For example, the namespace for working with the File System is System.IO,
         And the namespace for manipulating strings is System.Text.
  Compiling ASP.NET – “Under the Hood”
     ASP.NET Pages are compiled before they are executed.
      The FIRST time you request an ASP.NET page, the page in compiled into a .NET class.
      This class file is stored in a special directory on your server named
      “Temporary ASP.NET Files”.

     ASP.NET pages are not compiled directly into machine code.
      Instead, they are compiled into an intermediate-level language called
      Microsoft Intermediate Language (MSIL).
      All .NET compatible languages are compiled into MSIL.

     An ASP.NET page is not compiled into native machine code until it is actually requested by a
      browser. At this point, the class file in the “Temporary ASP.NET Files” directory is
      compiled with the .NET Framework Just In Time (JIT) compiler and executed.




Viewing an ASP.NET Page In Your Browser
     You must save your ASP.NET page in a directory that your browser can access.

     Save your ASP.NET pages in the inetpub/wwwroot directory, or in a folder below this
      directory.

     Do not open the page directly in your browser by typing the filepath.
      Instead, if your web server and browser are on the same machine,
      enter this URL in your browser:

                        http://localhost/filename.aspx

      So, assuming your ASP.NET file is named test1.aspx, enter

                        http://localhost/test1.aspx

     localhost is your web server.
      You must not forget to type http://localhost.
      localhost looks for files in the inetpub/wwwroot directory.
 Benefits of ASP .NET
        Provides a programmable way to render web pages

        Form data will retain it’s value by using View State

        Allows for a cleaner separation of design code and logic code

        Enables you to retain browser compatibility




ASP.NET Pages – Things You Need To Know
1) ASP.NET pages use the File Extension .aspx          (example: demo.aspx)

2) Although the .NET Framework supports multiple programming languages,
   each aspx page can only contain a single language.

3) Each aspx page must contain a form tag with the attribute Runat=”Server”.
   This is known as a Server-Side Form.
     Example: <form Runat=”Server”>

4)   There must be exactly ONE Server-Side Form in your aspx page.

5)   ASP.NET Web Controls must appear within the <form></form> tags
     The exception is for <span Runat=”Server” /> and <asp:Label Runat=”Server” />

6)   Visual Basic subroutines and functions must be declared in script tags with the
      attribute Runat=”Server”.
         Example:     <Script Runat=”Server”>
                           Sub AddNumbers
                           Dim Result = 5 + 9
                           End Sub
                       </Script>


7)   You must use parenthesis ( ) when passing data to a function.
         Example:     Response.Write(“Hello World”)


8) Instead of using the NAME attribute for your ASP Controls,
     use the ID attribute.
Page Events
  An aspx page raises 4 specific events every time the page is requested.
  The Sequence of events happens as listed in items 1 through 4 below.

  1. Page_Init

  2. Page_Load

  3. Page_PreRender

  4. Page_Unload

 The most useful of these events is the Page_Load event.
 You can use Page_Load to initialize variables and controls in your aspx page.

     Note: Any text created by the Page_Unload subroutine will never be displayed because
           Page_Unload happens after all content has been rendered to the browser.



Page Post Back
  When a form is submitted, the action attribute declares where the data should is “posted” to.
  The for data is sent to the URL in the action attribute, and then this URL will be displayed
  in the browser. Example:
                              <form method=”post” action=”text.aspx”>

  With ASP .NET, However…
     All forms default to a method of “post”
     All pages post back to themselves by default

  So, an ASP .NET form does not need to set the action attribute unless you want to
  display a different URL after you submit the form data.
  Here is what a typical aspx form tag looks like:     <form runat=”server”>




The IsPostBack Property
  You can use Page.IsPostBack with the Page_Load event to execute code the First time a
  page is loaded. Subsequent page – post backs will not execute this code.
  See the RadioButtonList code in the “Web Controls” section for an example.
Server-Side Comments
   You can add comments to your ASP code by using server-side comment blocks.
   Server-side comment tags are <%-- and --%>
            Example:    <%--    This code has been commented out
                           <asp:Label Text=”Hello” runat=”Server” />
                         --%>




Code Render Blocks
  1. Inline Code executes one or more ASP statements within the <% … %> tags
     Use Inline Code to add ASP code inside the <BODY> of your HTML
            Example:    <p>
                           <%Response.Write(“Hello World”)%>
                        </p>




  2. Inline Expressions display the value of an expression or method
        Example:

          <script runat="server">
             Dim SomeText As String

             Sub Page_Load
                    SomeText = “Hello”
             End Sub
          </script>

          <html>
          <body>

          <form runat="server">

             Here Is the Text: <%=Sometext%>
          </form>
          </body>
          </html>
                                  HTML Server Controls
HTML server controls are HTML tags understood by the server.
HTML elements in ASP .NET files are, by default, treated as text.
To make these elements programmable, add a runat="server" attribute to the HTML element.
This attribute indicates that the element should be treated as a server control.

Note: All HTML server controls must be within a <form> tag with the runat="server" attribute!

Note: ASP .NET requires that all HTML elements must be properly closed and properly nested.

HTML Server Control Descriptions
HtmlAnchor                   Controls an <a> HTML element
HtmlButton                   Controls a <button> HTML element
HtmlForm                     Controls a <form> HTML element
HtmlGeneric                  Controls HTML elements that don’t have a corresponding
                             HTML server control, like <body>, <div>, <span>, etc.
HtmlImage                    Controls an <image> HTML element
HtmlInputButton              Controls <input type="button">, <input type="submit">,
                             and <input type="reset"> HTML elements
HtmlInputCheckBox            Controls an <input type="checkbox"> HTML element
HtmlInputFile                Controls an <input type="file"> HTML element
HtmlInputHidden              Controls an <input type="hidden"> HTML element
HtmlInputImage               Controls an <input type="image"> HTML element
HtmlInputRadioButton         Controls an <input type="radio"> HTML element
HtmlInputText                Controls <input type="text"> and
                              <input type="password"> HTML elements
HtmlSelect                   Controls a <select> HTML element
HtmlTable                    Controls a <table> HTML element
HtmlTableCell                Controls <td>and <th> HTML elements
HtmlTableRow                 Controls a <tr> HTML element
HtmlTextArea                 Controls a <textarea> HTML element
                                    WEB Server Controls
Web server controls are special ASP .NET tags understood by the server.
Web server controls are created on the server and they require a runat="server" attribute to work.
Web server controls do not necessarily map to any existing HTML elements.

The syntax for creating a Web server control is:
                    <asp:control_name id="some_id" runat="server" />

Web Server Controls (Brief Description):
AdRotator          Displays a sequence of images
Button             Displays a push button
Calendar           Displays a calendar
CheckBox           Displays a check box
CheckBoxList       Creates a multi-selection check box group
DataGrid           Displays fields of a data source in a grid
DataList           Displays items from a data source by using templates
DropDownList       Creates a drop-down list
HyperLink          Creates a hyperlink
Image              Displays an image
ImageButton        Displays a clickable image
Label              Displays static content which is programmable
                   (lets you apply styles to its content)
LinkButton         Creates a hyperlink button
ListBox            Creates a single- or multi-selection drop-down list
Literal            Displays static content which is programmable
                   (does not let you apply styles to its content)
Panel              Provides a container for other controls
PlaceHolder        Reserves space for controls added by code
RadioButton        Creates a radio button
RadioButtonList Creates a group of radio buttons
Repeater           Displays a repeated list of items bound to the control
Table              Creates a table
TableCell          Creates a table cell
TableRow           Creates a table row
TextBox            Creates a text box
Xml                Displays an XML file or the results of an XSL transform
                                  Validation Server Controls
Validation server controls are used to validate user-input.
A Validation server control is used to validate the data of an input control.
If the data does not pass validation, it will display an error message to the user.

The syntax for creating a Validation server control is:

                  <asp:control_name id="some_id" runat="server" />


Validation Server Control Descriptions
CompareValidator                 Compares the value of one input control to the value of
                                 another input control or to a fixed value

CustomValidator                  Allows you to write a method to handle the validation of the value entered

RangeValidator                   Checks that the user enters a value that falls between two values

RegularExpressionValidator       Ensures that the value of an input control matches a specified pattern.
                                  (Example: Zip code data should be 5 digits)

RequiredFieldValidator           Makes an input control a required field

ValidationSummary                Displays a report of all validation errors occurred in a Web page
                   ASP.NET Web Server Control Details
AdRotator
         <script runat="server">
            Sub change_url(sender As Object, e As AdCreatedEventArgs)
              e.NavigateUrl="http://www.w3schools.com"
            End Sub
         </script>

         <html>
         <body>

         <form runat="server">

            <asp:AdRotator id=”showed”
                           AdvertisementFile="Ad1.xml"
                           runat="server"
                           OnAdCreated="change_url"
                           target="_blank" />
         </form>
         </body>
         </html>




Button     Buttons must respond to mouse click events.
           Buttons can respond with OnClick() or OnCommand() methods.

    <asp:Button      id=”btnCounter”
                     text=”Click Me”
                     OnClick=”btnCounter_Click”             <!--The Func Name-->
                     Runat=”Server”   />


    <asp:Button      id=”btnAdd”
                     text=”Add 5”
                     CommandName=”Add”
                     CommandArgument=”5”
                     OnCommand=”Button_Command”             <!--The Func Name-->
                     Runat=”Server”   />

   The difference between OnClick() and onCommand() is that OnCommand() passes
   Information to the event handler. (Remember, an “event handler” is a function.)
   In the above examples, there will be an event handler called btnCounter_Click()
   and an event handler called Button_Command().
BUTTON SAMPLE #1


<script runat="server">
    Sub submit(Source As Object, e As EventArgs)
        Button1.Text="You clicked me!"
    End Sub
</script>
<html>
<body>
<form runat="server">

  <asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit"/>

</form>
</body>
</html>




BUTTON SAMPLE #2


<script runat="server">
    Sub submit(Source As Object, e As EventArgs)
      button1.Style("background-color")="#0000ff"
      button1.Style("color")="#ffffff"
      button1.Style("width")="200px"
      button1.Style("cursor")="hand"
      button1.Style("font-family")="verdana"
      button1.Style("font-weight")="bold"
      button1.Style("font-size")="14pt"
      button1.Text="You clicked me!"
    End Sub
</script>

<html>
<body>
<form runat="server">

  <asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit"/>

</form>
</body>
</html>
Calendar
      CALENDAR SAMPLE #1

      <html>
      <body>
      <form runat="server">
              <asp:Calendar runat="server" />
      </form>
      </body>
      </html>




      CALENDAR SAMPLE #2

      <html>
      <body>
      <form runat="server">

           <asp:Calendar DayNameFormat="Full" runat="server">

                <WeekendDayStyle BackColor="#fafad2" ForeColor="#ff0000" />
                <DayHeaderStyle ForeColor="#0000ff" />
                <TodayDayStyle   BackColor="#00ff00" />

           </asp:Calendar>

      </form>
      </body>
      </html>




      CALENDAR SAMPLE #3

      <html>
      <body>
      <form runat="server">

            <asp:Calendar DayNameFormat="Full" runat="server"
                          SelectionMode="DayWeekMonth"
                          SelectMonthText="<*>"
                          SelectWeekText="<->"/>

                  <SelectorStyle BackColor="#f5f5f5" />

           </asp:Calendar>
      </form>
      </body>
      </html>
CheckBox      CheckBox controls create a simple check box on a page.

      <asp:CheckBox      id=”AddEmail”
                         Text=”Add Me You Your Email List ”
                         AutoPostBack=”False”
                         Checked=“False”
                         TextAlign=”Left”
                         OnCheckChanged=”Update_Mailer”
                         Runat=”Server” />

 Attribute Info:
  AutoPostBack True|False     If true, the form will be posted whenever
                               any Button in this group is checked.
   Checked      True|False    Equals True when the button is selected
   TextAlign    Left|Right    Relative to the Button. Default is Right.
   OnCheckChanged=”func_name” Calls an Event-Handler when the Check Box
                               is selected. (Optional.)

           <script runat="server">
              Sub Check(sender As Object, e As EventArgs)
                if check1.Checked then
                  work.Text=home.Text
                else
                  work.Text=""
                end if
              End Sub
           </script>

           <html>
           <body>
           <form runat="server">

               <p>Home Phone:
               <asp:TextBox id="home" runat="server" />

               <br />Work Phone:
               <asp:TextBox id="work" runat="server" />

                <asp:CheckBox id="check1"
                              Text="Same as home phone"
                              TextAlign="Right"
                              AutoPostBack="True"
                              OnCheckedChanged="Check"
                              runat="server" />
                 </p>
           </form>
           </body>
           </html>
CheckBoxList         The CheckBoxList control represents a list of Check Boxes.
                     Each list item is an individual Check Box.
                     (See also RadioButtonList).

   <asp:CheckBoxList id=”FavFood” Runat=”Server”>
        <asp:ListItem Text=”Pizza” Value=”Pizza” />
        <asp:ListItem Text=”Steak” Value=”Steak” Selected=”True” />
        <asp:ListItem Text=”Salad” Value=”Salad” />
   </asp:CheckBoxList>


 Attribute Info:
  AutoPostBack True|False                  Same as attribute for RadioButton..
  CellPadding              Sets the number of Pixels between the border and a particular Check Box
  CellSpacing              Sets the number of Pixels between individual radio Check Boxes
  Items                    Represents the collection of items in the CheckBoxList.
  DataSource               A Data source for the items listed in the CheckBox List.
  SelectedIndex The index number of the currently checked box
  SelectedItem             Represents the selected Check Box
  SelectedValue Gets or Sets the selection status CheckBox
  TextAlign             Left|Right           Alignment of Label relative to the CheckBox.
  OnSelectedIndexChanged=”func_name”
               Calls an Event-Handler when the CheckBox is selected. (Optional.)

 It is also possible to have multiple selected items in a CheckBoxList.
 To determine which items are selected, you must loop through the items as follows:

         <script runat="server">
         Sub Check(sender As Object, e As EventArgs)
            dim i
            mess.Text="<p>Selected Item(s):</p>"
            for i=0 to check1.Items.Count-1
              if check1.Items(i).Selected then
                 mess.Text+=check1.Items(i).Text + "<br />"
              end if
            next
         End Sub
         </script>

         <html>
         <body>
         <form runat="server">

              <asp:CheckBoxList id="check1"
                                AutoPostBack="True"
                                TextAlign="Right"
                                OnSelectedIndexChanged="Check"
                                runat="server">

                    <asp:ListItem>Item 1</asp:ListItem>
                    <asp:ListItem>Item 2</asp:ListItem>
                     <asp:ListItem>Item   3</asp:ListItem>
                     <asp:ListItem>Item   4</asp:ListItem>
                     <asp:ListItem>Item   5</asp:ListItem>
                     <asp:ListItem>Item   6</asp:ListItem>

                </asp:CheckBoxList>

                <br />
                <asp:label id="mess" runat="server"/>

           </form>
           </body>
           </html>


CompareValidator

CustomValidator

DataGrid

DataList


DropDownList
           <script runat="server">
           Sub submit(sender As Object, e As EventArgs)
              mess.Text="You selected " & drop1.SelectedItem.Text
           End Sub
           </script>

           <html>
           <body>
           <form runat="server">

               <asp:DropDownList id="drop1" runat="server">

                  <asp:ListItem>Item      1</asp:ListItem>
                  <asp:ListItem>Item      2</asp:ListItem>
                  <asp:ListItem>Item      3</asp:ListItem>
                  <asp:ListItem>Item      4</asp:ListItem>
                  <asp:ListItem>Item      5</asp:ListItem>
                  <asp:ListItem>Item      6</asp:ListItem>
               </asp:DropDownList>

               <asp:Button Text="Submit" OnClick="submit" runat="server"/>

               <p>   <asp:label id="mess" runat="server"/>   </p>

           </form>
           </body>
           </html>
Hyperlink
        <html>
        <body>
        <form runat="server">

            <asp:HyperLink   ImageUrl      ="csulb.gif"
                             NavigateUrl   ="http://www.csulb.edu"
                             Text          ="Visit Cal State Long Beach!"
                             Target        ="_blank"
                             runat         ="server" />
        </form>
        </body>
        </html>




Image
        <html>
        <body>
        <form runat="server">

            <asp:Image   runat         ="server"
                         AlternateText ="Visit Cal State Long Beach!"
                         ImageUrl      ="csulb.gif" />

        </form>
        </body>
        </html>
ImageButton
   ImageButton is similar to a regular Button, except that ImageButton displays an image.
   Like the Button control, ImageButton can also use the OnCommand attributes.
   When you click on the image, the OnClick or OnCommand event handler is called.

          <asp:ImageButton          id=”imgBtn1”
                                    ImageUrl=”flower.gif”
                                    ImageAlign=”Top”
                                    AlternativeText=”A Flower”
                                    OnClick=”ImageBtn1_Click”
                                    Runat=”Server”   />


          <asp:ImageButton          id=”imgPickColor”
                                    ImageUrl=”rainbow.gif”
                                    ImageAlign=”Left”
                                    AlternativeText=”Update Your Browser”
                                    CommandName=”ChangeBGColor”
                                    CommandArgument=”Yellow”
                                    OnCommand=”imgPickColor_Click”
                                    Runat=”Server”    />


    THE FOLLOWING CODE WILL DISPLAY THE X/Y COORDINATES WITHIN
    AN IMAGE WHERE THE MOUSE WAS CLICKED:

      <script runat="server">
      Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
         mess.Text="Coordinates: " & e.x & ", " & e.y
      End Sub
      </script>

      <html>
      <body>
      <form runat="server">

          <p>Click on the image:</p>

          <asp:ImageButton        runat="server"
                                  ImageUrl="..\images\smiley.gif"
                                  OnClick="getCoordinates" />

          <p> <asp:label id="mess" runat="server"/> </p>

      </form>
      </body>
      </html>
Label
          To change the data that is displayed by the Label,
          re-assign new data to the Text attribute. (Message.Text = ”Goodbye! ”)

           <asp:Label     id=”Message”
                          Text=”Here is Some Text! ”
                          Runat=”Server” />



        <script runat="server">
        Sub submit(Sender As Object, e As EventArgs)
           label1.Text=txt1.Text
        End Sub
        </script>

        <html>
        <body>
        <form runat="server">

           Write some text:
           <asp:TextBox id="txt1" Width="200" runat="server" />

           <asp:Button    id="b1"
                          Text="Copy to Label"
                          OnClick="submit"
                          runat="server" />

           <p>
                   <asp:Label id="label1" runat="server" />
            </p>
        </form>
        </body>
        </html>
LinkButton         The LinkButton control renders a HyperText link.
                   When you click the link, all the fields in the form that contain the link will
                   be submitted to the server.

            <asp:LinkButton          id=”link3”
                                     Text=”Send Data ”
                                     CausesValidation=”False”
                                     OnClick=”Link3_Click”
                                     Runat=”Server” />

            <asp:LinkButton         id=”runUpdate”
                                    Text=”Send Data ”
                                    CommandName=”ValidateQtyField”
                                  CommandArgument=”Limit”
                                    OnCommand=”LinkUpdate_Click”
                                    Runat=”Server” />



    LinkButton can use either OnClick or OnCommand attributes.
    If the CausesValidation attribute is set to false, the form submitted by
     the button is not validated.
    The Default value for CausesValidation is true.
    The LinkButton control does not work if JavaScript is disabled in the browser.


          <script runat="server">
          Sub lblClick(sender As Object, e As EventArgs)
             Label1.Text="You clicked the LinkButton control"
          End Sub
          </script>

          <html>
          <body>
          <form runat="server">

                    <asp:LinkButton            Text="Click me!"
                                               OnClick="lblClick"
                                               runat="server" />

                    <p>
                           <asp:Label id="Label1" runat="server" />
                    </p>
          </form>
          </body>
          </html>
ListBox
          <script runat="server">
          Sub submit(Sender As Object,e As EventArgs)
          mess.Text="You selected " & drop1.SelectedItem.Text
          End Sub
          </script>

          <html>
          <body>
          <form runat="server">

             <asp:ListBox id="drop1" rows="3" runat="server">

                  <asp:ListItem selected="true">Item 1</asp:ListItem>
                  <asp:ListItem>Item 2</asp:ListItem>
                  <asp:ListItem>Item 3</asp:ListItem>
                  <asp:ListItem>Item 4</asp:ListItem>
                  <asp:ListItem>Item 5</asp:ListItem>
                  <asp:ListItem>Item 6</asp:ListItem>
             </asp:ListBox>

             <asp:Button Text="Submit" OnClick="submit" runat="server" />

             <p><asp:label id="mess" runat="server" /></p>

          </form>
          </body>
          </html>


Literal
          <html>
          <body>
          <form runat="server">
                <asp:Literal Text="I love ASP. NET!" runat="server" />
          </form>
          </body>
          </html>

      LITERAL SAMPLE #2

          <script runat="server">
          Sub submit(sender As Object, e As EventArgs)
             Literal1.Text="I love ASP.NET!"
          End Sub
          </script>

          <html>
          <body>
          <form runat="server">
            <asp:Literal id="Literal1" Text="I love ASP!" runat="server" />
            <br><br>
            <asp:Button Text="Change Text" OnClick="submit" runat="server" />
          </form>
          </body>
          </html>
Panel
          <script runat="server">
          Sub Page_Load(sender As Object, e As EventArgs)
             if check1.Checked then
               panel1.Visible=false
             else
               panel1.Visible=true
             end if
          End Sub
          </script>

          <html>
          <body>
          <form runat="server">

              <asp:Panel id="panel1"
                         runat="server"
                          BackColor="#ff0000"
                          Height="100px"
                          Width="100px"> Hello World!
              </asp:Panel>

              <asp:CheckBox   id    ="check1"
                              Text ="Hide Panel control"
                              Runat ="server"/>
              <br /><br />
              <asp:Button Text="Reload" runat="server" />

          </form>
          </body>
          </html>




PlaceHolder
RadioButton      RadioButton controls add individual Radio Buttons to a page.
                 Radio Buttons are grouped together using the GroupName attribute.
                 Only one RadioButton in a group can be checked at any time.

      <asp:RadioButton   id=”SanFran”
                             Text=”San Francisco ”
                             GroupName=”Cities”
                             Checked=“false”
                             TextAlign=”Left”
                             OnCheckChanged=”CityChanged”
                             Runat=”Server” />

 Attribute Info:
  AutoPostBack True|False     If true, the form will be posted whenever
                               any Button in this group is checked.
   Checked      True|False    Equals True when the button is selected
   TextAlign    Left|Right    Relative to the Button. Default is Right.
   OnCheckChanged=”func_name” Calls an Event-Handler when the Button is selected.
                               Optional.

        <script runat="server">
         Sub submit(Sender As Object, e        As EventArgs)
           if red.Checked then
              Label1.Text="You selected        " & red.Text
           elseIf green.Checked then
              Label1.Text="You selected        " & green.Text
           elseIf blue.Checked then
              Label1.Text="You selected        " & blue.Text
           end if
         End Sub
        </script>

        <html>
        <body>
        <form runat="server">
            Select your favorite color:<br />

           <asp:RadioButton      id="red" Text="Red" Checked="True"
                                 GroupName="colors" runat="server"/><br />

           <asp:RadioButton id="green" Text="Green"
                            GroupName="colors" runat="server"/><br />

           <asp:RadioButton id="blue" Text="Blue"
                            GroupName="colors" runat="server"/><br />

            <asp:Button text="Submit" OnClick="submit" runat="server"/>

           <p><asp:Label id="Label1" runat="server"/></p>
        </form>
        </body>
        </html>
RadioButtonList         The RadioButtonList control represents a list of Radio Buttons.
                        Each list item is an individual Radio Button.

           <asp:RadioButtonList id=”FavColor” Runat=”Server”>
                <asp:ListItem Text=”Red” Value=”Red” />
                <asp:ListItem Text=”Blue” Value=”Blue” Selected=”True” />
                <asp:ListItem Text=”Green” Value=”Green” />
           </asp:RadioButtonList>

 Attribute Info:
  AutoPostBack True|False                 Same as attribute for RadioButton..
  CellPadding             Sets the number of Pixels between the border and a particular button
  CellSpacing             Sets the number of Pixels between individual radio buttons
  Items                   Represents the collection of items in the RadioButtonList.
  DataSource              A Data source for the items listed in the RadioButtonList.
  SelectedIndex The index number of the currently checked button
  SelectedItem            Represents the selected radio button
  SelectedValue Gets or Sets the selection status of a radio button
  TextAlign             Left|Right          Relative to the Button. Default is Right.
  OnSelectedIndexChanged=”func_name”
          Calls an Event-Handler when the Button is selected. (Optional.)


          <script runat="server">
          Sub submit(sender As Object, e As EventArgs)
             label1.Text="You selected " & radiolist1.SelectedItem.Text
          End Sub
          </script>

          <html>
          <body>
          <form runat="server">

              <asp:RadioButtonList id="radiolist1" runat="server">
                  <asp:ListItem selected="true">Item 1</asp:ListItem>
                  <asp:ListItem>Item 2</asp:ListItem>
                  <asp:ListItem>Item 3</asp:ListItem>
                  <asp:ListItem>Item 4</asp:ListItem>
               </asp:RadioButtonList>

            <br />
            <asp:Button text="Submit" OnClick="submit" runat="server"/>
            <p>
                <asp:Label id="Label1" runat="server"/>
            </p>
          </form>
          </body>
          </html>
     It is also possible to dynamically add items to a RadioButtonList as follows:
           <Script Runat=”Server”>
              Sub Page_Load
                     If Not IsPostBack Then
                         States.Items.Add( New ListItem (“California”, “CA”) )
                         States.Items.Add( New ListItem (“Washington”, “WA”) )
                         States.Items.Add( New ListItem (“Arizona”, “AZ”) )
                     End If
              End Sub
           </Script>

           <html>
           <head></head>
           <body>

                 <form Runat=”Server”>

                   <asp:RadioButtonList       id=”States” Runat=”Server” />
               </form>
           </body>
           </html>




RangeValidator



RegularExpressionValidator



Repeater



RequiredFieldValidator
Table
        <html>
        <body>
        <form runat=server>

           <asp:Table runat="server" CellPadding="5"
                      GridLines="horizontal" HorizontalAlign="Center">

              <asp:TableRow>
                    <asp:TableCell>1</asp:TableCell>
                    <asp:TableCell>2</asp:TableCell>
              </asp:TableRow>
              <asp:TableRow>
                    <asp:TableCell>3</asp:TableCell>
                    <asp:TableCell>4</asp:TableCell>
              </asp:TableRow>
          </asp:Table>

          <br />

         <asp:Table runat="server" CellPadding="5"
                      GridLines="vertical" HorizontalAlign="Center">
            <asp:TableRow>
               <asp:TableCell>1</asp:TableCell>
               <asp:TableCell>2</asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
               <asp:TableCell>3</asp:TableCell>
               <asp:TableCell>4</asp:TableCell>
           </asp:TableRow>
          </asp:Table>

        </form>
        </body>
        </html>
            TABLE SAMPLE #2

            <script runat="server">
            Sub Page_Load(sender As Object, e As EventArgs)
                dim rows,cells,j,i
                rows=3
               cells=2
               For j=0 To rows-1
                  dim r As New TableRow()
                  For i=0 To cells-1
                     dim c As New TableCell()
                    c.Controls.Add(New LiteralControl("row " & j & ", cell " & i))
                     r.Cells.Add(c)
                  Next
                  Table1.Rows.Add(r)
                Next
            End Sub
            </script>

            <html>
            <body>
            <form runat="server">

                 <asp:Table id="Table1" BorderWidth="1"
                            GridLines="Both" runat="server" />
            </form>
            </body>
            </html>




TableCell       See Table (Above)




TableRow        See Table (Above)
TextBox      TextMode may be SingleLine, MultiLine or Password


      <asp:TextBox        id=”UserPass”                  <!— A Single line input-->
                          TextMode=”password”
                          Columns=”30”
                          Runat=”Server” />


      <asp:TextBox        id=”Comments”                  <!— A Multi-line input-->
                          TextMode=”multiline”
                          Columns=”30”
                          Rows=”10”
                          Runat=”Server” />


      Some attributes are mutually exclusive.
      For example, you can’t have a MultiLine password input.

             <script runat="server">
             Sub submit(sender As Object, e As EventArgs)
                lbl1.Text="Your name is " & txt1.Text
             End Sub
             </script>

             <html>
             <body>
             <form runat="server">

                  Enter your name:
                  <asp:TextBox id="txt1" runat="server" />

                  <asp:Button OnClick="submit" Text="Submit" runat="server" />

                  <p><asp:Label id="lbl1" runat="server" /></p>

             </form>
             </body>
             </html>




ValidationSummary
Xml
      THIS CODE WILL DISPLAY AN XML FILE:

      <html>
      <body>
      <form runat="server">

          <asp:Xml   DocumentSource="cdcatalog.xml"
                     TransformSource="cdcatalog.xsl"
                     runat="server" />
      </form>
      </body>
      </html>



      HERE IS THE “cdcatalog” XML FILE MENTIONED ABOVE:

      <?xml version="1.0" encoding="ISO-8859-1" ?>
        <catalog>
          <cd>
             <title>Empire Burlesque</title>
             <artist>Bob Dylan</artist>
             <country>USA</country>
             <company>Columbia</company>
             <price>10.90</price>
             <year>1985</year>
          </cd>
          <cd>
             <title>Hide your heart</title>
             <artist>Bonnie Tyler</artist>
             <country>UK</country>
             <company>CBS Records</company>
             <price>9.90</price>
             <year>1988</year>
          </cd>
          <cd>
             <title>Greatest Hits</title>
             <artist>Dolly Parton</artist>
             <country>USA</country>
             <company>RCA</company>
             <price>9.90</price>
             <year>1982</year>
          </cd>
          <cd>
             <title>Still got the blues</title>
             <artist>Gary Moore</artist>
             <country>UK</country>
             <company>Virgin records</company>
             <price>10.20</price>
             <year>1990</year>
          </cd>
          <cd>
             <title>Eros</title>
       <artist>Eros Ramazzotti</artist>
       <country>EU</country>
       <company>BMG</company>
       <price>9.90</price>
       <year>1997</year>
    </cd>
  </catalog>




HERE IS THE “cdcatalog” XSL FILE MENTIONED ABOVE:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
  <h2>My CD Collection</h2>
  <table border="1">
      <tr bgcolor="#9acd32">
         <th align="left">Title</th>
         <th align="left">Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
         <tr>
            <td>
                <xsl:value-of select="title" />
            </td>
            <td>
                <xsl:value-of select="artist" />
            </td>
         </tr>
     </xsl:for-each>
  </table>
  </body>
  </html>
  </xsl:template>
  </xsl:stylesheet>
                                        BIBLIOGRAPHY

Beginning ASP.NET 1.0 With Visual Basic .NET    Goode, Kauffman, et. al. Wrox Publishing, 2003


ASP.NET Unleashed 2nd Edition   Walther, Stephen   Sams Publishing, 2004


ASP.NET Kick Start   Walther, Stephen   Sams Publishing, 2003


ASP.NET And VB .NET Web Programming        Crouch, Matt   Addison Wesley Publishing, 2002

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:9
posted:11/27/2011
language:English
pages:29