Search code examples
c#asp.netserver.transfer

Whats the namespace of Server.Transfer method?


I get a red underline under the Server Class:

Server.Transfer("~/PostEdit.aspx");

The mistake is:

Cannot access a non-static member of outer type 'System.Web.UI.Page' via nested type 'AnswerQuestion.ThreadTable'

AnswerQuestion is the partial class and ThreadTable is a custom class that I made.


Solution

  • You are not inside the Page instance, so you don't have access to the Server property, which is a shortcut to the Server property in the HTTP context.

    Use the static Current property to get the context of the current page:

    HttpContext.Current.Server.Transfer("~/PostEdit.aspx");