L19 - 5. Web Application Controls

L19 - 5. Web Application Controls - 1 Server-Side Scripting...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Y. Chen 1 Server-Side Scripting Using Web Controls Default.aspx <html> <head runat="server"><title>Server Side Scripting</title></head> <body> <form runat="Server"> < asp:TextBox ID= "x" RunAt="server" /> + < asp:TextBox ID= "y" RunAt="server" /> < asp:Button Text= " = " OnClick = " OnAdd " RunAt= "server" /> < asp:Label ID= "z" RunAt="server" /> </form> </body> </html> <script language= "C#" runat="server"> void OnAdd (Object sender, EventArgs e) { Int32 a = Convert.ToInt32(x.Text); Int32 b = Convert.ToInt32(y.Text); z.Text = (a + b).ToString(); } </script> Default.aspx.cs Another possible way
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen 2 What You Can View in the Browser? You can only view html file when you use View Source Command to view .aspx file -- an html file will be generated : <html> <head><title>Server Side Script</title></head> <body> <form name="ctl01" method="post" action="Default.aspx" id="ctl01"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUK </div> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" </div> <input name="x" type="text" id="x" /> + <input name="y" type="text" id="y" /> <input type="submit" name="ctl03" value=" = " /> <span id="z"></span> </form> </body> </html> This approach is similar to abstract data type/class: Data are private, and has to be accessed via a method.
Background image of page 2
Y. Chen 3 Adding exception handler in the .aspx File <script language= "C#" runat="server"> void OnAdd (Object sender, EventArgs e) { try { Int32 a = Convert.ToInt32(x.Text); Int32 b = Convert.ToInt32(y.Text); z.Text = (a + b).ToString(); } catch (FormatException) { z.Text = "Please enter integers only"; } } </script> In the previous form, if a noninteger is entered, the form will return an “ uncaught exception ”. In aspx, one can add an exception handler to catch the error:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen <html> </html> Different Web-based Computing Models 4 <html> </html> Client browser Server Processing Pure HTML forms Scripting HTML with embedded scripting <% Page Language <!DOCTYPE html <html> </html> Run at Server ASPX forms <html> </html> Run at client ASPX.cs
Background image of page 4
Y. Chen Example: AJAX Web Control 5 Label Button
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen Example: AJAX Web Controls 6 What control does the form belong to? Server control or user control? Web control or html control?
Background image of page 6
Y. Chen Using Web Controls to Display XML File <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Display XML File</title> </head> <body> <form id="form1" runat="server"> <div> </div> < asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile=" http://asusrl.eas.asu.edu/share/services/xml/Courses.xml " XPath="/Courses/Course/*"></asp:XmlDataSource> < asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1"> </asp:GridView> < asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1"> </asp:TreeView> </form> </body> </html> 7 asp:XmlDataSource asp:GridView asp:TreeView XML
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Y. Chen GridView and TreeView Web Controls 8 < asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource1"> </asp:GridView> Display the attributes at the top level of the tree < asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1"> </asp:TreeView> Display the element names of the XML file
Background image of page 8
Y. Chen Using DataBinding to Display Contents <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://asusrl.eas.asu.edu/share/services/xml/Courses.xml"
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 36

L19 - 5. Web Application Controls - 1 Server-Side Scripting...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online