Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 10th, 2006, 10:55 AM
Authorized User
 
Join Date: Mar 2006
Location: Pune, Maharashatra, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Response.Redirect in c# class.

hi,
I have one class library project created, there is one class BaseUIController in that, I want to write Navigate() method in the class would work as good as Response.Redirect("URL")
Function declaration is:
public void NavigatePage(string URL)
{

}

Please tell me how can I implement it, because System.Web.UI is not avaliabe in class library type projects, so I can'nt use Response.Redirect(URL).
Please guide me.

Thanks is advance,
manish

Reply With Quote
  #2 (permalink)  
Old May 10th, 2006, 12:28 PM
Imar's Avatar
Wrox Author
Points: 65,681, Level: 100
Points: 65,681, Level: 100 Points: 65,681, Level: 100 Points: 65,681, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,966
Thanks: 64
Thanked 1,349 Times in 1,329 Posts
Default

Hi manish,

From a good design perspective, you should let the class library simply return a value that you use to determine where to redirect to in the presentation layer (the .aspx pages). By letting the class library redirect users, you tie it to a web application, which limits its reuse possibilities.

That said, you can add a reference to System.Web in your class library. Then you access objects like Response and Session in the class library like this:

System.Web.HttpContext.Current.Response.Redirect(" SomePage.aspx");

Note that this method will fail when it's accessed from outside a Web app (e.g. a Console app, Windows Forms etc)

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #3 (permalink)  
Old May 12th, 2006, 01:20 AM
Authorized User
 
Join Date: Mar 2006
Location: Pune, Maharashatra, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar!
-Manish

Reply With Quote
  #4 (permalink)  
Old October 30th, 2007, 05:33 AM
Registered User
 
Join Date: Oct 2007
Location: Bangalore, Karnataka, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
I tried using the system.web.httpcontext.current.response.redirect(" mypage.aspx"); in the class library... but in runtime, its specifying that the object is null and not set to an instance. any ideas??? what do i need to do as alternative.

thanx in advance. please reply asap...
RO
Reply With Quote
  #5 (permalink)  
Old October 30th, 2007, 03:53 PM
Imar's Avatar
Wrox Author
Points: 65,681, Level: 100
Points: 65,681, Level: 100 Points: 65,681, Level: 100 Points: 65,681, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,966
Thanks: 64
Thanked 1,349 Times in 1,329 Posts
Default

Hi there,

Can you show us your exact code and explain where it is being called?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #6 (permalink)  
Old February 11th, 2011, 03:29 PM
Registered User
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have the same issue as Red_October. I have a button and the code behind for the button is
HttpContext.Current.Response.Redirect("URL", false);
when click on the button, system give this error "Object reference not set to an instance of an object"

can anyone help me with this issue?
Reply With Quote
  #7 (permalink)  
Old February 12th, 2011, 04:41 AM
Imar's Avatar
Wrox Author
Points: 65,681, Level: 100
Points: 65,681, Level: 100 Points: 65,681, Level: 100 Points: 65,681, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,966
Thanks: 64
Thanked 1,349 Times in 1,329 Posts
Default

If you have the same issue as Red_October, the same response to the question applies ;-)

Quote:
Can you show us your exact code and explain where it is being called?
That is, explain the setup of your site / application, and show us the code for the page.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #8 (permalink)  
Old February 12th, 2011, 08:20 AM
Registered User
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a SharePoint site http://moss2007
I have a page on this site call ViewMyStaff.aspx (this is just a blank webpart page). when the user clicks on the button, system should take me to http://moss2007/Pages/ViewMyStaff.aspx page. The form library is in the same site collection as this page

httpcontext.current.response.redirect("http://moss2007/pages/ViewMyStaff.aspx", false)

Thanks in advance,
Reply With Quote
  #9 (permalink)  
Old February 13th, 2011, 09:26 AM
Imar's Avatar
Wrox Author
Points: 65,681, Level: 100
Points: 65,681, Level: 100 Points: 65,681, Level: 100 Points: 65,681, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,966
Thanks: 64
Thanked 1,349 Times in 1,329 Posts
Default

You may be better off posting this in a SharePoint category, and provide more code that demonstrates the problem.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #10 (permalink)  
Old February 16th, 2012, 12:13 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I have the same problem, in my case I am trying to do the redirect from a VB.Net module, here is the code:

Code:
 Public Sub ShowEPSErrorPage(Optional ByVal strErrorMessage As String = gGenericErrorMessage,Optional ByVal strDetailedMessage As String = "")

            HttpContext.Current.Session.Add(ErrorPage.SA_ERR_MESSAGE, strErrorMessage)
            HttpContext.Current.Session.Add(ErrorPage.SA_DETAILS_MESSAGE, strDetailedMessage)
            HttpContext.Current.Response.Redirect("/ErrorPage.aspx")
End Sub
I have System.Web imported and as I said this is in a module which is part of my web application.

When I debug this, sometimes the debugger will be able to evaluate HttpContext.Current and sometimes it would tell me "Unable to evaluate expression", but either way this throws an exception with a message "Unable to evaluate expression"!! the path is proper so I am not sure what am I missing or doing wrong?

Thanks
Jafar
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
response.redirect sarah lee ASP.NET 1.0 and 1.1 Basics 1 October 27th, 2006 08:57 AM
response.redirect ava_h .NET Framework 2.0 0 October 18th, 2006 10:21 PM
Response.Redirect + Javascript jfergy Classic ASP Basics 2 January 17th, 2006 08:17 PM
response.redirect crmpicco Classic ASP Basics 3 February 9th, 2005 12:50 AM
Response.Redirect dhborchardt Classic ASP Basics 4 June 16th, 2003 05:56 AM



All times are GMT -4. The time now is 04:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.