stop website from loading after a catch and show error. Inside a class
Hi,
I am having a problem with a Try and Catch in a Web Application, pretty much the problem is:
I have my function to open a port, if the reader is not connected then it will catch it but I am not sure on the following:
Showing the error in a label (when working from inside a class) and how to stop the WebApp from finishing loading so it doesn't load the rest of the code.
I can't use Java because of Users Requirements so this is why I am a bit stuck as MessageBox doesn't exist anymore.
Many Thanks
Kirtan PatelPosted Nov 30, 2009, 8:50 AM
so you can Call Redirect From Function Like Below if I call Function() from Page1 and Function Contain Redirect code.
and you need to add name space for Accessing Page Object
if my answer helps you then please check "Do you like this answer" check box please :)
using System.Web.UI;
Page1 Code
-------------------------
protected void Page_Load(object sender, EventArgs e)
{
try
{
}
catch
{
//Pass Page Object in function Parameter
Class1.Function(this.Page);
}
}
Class1 Code
----------------
public class Class1
{
public static void Function(Page p)
{
p.Response.Redirect("Error.aspx", true);
}
}
regorPosted Nov 30, 2009, 8:36 AM
Kirtan PatelPosted Nov 30, 2009, 7:05 AM
Simple Solution is When page generates Exception redirect it to Some Other Page that has Error Message in It .so after
Exception is generated user see the Error Message in Error.aspx :) like below Code .
if my answer helps you then please check "Do you like this answer check box :)
protected void Page_Load(object sender, EventArgs e)
{
try
{
//Your Code that Generates Exception
}catch
{
//Here Second parameter Force Page to Stop responding
// And redirect it To error Page
Response.Redirect("Error.aspx",true);
}
}
friend, if still have any confusion then free to ask :)