redirecting from a vb class

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
 
M

Marina

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

Guest

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
 

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

Similar Threads


Top