ASP.NET how you read the data sent in the Query String
A. Add Existing Item and use the Data.aspx from Assignment 4
B. Place a label called lblError below the listbox.
2. Edit the connect string and change add x to the end of the password (to make it fail).
A. Check the web.config and confirm that customErrors mode="RemoteOnly"
B. Run and Print default error page
3. Edit the Web.Config file
A. Change customErrors mode="On" and run again.
B. Print the default generic error message
4. Create a new generic error message page called genericerror.htm
A. Include a message that says “Sorry we are down, check back later”
B. Add an appropriate image (check images.google.com)
1. Copy to images folder then drag onto page.
C. Modify the web config to show this page when mode="On".
1. Print web config
D. Trigger error to test and print the results
5. In the button click event….
A. Wrap up the data access code in a Try …Catch block
1. Display the expection.message in lblError
2. Exit sub within the Catch
B. Place the following code in the Finally block
da.Dispose()
ds.Dispose()
Print your code
C. Screen print showing results of the message in lblError
6. Remove the Finally clause and dispose methods
7. Create a Private Sub ByteError as follows
Dim x As Byte
x = 230
x = x + x
…
A. Call ByteError from the button click event right after the Try statement
B. Print the resulting message as displayed in lblError.
1. The error should have been passed back to the calling sub with the error handling code.
8. Add a “Catch ex as …..” to the Try block ………
A. Capture the specific System.OverflowException error
B. Set the label to “Bad Math” and exit
C. Print
9. Add a new class Called MyWebBase to override the Web Page Class
A. Inherit the System Web page base class
B. Override the On Error event and PageLoad as shown
1. There is considerable work here so plan accordingly.
C. Create a new MyErrPage.aspx that will display information you send it about the error
1. Pass the error information in the QueryString as show below.
2. Error Message, Name of page, date/time
D. See attached for my code to do this
10. Modify Error trap as follows:
A. On the line prior to lblError.text = … in the trap insert
1. Throw ex
2. This will propagate the error to the base class
B. Print all code and running example to show it works
11. FROM BOOK…Do Chapter 13
A. Print code and completed Products page.
12. Add Existing Customers Page from Assignment 4
13. Create a Class Called DataSQL with Public Shared Function CS() As String
A. Replace all connect strings with references to this function
14. Add Freight column to the grid
15. Add a label that says “Sum of Freight for current customer is “
A. Update this label when customer changes.
1. Use cm.ExecuteScalar
16. Add a button “Add 5 cents” (example not shown)
A. Create a sub that updates the current customer’s freight by adding .05
1. strSQL = "Update Orders set Freight = Freight + .05 where CustomerID = '" & ddlCustomers.SelectedItem.Value & "'"
B. Call this sub from the button click
C. Then reload the grid and update the Sum Label.
17. Implement Error trapping of your choice for all data access
18. Sample Code for MyBase
Imports System.Diagnostics
Public Class WebBase
Inherits System.Web.UI.Page
Private mstrPageName As String
Protected Overrides Sub OnError(ByVal e As System.EventArgs)
Dim exp As System.Exception = Server.GetLastError
Dim strCurErr As String
Dim dteCurDate As DateTime
strCurErr = String.Format("Error={0}&Page={1}&Time={2}", Server.UrlEncode(exp.Message), Server.UrlEncode(mstrPageName), Server.UrlEncode(dteCurDate.Now.ToString))
Response.Redirect("ErrorPage.aspx?" & strCurErr)
End Sub
Sub SetPageName()
If mstrPageName = "" Then
mstrPageName = Replace(Page.ToString, "ASP.", "")
mstrPageName = Replace(mstrPageName, "_aspx", ".aspx")
End If
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Call SetPageName()
MyBase.OnLoad(e)
End Sub
End Class
This is how you read the data sent in the Query String
ErrorPage.aspx
txtError.Text = Request.QueryString("Error")
ditto for other two params
B. Place a label called lblError below the listbox.
2. Edit the connect string and change add x to the end of the password (to make it fail).
A. Check the web.config and confirm that customErrors mode="RemoteOnly"
B. Run and Print default error page
3. Edit the Web.Config file
A. Change customErrors mode="On" and run again.
B. Print the default generic error message
4. Create a new generic error message page called genericerror.htm
A. Include a message that says “Sorry we are down, check back later”
B. Add an appropriate image (check images.google.com)
1. Copy to images folder then drag onto page.
C. Modify the web config to show this page when mode="On".
1. Print web config
D. Trigger error to test and print the results
5. In the button click event….
A. Wrap up the data access code in a Try …Catch block
1. Display the expection.message in lblError
2. Exit sub within the Catch
B. Place the following code in the Finally block
da.Dispose()
ds.Dispose()
Print your code
C. Screen print showing results of the message in lblError
6. Remove the Finally clause and dispose methods
7. Create a Private Sub ByteError as follows
Dim x As Byte
x = 230
x = x + x
…
A. Call ByteError from the button click event right after the Try statement
B. Print the resulting message as displayed in lblError.
1. The error should have been passed back to the calling sub with the error handling code.
8. Add a “Catch ex as …..” to the Try block ………
A. Capture the specific System.OverflowException error
B. Set the label to “Bad Math” and exit
C. Print
9. Add a new class Called MyWebBase to override the Web Page Class
A. Inherit the System Web page base class
B. Override the On Error event and PageLoad as shown
1. There is considerable work here so plan accordingly.
C. Create a new MyErrPage.aspx that will display information you send it about the error
1. Pass the error information in the QueryString as show below.
2. Error Message, Name of page, date/time
D. See attached for my code to do this
10. Modify Error trap as follows:
A. On the line prior to lblError.text = … in the trap insert
1. Throw ex
2. This will propagate the error to the base class
B. Print all code and running example to show it works
11. FROM BOOK…Do Chapter 13
A. Print code and completed Products page.
12. Add Existing Customers Page from Assignment 4
13. Create a Class Called DataSQL with Public Shared Function CS() As String
A. Replace all connect strings with references to this function
14. Add Freight column to the grid
15. Add a label that says “Sum of Freight for current customer is “
A. Update this label when customer changes.
1. Use cm.ExecuteScalar
16. Add a button “Add 5 cents” (example not shown)
A. Create a sub that updates the current customer’s freight by adding .05
1. strSQL = "Update Orders set Freight = Freight + .05 where CustomerID = '" & ddlCustomers.SelectedItem.Value & "'"
B. Call this sub from the button click
C. Then reload the grid and update the Sum Label.
17. Implement Error trapping of your choice for all data access
18. Sample Code for MyBase
Imports System.Diagnostics
Public Class WebBase
Inherits System.Web.UI.Page
Private mstrPageName As String
Protected Overrides Sub OnError(ByVal e As System.EventArgs)
Dim exp As System.Exception = Server.GetLastError
Dim strCurErr As String
Dim dteCurDate As DateTime
strCurErr = String.Format("Error={0}&Page={1}&Time={2}", Server.UrlEncode(exp.Message), Server.UrlEncode(mstrPageName), Server.UrlEncode(dteCurDate.Now.ToString))
Response.Redirect("ErrorPage.aspx?" & strCurErr)
End Sub
Sub SetPageName()
If mstrPageName = "" Then
mstrPageName = Replace(Page.ToString, "ASP.", "")
mstrPageName = Replace(mstrPageName, "_aspx", ".aspx")
End If
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Call SetPageName()
MyBase.OnLoad(e)
End Sub
End Class
This is how you read the data sent in the Query String
ErrorPage.aspx
txtError.Text = Request.QueryString("Error")
ditto for other two params
<< Home