【问题标题】:How to use POST method with Asp.Net Master page?如何在 Asp.Net 母版页中使用 POST 方法?
【发布时间】:2011-10-11 07:56:33
【问题描述】:

我有一个母版页,在另一个 asp.net 表单上,我需要调用一个方法来 .ashx 文件,如下所示:

由于我在使用按钮时遇到问题,因为无论我点击哪个按钮,我都会发回我不想要的内容。

 <form id="Form1" action="Upload.ashx" method="POST" enctype="multipart/form-data"
    runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div id="fileupload" style="border: thin solid #666666; width: 600px; height: 520px;
        z-index: 1; left: 18px; top: 22px; position: absolute; overflow: auto;">
        <div class="fileupload-buttonbar">
            <label class="fileinput-button">
                <span>Add files...</span>
                <input type="file" name="files[]" multiple="multiple" />
            </label>
            <button type="submit" class="start">
                Start upload</button>
            <button type="reset" class="cancel">
                Cancel upload</button>
            <button type="button" class="delete">
                Delete all files</button>
            <div class="fileupload-progressbar">
            </div>
        </div>
        <div class="fileupload-content" style="border-style: none">
            <table class="files">
            </table>
            </div>
        </div>
</form>

这是不可能的,因为我有一个内容页面。

那么我该如何在基于母版页的 asp.net 表单的内容中做到这一点。

【问题讨论】:

  • “母版页和其他表单”?你想做什么?您可能正在尝试做某事,而当涉及到 asp.net 和母版页时,您的做法是完全错误的
  • 是的,我只是想展示我目前拥有的表单,并且在该表单上我有一个发布方法。而且我正在使用母版页,所以我对母版页如何处理是我的疑问!跨度>
  • 我需要将数据从内容占位符发布到upload.ashx文件。

标签: asp.net master-pages


【解决方案1】:

您不能将服务器端表单标签发布到不同的页面。服务器端表单控件旨在回发给自己(它忽略了 action 属性) - 这就是为什么您看到您的页面被发布到(内容)页面的原因。母版页不是真正的页面,而是模板/布局 - 内容页表示实际页面(母版页实际上是一个控件,其控制树合并到内容页树中)。

您还可以使用服务器端按钮控件来拥有cross-page posting in ASP.NET

但是,我相信无论您想要实现什么,您都需要创建一个 separate html 表单标签。例如,

...

<!-- server side form - do not touch -->
<form id="Form1" runat="server">
... 
</form>

...

<!-- you can have multiple html form tags but you cannot use server controls -->
<form action="Upload.ashx" method="POST" enctype="multipart/form-data">
...
</form>

...

【讨论】:

  • 感谢您的回复,链接正是我现在正在寻找的!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-26
  • 1970-01-01
  • 2010-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多