How can I stop ASPX file rendering in Page_Load event?

  • Thread starter Thread starter A.M-SG
  • Start date Start date
A

A.M-SG

Hi,

Within my code behind's Page_Load event, I need to prevent the aspx contents
be rendered.

I tried to use Response.End() , but ASP.NET gives me
"System.Threading.ThreadAbortException" exception. I also tried

Response.OutputStream.Flush();
Response.OutputStream.Close();

Or

Response.Flush();
Response.Close();

They do not stop ASP.NET to render the rest of contents.

How can I stop ASP.NET to rendering the rest of contents?

Thank you,
Alan
 
I think that exception is normal, no? Note: ThreadAbortException cannot be
caught.

You get that also if you try and do a response.redirect.
 
Hi,
Within my code behind's Page_Load event, I need to prevent the aspx contents
be rendered.

I tried to use Response.End() , but ASP.NET gives me
"System.Threading.ThreadAbortException" exception. I also tried

Response.OutputStream.Flush();
Response.OutputStream.Close();

Or

Response.Flush();
Response.Close();

They do not stop ASP.NET to render the rest of contents.

How can I stop ASP.NET to rendering the rest of contents?

Thank you,
Alan

For a less drastic way, try to set the controls to Visible=false.
Or even "this.Visible = false;" to hide the complete control.

Hans Kesting
 
Hi,

Within my code behind's Page_Load event, I need to prevent the aspx contents
be rendered.

I tried to use Response.End() , but ASP.NET gives me
"System.Threading.ThreadAbortException" exception. I also tried

Response.OutputStream.Flush();
Response.OutputStream.Close();

Or

Response.Flush();
Response.Close();

They do not stop ASP.NET to render the rest of contents.

How can I stop ASP.NET to rendering the rest of contents?

Thank you,
Alan
Explain a little more of what you are doing and why you want to stop
rendering.
If you must try overriding the Render method - don't invoke the base class
Render and don't output anything.
 
Thank you very much guys.

Now in know that the exception is normal and I can cach/ignore it.

this.Visible = false and also overriding Render methods also are good idea.

Thank you again,
Alan
 
Don't bother trying to catch it. That exception type is very perculiar. You
cannot catch it at all.

Greg
 
Back
Top