0

I recently tried to use asp.net POST method and came up with some issues

I'm asking this when i tried to use post method it does not allow me to change action of form and allowed to use only one server side form per page.

what i did was create my own form control and use it on page

Response.Clear();

        StringBuilder sb = new StringBuilder();
        sb.Append("<html>");
        sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
        sb.AppendFormat("<form name='form' action='{0}' method='post'>", "https://test.com.au/Login/Account/Login.aspx");
        sb.AppendFormat("<input type='hidden' name='AP' value='{0}'>", "99");
        // Other params go here
        sb.Append("</form>");
        sb.Append("</body>");
        sb.Append("</html>");

        Response.Write(sb.ToString());

        Response.End();

after navigating to the destination URL i tried to use the browser back button and it's not working. Simply i can not navigate to back?

is this a issue with asp.net or am i missing something?

Actually i'm working on a payment getaway and it requires the parameters to be pass in POST method

chamara
  • 12,649
  • 32
  • 134
  • 210
  • 1
    Sorry, is this ASP.NET? Sorry again: actually, is your sample code a control?? – Matías Fidemraizer Oct 21 '12 at 09:04
  • Even if this is coded using C# and ASP.NET, this question is unrelated to ASP.NET, and rather just about how HTTP POST works. Consider re-tagging it; none of the tags really match the question. – Lucero Oct 21 '12 at 11:05

1 Answers1

0

You try to go back, and you go back - but the previous page is automatic make "post back" and so you move to the page you are again.

So the back work, and you actually move back - what there is done is the issue of you.

The correct way is to "render" that form you show there all ready on a part of your page and with the input click of submit, you just submit that form direct, and not make a second page that make an automatic post.

I know the issue that asp.net allow only one form, but there are some alternative to that. You can read this answer that may help you: Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?

Now because you say that you make a payment getaway, the better is to fully render a page with the custom submit form, right after the form of asp.net. You actually not use the asp.net form at all and you just render your parametres, like you do above, and you let the user just click on the submit and move the the gate way.

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150