tags:

views:

212

answers:

4

Hi there.

I'm developing a website (ASP.NET Webform with C#) where I have a <button> element.

Here's the code snippet:

<a href="ThisPage.aspx" ID="myButtonID" runat="server">
    <button>Configure new trip</button>
</a>

When I use Firefox or Chrome, this code does a "GET" over this ThisPage.aspx. That's what I want to do, actually.

The question is that the same code does "POST" when I use Opera. Does anyone know what shall I do to make this button act the same way using Opera?

A: 

I'm guessing it's within a form tag?

If so, try setting the method of the form to "get".

Daniel Robinson
My form has other buttons that need to do "POST". Isn't there any way to order this button to make a "GET" instead?
XpiritO
You could not put your page in a giant form.
Breton
It is an ASP.NET application => page is one entire form and it is automatically POST
veggerby
@veggerby exactly
XpiritO
the problem is ASP.NET then. Stop using that.
Breton
Of course... I've been working in MVC so I forgot you couldn't change it.
Daniel Robinson
+5  A: 

Probably because FF/Chrome handles the click on the <a /> tag and Opera does it on the <button /> tag.

What you are looking for (I guess) is having a <a /> tag renderes as a button? In that case have a look at this for at good tutortial on how to style an <a /> tag like a button

What you are doing is to some extent similar to adding a textbox to an anchor tag, i.e. sematically wrong.

veggerby
I'll check that out. Thanks for your reply.
XpiritO
I've solved it using an <a> element instead of a <button>. Thanks for helping me clarifying this.
XpiritO
A: 

If you're not doing any AJAX operations, and clicking on the button is expected to navigate to 'ThisPage.aspx', then I'd consider styling the <a> element - as suggested by @veggerby - and removing the <button> </button> elements.

However, this could be confusing for the user, who might not expect a button within a form to be a navigational element. I'd tend to keep the form and its controls visually separate from other elements on the page - using a <fieldset>, maybe.

belugabob
A: 

How do Firefox/Chrome submit the "GET"? Are there any parameters? If you want to link to ThisPage.aspx then just do it without a button.

A form can be GET or POST, but not both. So if the button is inside a form it will always submit the data from the form, and should use whatever method is set on the form.

Perhaps you can post the actual HTML output to the browser, rather than the ASP code? I have a feeling you may be generating a form-within-a-form. In which case the solution would be to keep the forms separate if possible.

DisgruntledGoat