Sending exceptions to a TextBox

J

Jerry J

I am using page level exceptions on some of my WebForms.
In most cases I am handling the errors simply like this:

Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Error
Response.Write(Server.GetLastError().Message)
Server.ClearError()
End Sub


Instead of doing that I would like to send the error info
to a textbox that is on the current form. Somthing like
this:

Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Error
txtErrMsg.text = Server.GetLastError().Message
Server.ClearError()
End Sub


This doesn't work, the page displayed isalways just a
blank white page. Is there a way to do this?

Jerry J
 
P

power

I think you must use try...catch.
you can show exceptions on textbox of current page use
catch.like this:
public void YourFunctionOrEvent(YourParametersList){
try{
// your code..
}
catch(Excepion ex){
this.YourEcvepionText.Text = ex.Message;
}
}

Response.Write(Server.GetLastError().Message) is a new
instance of page so there isn't a textbox.

you can add a textbox in your every page,and then you let
your page accept a parmeter names err,and then you can
send a parameter to current page.for example:

// this page name is a.aspx,there is a textbox in it
named txtErrMsg.
protected void Page_Error(parametersList){
Response.Redirt
(this.page...+"@err="+Server.GetLastError().Message);
}

public void Page_Load(PrametersList){
// your code..
if(this.Param["err"] != null){
txtErrMsg.text = Server.GetLastError().Message
Server.ClearError()
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top