Response Redirect

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I instantiate a new class from a web page, can that class call the
Response.Redirect? Do I need to pass the page object into this class as part
of that classes constructor? What library do I need to add a reference to or
what using statement should I use to have access to the Response object?
 
You can pass the Page object into the class (via a contsutrctor, a property
or a parameter to a function). It would make more sense to pass the
Resposne object directly, but it's the same thing.

As an alternative, you could use

HttpContext.Current.Response.Redirect("xxx")

you'll need to have system.web referenced

Note that if your class is used outside of a web application,
HttpContext.Current will be null and the above line will get you a null
reference. If this is a business class, you'll need to write defensively,
and even ask yourself how such presentation stuff ever got there. If it's
considered a presentation class or a presentation support, no problem having
that dependency built in, in my opinion.

Karl
 
As long as you have access to Response object you can call it.

You can access it using HttpContext.Curent.Response

George.

If I instantiate a new class from a web page, can that class call the
Response.Redirect? Do I need to pass the page object into this class as part
of that classes constructor? What library do I need to add a reference to or
what using statement should I use to have access to the Response object?
 

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

Back
Top