How can I stop ASPX file rendering in Page_Load event?

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
 
G

Greg Burns

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

You get that also if you try and do a response.redirect.
 
H

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

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
 
I

intrader

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.
 
A

A.M-SG

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
 
G

Greg Burns

Don't bother trying to catch it. That exception type is very perculiar. You
cannot catch it at all.

Greg
 

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

Top