can a forms action url contain querystring values? [duplicate] - asp.net

This question already has answers here:
What happens if the action field in a <form> has parameters?
(4 answers)
Closed 2 years ago.
can a forms action url contain querystring values?

Yes
it can.
But
when method="get" then the querystring will be stripped out and replaced by the form input names/values (since the form controls are those that build the GET querystring).
<form method="get" action="?param=foo">
<input type="hidden" name="param" value="bar" />
</form>
will submit param=bar
To keep the value you should specify method="post" on the form.
<form method="post" action="?param=foo">
<input type="hidden" name="otherparam" value="bar" />
</form>
will submit param=foo&otherparam=bar
<form method="post" action="?param=foo">
<input type="hidden" name="param" value="bar" />
</form>
will submit param=foo&param=bar (so, depending on how you process the request, you could get either an array value or unexpected results).

Yes, it can.
(Keystrokes)

I've just checked using a reduced test case:
Form.htm that contains a form with an action of default.aspx?query=1 and a submit button.
default.aspx that contains code in Page_Load to write out Request.QueryString["query"]
The result I got when clicking on the button was a page that read:
1
So, the answer is yes.

Related

Is there a good way to pass both form information and URL parameters to server?

In my web forms project (a forum) I have a form that is accessed through a link from another page, a link which includes parameters. for example:
EditPost.aspx?mid=0
When the page is loaded, the form hasn't yet been submitted and Request.QueryString contains the URL parameters I loaded the page with. However, after I send the form, Request.QueryString conatins the values of the form fields. This is a problem because I need the URL parameters after the form is sent.
The question is, how do i make the page send me those URL parameter with the form information?
If I'm approaching this wrong, and I'm supposed to keep the URL parameters from when the page is first loaded, let me know how.
Thanks!
Edit:
<form action="" id="f_editComment" name="f_editThread" method="post" onsubmit="return true;">
<%=ThreadTitle %>
<textarea id="body" name="body" runat="server"></textarea>
<input type="submit" id="submit" name="submit" />
</form>

How to POST from WebForms to External URL and Supply Values from Server

Having lived in an MVC world for the last few years I just cannot get my head back into a WebForms world.
I have to try to integrate an external payment getway into a 4 step process. The last step involves POSTing some values to a given URL. This URL is expecting a preset list of values with predefined names (i.e. I cannot change what it is expecting).
The problem I am having is populating values gained from steps 1-3 on the form I want to post.
Let's say I need to send 3 values (there are more but the principle is the same):
- amount
- returnurl
- name
I could write a form along the lines of
<form action="http://url/goes/here">
<p>Please confirm the details below</p>
<asp:TextBox id="amount" runat="server" />
<asp:TextBox id="returnurl" runat="server" />
<asp:TextBox id="name" runat="server" />
<asp:Button id="submitme" />
</form>
And easily pre-populate the textboxes (or labels, or whatever I need) from the codebehind on PageLoad.
But then the values are submitted with prefixed with the 'ctl00$ContentBottom$WebFormControl$ctl00$' and so the external url throws it away and complains no values have been supplied. It sees 'ctl00$ContentBottom$WebFormControl$ctl00$amount' and not 'amount'.
Is there anyway I can amend the names of the values that are posted?
instead of amending the names of value you can add them in your aspx page as follows
<input type="hidden" name="billing_cust_name" value="<%=txtbox1.Text%>">
<input type="hidden" name="billing_cust_address" value="<%=txtbox2.Text%>" >
<input type="hidden" name="billing_cust_email" value="<%=txtbox3.Text%>">
<input type="hidden" name="billing_cust_notes" value="<%=txtbox4.Text%>">
When the form is ready to be posted change the value and then post.

What happens to an "input" on "submit"? And how can that be done by ASP.Net? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Read Post Data submitted to ASP.Net Form
I have a google checkout "buy now" button, and am trying to add dynamically created content to send when it's clicked. Using the original html is proving a bit difficult so I want to create an ASP.Net ImageButton Instead of that.
I've succeeded in creating the button with the right image, and hooking it up to an event handler in the codebehind.
However, I'm not sure what exactly happens when the original button is clicked, in order to try and emulate it in the new ImageButton.
The original code is:
<form action="https://sandbox.google.com/checkout/..." id="Form1" method="post" name="..." target="_top">
<input name="item_name_1" type="hidden" value="..." />
...
<input alt="" src="https://sandbox.google.com/checkout/buttons/buy.gif?merchant_id=..." type="image" />
</form>
And I want to place a dynamically created item_name_1.
What do I have to do in the Button1_Click method for that?
The short, concise and usefull version:
Html:
<form id="__parent" action="..." method="post" runat="server">
<input id="__child0" name="type" type="hidden" value="button" runat="server" />
<input id="__child1" name="name" type="hidden" value="teh_button" runat="server" />
<input id="__child2" name="value" type="hidden" value="Hello?" runat="server" />
</form>
tehfile.cs:
<%# Page Language="C#" CodeFile="tehfile.cs" %>
String
_type = __child0.Value,
_name = __child1.Value,
_value = __child2.Value,
_element = String.Format(
"<{0} {1}=\"{2}\" {3}=\"{4}\" {5}=\"{6}\" />",
"input",
"type", _type,
"name", _name,
"value", _value );
Literal _lit = new Literal( );
_lit.Text = _element;
__parent.AddControl( _lit );
To post that data to another server on the ASP.NET server-side, you are going to need to use something like the WebRequest class.
Or also in order to post a form, you can use a remote post class like any of the ones here: Remote HTTP Post with C# , the answer by #BobbyShaftoe is the one i've used in many projects.
Same question/POST here. I would have commented instead of answered, but seems this is a better/formatted way to get to bottom of it all:
In your comment to #MarcusHansson's answer:
I fail to see how this addresses the question of how to use the codebehind to send the information
You are mixing server side with client side submission methods.
If you want to submit using "code behind" you must implement server-to-server HTTP Post. In the context of Google Checkout, I've provided that link in your other post.
Your client side is using an HTML FORM which in, and of itself is how you "send the data". You can try all sorts of client-side submission processes, but at the end of the day, it is a client-side (Javascript) method.
What is "dynamic" about your buy now button? It's meant for a single item (at a time) purchase. Why can't you construct all the variables you need at the same time you create the button? What are you adding (that requires another redirect or postback)?

Posting data to ASP.NET application

I have an application into which I wish to allow users to enter login details for their own websites. One of authentication methods is 'forms'. The way I had envisaged it working, is the users entering the method & action of their login form, and the name/value for each credential item, e.g. one for username, one for password. My application would then post this data in order to simulate a login, get the returned authentication cookie and be able to work on their site as if logged in.
In principle, this sounded like a reasonable kind of thing to do. However, as I'm sure you're aware, ASP.NET has a lot of inputs, and also hidden ones, e.g. __VIEWSTATE, which are all always posted back to the server whenever the ASP.NET form is submitted e.g. when a real user logs in. When my app tries to login however, it doesn't have the full list of inputs on that page, and their values, e.g. the always changing __VIEWSTATE.
My question: is there a way to post data to an ASPX page, posting only certain inputs, and excluding others, e.g. __VIEWSTATE?
If the page were, say, PHP it would probably look like this:
Ex. 1:
...
<div id="header">
<form action="search.php" action="POST">
<div id="search">
<input type="text" name="query" id="SearchQueryText" value="Search query" />
<input type="button" name=submit" id="SearchSubmitButton" value="Search!" />
</div>
</form>
<form action="login.php" action="POST">
<input type="text" name="uname" id="Username" value="Username" />
<input type="text" name="passwd" id="Password" value="Password" />
<input type="button" name=submit" id="LoginSubmitButton" value="Login" />
</form>
...
</div>
...
in ASP.NET Web Forms, however, through the use of server controls, it'd probably look like:
Ex. 2:
...
<body>
<form name="AspNetForm" method="post" action="/Products/SomethingOrOther.aspx" id="Form" enctype="multipart/form-data">
<div id="header">
<div id="search">
<input type="text id="ctl00$SearchComponent$SearchBox" name="ctl00$SearchComponent$SearchBox" value="Search query" />
<input type="submit" id="ctl00$SearchComponent$SearchSubmit" name="ctl00$SearchComponent$SearchSubmit" value="Search!">
</div>
<div id="login">
<input type="text id="ctl00$LoginComponent$Username" name="ctl00$LoginComponent$Username" value="Username" />
<input type="text" id="ctl00$LoginComponent$Password" name="ctl00$LoginComponent$Password" value="Password">
<input type="submit" id="ctl00$LoginComponent$LoginSubmit" name="ctl00$LoginComponent$LoginSubmit" value="Login">
</div>
</div>
...
</form>
</body>
...
With example 1, submitting the login form is a simple case of POSTing uname=something&passwd=somethingelse to login.php, however, in ASP.NET, because all inputs are wrapped in a 'global' <form>, to submit the login inputs, you have to submit the global form, and therefore all the inputs.
So what I'm after, is a way to submit only certain inputs in that global form, e.g. not __VIEWSTATE, which we can't know without probing the page beforehand.
You can use AJAX to post back the values to a specific page. In general, Web Forms is designed to post back all data on the page when you trigger a server side event. You then choose which elements/values to use in your code. If you don't want to use view state on a element, you can disable it (e.g. EnableViewState=False).
You can use asp.net page same as asp classic.
In html action you can put the aspx page from and then you have to take that.
then you can use request object of asp.net to retrive data from form. Same you can create a html form in string and put that via putting it into panel control.
Then you can asp.net button as submit button.

ASP.Net using multiple form tag and post them to another page

I don't know it's even possible but I try to achieve to post data from one page to another using the second form.
The problem is I need a form tag for the user interface containing callback panels etc. I want to put a second form with some hidden-field:
<form id="postForm" method="post" action="target.aspx">
<input type="hidden" id="id" />
</form>
I submit the form from javascript with jquery:
$("#id").val(id);
$("#postForm").submit();
Is there a way access the value of the hidden field on the target page?
You should give the hidden field a name attribute:
<input type="hidden" id="id" name="id" />
You'll then be able to use Request.Form in your target page to access the posted data:
string postedId = Request.Form["id"];

Resources