Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP Web Server Controls Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "ASP Web Server Controls Please use speaker notes for additional information!"— Presentation transcript:

1 ASP Web Server Controls Please use speaker notes for additional information!

2 Label Web Server Control ASP.NET Label Web Server Control Label Web Server Control Label Web Server Control ASP.NET Label Web Server Control Simple example of a label control! My code. Output Results of viewing source.

3 Label Web Server Control Testing the Label Web Server Control Sub Page_Load lblHeader.Text="Testing the Label Web Server Control" lblDate.Text="Today is: " & now() End Sub ASP.NET

4 Testing the Label Web Server Control ASP.NET Testing the Label Web Server Control Today is: 6/24/2003 4:56:55 PM Testing the Label Web Server Control Sub Page_Load lblHeader.Text="Testing the Label Web Server Control" lblDate.Text="Today is: " & now() End Sub ASP.NET My code is shown here. The output is shown here. When you click on view source, you see the code below.

5 Testing the Label Web Server Control Sub Page_Load(sender As Object, e As EventArgs) lblHeader.Text="Testing the Label Web Server Control" lblDate.Text="Today is: " & now() End Sub ASP.NET Label Web Server Control

6 Textbox Web Server Control Sub NameSub(sender As Object, e As EventArgs) lblGreet.text = "Hi, " & txtFst.text & " " & txtLast.text End Sub ASP.NET Textbox Web Server Control First Name Last Name Button & Textbox Web Server Controls

7 Textbox Web Server Control ASP.NET Textbox Web Server Control First Name Last Name Hi, Susan Ash

8 List before I checked anything. List after I checked the three components of my sentence.

9 Here I unclicked the horse and you can see the sentence is simply jumped over the fence. Now I clicked The dog and the sentence got reformed starting with the first clicked element and moving sequentially through the last clicked item.

10 Make sentences using List Items Sub makeSentence(sender As Object, e As EventArgs) dim ct mySentence.Text=" Your sentence: " for ct =0 to phrases.Items.Count-1 if phrases.Items(ct).Selected then mySentence.Text=mySentence.Text & " " & phrases.Items(ct).Text end if next End Sub Sub clear(Source As Object, e As EventArgs) dim pt for pt = 0 to phrases.Items.Count-1 if phrases.Items(pt).Selected then phrases.Items(pt).Selected = False end if next mySentence.Text="" End Sub Each time this is executed, it checks all of the check boxes and concatenates each box that is checked to the mySentence structure. This code clears by checking to see if the item is checked and if it is setting it to false. Obviously, I did not need to do the check, I could have just set them all to false. Clears the sentence which is made up of the phrase Your sentence in a paragraph followed by the selected elements formed into the mySentence structure. The mySentence structure is a paragraph that says Your sentence: followed by the sentence I put together.

11 <asp:CheckBoxList id="phrases" AutoPostBack="True" TextAlign="Right" OnSelectedIndexChanged="makeSentence" runat="server"> The dog The cat The bird The fish The horse ran flew swam jumped trotted over the fence onto the railing into the rock down the hill into the tree into the cage up the stream <asp:Button id="clearButton" Text="Clear" runat="server" OnClick="clear"/> The event OnSelectedIndexChanged causes makeSentence to be executed. This code sets up the elements in the list. The label holds the sentence that was constructed. A clear button is set up. The on click event causes the clearButton sub to be executed.

12 Your sentence: The horse jumped over the fence <input id="phrases_0" type="checkbox" name="phrases:0" onclick="__doPostBack('phrases:0','')" language="javascript" /> The dog Make sentences using List Items <!-- function __doPostBack(eventTarget, eventArgument) { var theform = document._ctl0; theform.__EVENTTARGET.value = eventTarget; theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } // -->

13 <asp:CheckBoxList id="phrases" AutoPostBack="True" TextAlign="Right" OnSelectedIndexChanged="makeSentence" RepeatColumns=3 RepeatDirection=Vertical runat="server"> The dog The cat The bird The fish The horse The duck The elephant ran flew swam jumped trotted lumbered walked over the fence onto the railing into the rock down the hill into the tree into the cage up the stream <asp:Button id="clearButton" Text="Clear" runat="server" OnClick="clear"/> Changed code to get 3 vertical columns. Added elements to the list of items.

14

15 Make sentences using List Items <asp:Table runat="server" id="flyPrice" BorderWidth=3 CellPadding=5 CellSpacing=5 GridLines="both" HorizontalAlign="Left"> Fare Table From Boston From NY From DC To London 199 189 195 To San Francisco 245 230 295 Table Web Server Control Continued on next slide...

16 To Baku 535 500 490 To Oslo 420 380 410

17

18 Table Sub getFare(sender As Object, e As EventArgs) dim strFare as string dim intFromIndx as integer dim intToIndx as integer dim objRow as TableRow dim objCell as TableCell intFromIndx = fromCity.SelectedIndex intToIndx = toCity.SelectedIndex objRow = flyPrice.Rows.Item(intToIndx+1) objCell = objRow.Cells.Item(intFromIndx+1) strFare = objCell.Text yourFare.Text="Your fare is: " & strFare End Sub From Boston From NY From DC To London To San Francisco To Baku To Oslo <asp:Table runat="server" id="flyPrice" BorderWidth=3 CellPadding=5 CellSpacing=5 fromCity.Selected Index means to tell which one was selected (0, 1, 2). This works the same with toCity.Selected Index, but there is one more entry. Now I am going to the table with multiple rows (shown on next slide) and use intToIndx +1 because in this table I made the first row a header. After getting the Row, I then get the cell. I then store the text from the objCell as the strFare. Here is where I develop the contents of yourFare which is the id of the label displayed in the next screen.

19 GridLines="both" HorizontalAlign="Left"> Fare Table From Boston From NY From DC To London 197 189 195 To San Francisco 245 230 295 To Baku 535 500 490 To Oslo 420 380 410 This shows the setup of the table and cells and the data contained. You can see the headers and the data. I know use label to show the id of yourFare which was generated in the OnClick execution of getFare.

20 Table From Boston From NY From DC To London To San Francisco To Baku To Oslo Fare Table From Boston From NY From DC To London 197 189 195 To San Francisco 245 230 295 To Baku 535 500 490 To Oslo 420 380 410 Your fare is: 245


Download ppt "ASP Web Server Controls Please use speaker notes for additional information!"

Similar presentations


Ads by Google