-2

I have the following code in the first page (Let's call it PageOne.aspx):

HyperLink link = null;
link.NavigateUrl = "http://" + Request.ServerVariables["http_host"] + ResolveUrl("~/") + "dynamicbannerLink.aspx";

The code sample above should trigger another aspx page called "dynamicbannerLink.aspx" once PageOne.aspx is done loading. The thing is I would like to return a string value from "dynamicbannerLink.aspx" through a Response method. Right now this is what I have in "dynamicbannerLink.aspx":

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("test.com");
}

The problem the code keeps crashing with "object not set to an instance of an object" error every time it tries to assign the navigation link in the first page, any ideas on what the problem may be or what other solution I can use?

Thank you.

EDIT:

For the record, for those who suggested that this question was asked somewhere else, no it was not, while I am getting a similar error message that message is quite vague and could happen in multiple places. If you read the question correctly you would understand that I wanted to return a value from another ASPX page. The error was just something that happened along the lines because I did something wrong.

I find it quite absurd that instead of reading the question properly, people choose to down-vote.

kv-prajapati
  • 90,019
  • 18
  • 141
  • 178
user2471103
  • 78
  • 2
  • 9
  • You want to do X but keep getting an error. The linked question shows how to fix the error you're getting. – TylerH Jul 23 '15 at 20:02

1 Answers1

3

You have to instantiate the HyperLink:

HyperLink link = new HyperLink();
kv-prajapati
  • 90,019
  • 18
  • 141
  • 178
  • 1
    Brilliant, can't believe I made such a rookie mistake. I have another question in addition to the above, currently the code segment makes the navigation link point todynamicbannerLink.aspx, but let's say I actually want it to point to test.com, what kind of Response type do I need to use? – user2471103 Jul 23 '15 at 02:14
  • You can set `link.NavigateUrl="http://www.test.com";` – kv-prajapati Jul 23 '15 at 05:41