开发者

How to use POST method with Asp.Net Master page?

开发者 https://www.devze.com 2023-04-12 17:05 出处:网络
I have a master page and on the other asp.net form I need to call a method to .ashx file something as shown below:

I have a master page and on the other asp.net form I need to call a method to .ashx file something as shown below:

As I am having problem with the buttons as whatever the button I click its Posting back the content which I don't want to.

 <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"&g开发者_运维知识库t;
                <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>

which is not possible as I have a content page.

So how do I do that within the content of the asp.net form which is based on the masterpage.


You cannot have server side form tag posting to a different page. Server side form control is designed to post-back to self (it ignores the action attribute) - that's why you see your page getting posted to (content) page. Master page is not really a page but rather a template/layout - content page denotes the actual page (master page is really a control whose control tree get merged into the content page tree).

You can also have cross-page posting in ASP.NET using server side button controls.

However, I believe for whatever you are trying to achieve, you need creating a separate html form tag. For example,

...

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

...
0

精彩评论

暂无评论...
验证码 换一张
取 消