【问题标题】:postbackurl using get rather than postpostbackurl 使用 get 而不是 post
【发布时间】:2011-11-11 08:20:55
【问题描述】:

我正在使用 asp.net c# 开发一个网站,我想在页面内放置一个表单。现在 aspx 页面有表单标签,我不想在其中嵌套另一个表单,因为它会使我的 html 无效。但我需要这种形式来使用 GET 而不是 POST。我知道我可以更改 asp:button 中的回发网址。这可以在不使用代码隐藏逻辑的情况下完成吗?

  1. 仅针对此表单将方法更改为 GET,而不是页面上的所有内容
  2. 尽可能将目标更改为 _blank。

我想要的 html 中的示例。

<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>

【问题讨论】:

    标签: c# asp.net forms get postbackurl


    【解决方案1】:

    您可以使用 jquery 来完成此操作

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

    上面的 sn-p,在单击 id 为 'buttonId' 的按钮时触发。它更改了 id 为“formId”的表单的方法属性

    【讨论】:

      【解决方案2】:

      一个 html 中可以有多个表单。 ASP.NET 页面还支持多个表单标记,但是其中只有一个可以是服务器端表单 (runat="server")。

      所以我建议你在页面中添加另一个表单标签——比如

      ...
      <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>
      

      请注意,您不能在 html 标记中放置任何服务器端控件。所以你必须使用 html 控件并使用 Request 对象在页面代码中管理它们。

      【讨论】:

        猜你喜欢
        • 2011-08-04
        • 2010-09-07
        • 1970-01-01
        • 2016-12-25
        • 1970-01-01
        • 1970-01-01
        • 2016-03-12
        • 1970-01-01
        相关资源
        最近更新 更多