I want to pass a query in a hidden filed from 1 page to another by querystring. Can anyone help me out with the logic?
相关问题
- How to access request query string parameters in j
- Querystring Issue on C# with special characters
- PHP: How to check if query string or POST vars con
- PHP: How to check total no. parameters in URL?
- .htaccess rewrite URL with a question mark “?” onl
相关文章
- Encrypt Or Hide QueryString at Asp.net website usi
- Whats the quickest way to dedupe a querystring in
- How can I turn off QSA? (query string append)
- how to pass data in an hidden field from one jsp p
- Is question mark in URL part of query string?
- how to remove characters from a string in sqlite3
- Alternative to sending comma separated parameter b
- javascript get querystring [duplicate]
If you are using aspx, you do not need to parse the query string using JavaScript, or even use
<form method="GET" ...>
. You can POST the form to the secondaspx
page, extract the value in C# or VB then write it to a client-side JavaScript variable. Something like this:page1.aspx:
page2.aspx:
The above would set the client-side JavaScript variable called
myHiddenClientValue
to a value of'myHiddenServerValue'
after the POST.This can be a bad idea because if
myHiddenServerField
contains single quotes or a newline character, then setting it on the client inpage2.aspx
can fail. Embedding ASP.NET Server Variables in Client JavaScript and Embedding ASP.NET Server Variables in Client JavaScript, Part 2 deals with specifically these issues, and solves them with a server-side class that ensures values being written to the client are escaped correctly.Assuming you mean hidden in the HTML form sense, your field will be submitted along with all the other fields when the form is submitted. If you are submitting via GET, then your "hidden" field will show up in plain text in the URL. If you don't want the data in the hidden field to be accessible to users, don't put an understandable value in that field.
You can easily submit a form on one page that points to another page using the
action
parameter. For instance, inside of page1.aspx put the following:Since you're using "GET" as the method instead of "POST", you could potentially use Javascript to parse the URL and get the value that was passed. Alternatively, you could use ASPX to store the value of the "username" field somewhere else on the page. I don't know ASPX (or ASP, or anything Microsoft really), but if you can find a way to output something like the following (and are using jQuery), it may do what you require. Honestly though, it sounds like you are going about something all wrong. Can you modify your question to be a bit more specific about what the general object is that you are attempting to accomplish?
If you use method="get" on an HTML form then any hidden inputs in that form will be converted to query parameters.
See also Jeremy Stein's answer.
It's worth taking the time to learn jQuery. It's not very complicated, and it makes writing javascript much easier. There are also many jQuery plugins, such as jquery.url.
Also, as other posters have suggested, you may not wish to put the hidden field's value in the query string if you care about it being displayed to the user. However, if the data is present in a hidden field it will always be possible for a user to find it if they care to look.
If you really do want to put the hidden field in the query string and then extract it via non-jQuery javascript:
hiddenFieldPage.aspx
This form will take the user to processingPage.aspx?datum=someValue when it is submitted. You could probably also just use an ordinary link if nothing else needs to be submitted at the same time.
or, inserting the value from code-behind:
processingPage.aspx
This script will pop-up an alert box with the value of "datum" from the URL - assuming the form's method is set to "GET":
If the form's method was set to "POST" (as it usually would be in ASP.NET), then "datum" won't be in the query string and you'll have to place it on the page again:
To retrieve the hidden value on the second page: