I've got a WebForms site built using Progressive Enhancement which uses Master pages. Obviously, the tag is injected by default by ASP.NET so it can manage the postbacks.

I need a way of doing the following

<form action="new_url" method="get">
 <input ... />
</form>

Obviously, .NET is intercepting the request with the outer and posting back to itself. I can do this with JavaScript but then I'll break the Progressive Enhancement policy of my website. Is this not possible without essentially building an ASP.NET Server Control to manage the redirection?

Thanks Martin

有帮助吗?

解决方案

The tag should be well visible in your source file, with a runat="server". However, it shouldn't be possible to add another form tag inside another one and you can't have two <form runat="server">.

So, one way to achieve this would be to append the form after the existing one. It might not be possible with your current MasterPages / Pages / UserControls setup, especialy if you got the <form runat="server"> tag in the MasterPage.

So, you can either reevaluate your structure using nested master pages so you can choose which pages will actually use the PostBack feature and use a <form>less MasterPage for the other pages.

Another way would be to use javascript to build an URL from some fields.

Have a look at this post, it might help you: Multiple forms on ASP.NET page

其他提示

I believe there is a property on the Page class called "PostBackUrl" that you can use to tell ASP.NET where to send the postback.

I can't remember if it's the Page or one of the link button classes, but just Google "PostBackURL" and you should get some good results.

With forms and ASP.net you can access the Get variables with

Page.Request.QueryString[<param>];

It's used like this

<form action="new_url" method="get">
    <input type="text" id="txtName" name="name" />
</form>

in your page_load method or the submit page you can access the input field using the this code

Page.Request.QueryString["name"]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top