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?

8
  • 1
    Query string arguments don't automagically map to inputs on the page, you have to set the value of the input. Commented Oct 14, 2015 at 19:41
  • @RJCuthbertson - isn't BuildingName the input that I need the value FranklinJonesSmith mapped to? Commented Oct 14, 2015 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? Commented Oct 14, 2015 at 19:44
  • 1
    @SimonParis: Regarding your Edit 2: Why would Page_Load not be triggered? Is the redirect to a static page (i.e. html)? Commented Oct 14, 2015 at 19:59
  • 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. Commented Oct 14, 2015 at 20:02

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

3 Comments

using webforms. See my edit #2, I now have somewhat of a better understanding of the issue.
Cuthebertson - where would I place the JavaScript piece to perform this?
At the bottom of the page in a script element just inside the closing tag of the body element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.