Reputation: 940
I want to pass some fields (for example like name information) into a form. I may not be the developer of this form though, so I am not sure how the page load or query strings are handled.
By doing some looking around, some web forms you can call text fields by their name
attribute, and automatically set those fields. For example, SO does this. If you go to https://stackoverflow.com/questions/ask?title=THISISMYTITLE, the first field (the title field) will be filled out with THISISMYTITLE.
Another great example is redmine. In that case, I can set any one of the fields (even custom ones) to values through the query string.
Finally, there are tools like 1Password that do something like this on the Mac and Windows - where it stores passwords in a local database. You can have it launch your browser though, and place in the content.
For some reason, when I try to pass querystrings like this to some asp.net web apps I developed, the Page Load method seems to pass them by. It knows they are there (I can see them in the Request.QueryString object), but it doesn't fill out the fields.
Is there a reliable way to do this, without having to ask the developer to update code? Why do some web pages allow this, and others don't? It does not seem to relate to the browser either - IE and Chrome both behaved the same way.
Note - This is for me, passing fields to any arbitrary webpage by using query strings or something similar. This is not for accessing the fields on the web page itself.
Upvotes: 5
Views: 7334
Reputation: 63962
This doesn't happen automatically, you must explicitly set the values in your form reading the parameters in the QueryString
. If SO and other websites seem to do this is because their code is looking for these parameters in the URL and populating the appropriate elements in the form.
Something like:
txtTitle.Text = Request.QueryString["Title"];
And so on...
Upvotes: 3