redirecting from a vb class

  • Thread starter Thread starter MattB
  • Start date Start date
M

MattB

I have what I hope is a simple problem. My ASP.net (1.1) application has
a vb class and I want to redirect from code in that class.
I figured out that plain old Response.Redirect() doesn't work from the
class like it does from codebehind by doing the following:

Dim Response As System.Web.HttpResponse
Response.Redirect("StartPage.aspx")

But when it executes I get a runtime error: Object not set to an
instance of an object.

What am I missing here? Thanks!

Matt
 
Right, because you declared the variable. But you never set it to anything.
It can't just get some sort of value on its own.

You can do something like:
System.Web.HttpContext.Current.Response.Redirect("mypage.aspx")

Of course if there is no current web response, this will throw an exception.
 
I suppose you call the method of the class from a .NET page. Hence you can
pass the page’s Response to the method (or class), then use the Response’s
Redirect method:

Class YourClass()
‘ Other code
Public Sub Redirect(ByVal Response As System.Web.HttpResponse)
‘
Response.Redirect(“StartPage.aspxâ€)
End Sub
‘ Other methods

End Class

‘ in Page code
Dim obj As New YourClass()
obj.Redirect(Me.Response)

HTH

Elton Wang
 
Back
Top