0

I have my query string down, and have verified that all values are being passed as they should be. Even if you look in the address bar it shows the appropriate values, but they are not being written to the page itself.

string pagetoload = "www.nonono12323hamarabi2323.html";
string bld = "FranklinJonesSmith";
Response.Redirect(pagetoload+"?BuildingName="+bld);

And this is the html for the field buildingname

<div style="width: 10px;"></div>
<input id="BuildingName" name="BuildingName" maxlength="255" type="text" style="width:240px;">

EDIT
and if I look in the address bar when the page loads it shows the correct value that I am trying to pass. The address bar reads:

www.nonono12323hamarabi2323.html?BuildingName=FranklinJonesSmith

EDIT 2
Thanks to @RJ Cuthbertson I now have a better understanding and realize that simplay passing the querystring to the page does not populate the textboxes themselves.

I am using webforms and am launching an order page using Response.Redirect so I do not have a way of accessing the C# Page_Load Event to do something like

BuildingName.Text=Request.QueryString["bld"];

So am I safe to say I need to research the JavaScrip methods mentioned below?

Simon Paris
  • 139
  • 1
  • 2
  • 13
  • 1
    Query string arguments don't automagically map to inputs on the page, you have to set the value of the input. – RJ Cuthbertson Oct 14 '15 at 19:41
  • @RJCuthbertson - isn't BuildingName the input that I need the value FranklinJonesSmith mapped to? – Simon Paris Oct 14 '15 at 19:42
  • 1
    How are you trying to set the value of the input? Are you trying to do it server-side or client-side? – RJ Cuthbertson Oct 14 '15 at 19:44
  • @RJCuthbertson - Either way will suffice. I just need to be able to click the button and the page load with the values being passed to it already populated. – Simon Paris Oct 14 '15 at 19:45
  • 1
    @SimonParis: Regarding your **Edit 2**: Why would `Page_Load` not be triggered? Is the redirect to a static page (i.e. html)? – Sani Huttunen Oct 14 '15 at 19:59
  • You probably aren't hitting Page_Load due to caching. A redirect should still trigger that event. See http://codeverge.com/asp.net.web-forms/page_load-not-firing-after-response.redirec/400354 – RJ Cuthbertson Oct 14 '15 at 19:59
  • @SaniHuttunen - Yes, the end of the page I am launching is .html is that what you are asking? – Simon Paris Oct 14 '15 at 20:01
  • 1
    @SimonParis: Yes that was what I was asking. Then the solution is to use javascript to get the values from the querystring and populate the controls. – Sani Huttunen Oct 14 '15 at 20:02

1 Answers1

1

Query string arguments are a way to pass data in your URL, but they don't automatically map their values to elements in the DOM.

If you're trying to do this client-side, with JavaScript you can get the query string from the location.search property.

To parse the query string, there are plenty of implementations on the web and on StackOverflow.

Then you'll need to set the value to your input control:

document.getElementById('BuildingName').value = yourVariableWithTheValueFromTheQueryString;
Community
  • 1
  • 1
RJ Cuthbertson
  • 1,458
  • 1
  • 20
  • 36