views:

13

answers:

1

Hello, this question should be fairly basic. I want to control the flow of an ASP.NET page -- if a certain condition is met, I want to write out an error message and stop drawing the page. However, I also want ASP.NET to output correct HTML (i.e. not cut off in the middle). Right now I am doing this:

   if (condition != what-i-want) {
     Label_Error.Text = "Sorry, you messed up";
     return;
   }

And the problem with that snippet is that ASP.NET draws the rest of the defined page without cutting off after the error. I really don't want to make the whole page Visible = False and then undo it when someone is authenticated.

Is there some good way to do this? I have tried Response.End() but that doesn't output clean HTML (or anything actually, since I'm checking in Page_Load). I've had similar experiences with Response.Close(), et al.

Thanks.

+1  A: 

Cleanest way would be to create another page that gives message to the user about issues and then use server.transfer (or response.redirect) to transfer control to that page.

Yet another way would be to include entire page content in a panel (or panel) apart from stuff that you want user to see and then turn visibility off for the panel for not to show page content - but mind you, page life cycle would not stop; its just that the content within the panel won't be visible.

VinayC
Thanks, the redirect is the best idea I think.
cookiecaper