2

I am developing a website using asp.net c# and I want to put a form inside the page. Now as aspx pages have the form tag I do not want to nest another form inside this as it will invalidate my html. But I need this form to use GET rather than POST. I know I can change the postback url in the asp:button. Can this be done without using logic in the codbehind?

  1. Change the method to GET just for this form not every thing on the page
  2. change the target to _blank if possible.

Example in html of what I want.

<form action="http://maps.google.co.uk/maps" method="get">
<p><label for="saddr">Your postcode</label>
<input type="text" name="saddr" id="saddr" value="" />
<input type="submit" value="Go" />
<input type="hidden" name="daddr" value="[destination]" />
<input type="hidden" name="hl" value="en" /></p>
</form>
Luke Wilkinson
  • 439
  • 8
  • 17

2 Answers2

0

you can use jquery to accomplish this

$(document).ready(function() {
 $("#buttonId").click(function() {
   $("#formId").attr("method", "get");
 });
});

the above snippet, fires when the button with id 'buttonId' is clicked. it changes the method attribute of the form with id 'formId'

Jason
  • 15,915
  • 3
  • 48
  • 72
0

You can have multiple forms in an html. ASP.NET page also supports multiple form tags, however only one of then can be server side form (runat="server").

So I will suggest that you add another form tag within your page - some thing like

...
<body>
  <form runat="server">
    ... server controls etc

  </form>
  <!-- your form -->
  <form action="http://maps.google.co.uk/maps" method="get">
    <p><label for="saddr">Your postcode</label>
    <input type="text" name="saddr" id="saddr" value="" />
    <input type="submit" value="Go" />
    <input type="hidden" name="daddr" value="[destination]" />
    <input type="hidden" name="hl" value="en" /></p>
  </form>
</body>
</html>

Note that you cannot put any server side control in your html tag. So you have to use html controls and manage them within page code using Request object.

VinayC
  • 47,395
  • 5
  • 59
  • 72