Friday, 1 February 2008

Posting back to a page without aspx extension

A project I am working on has the requirement for URLs not to have .aspx extensions. Requests are handled by IIS using ISAPI_Rewrite, which effectively adds on the extension behind the scenes. Generating the URLs is a fairly simple affair in XSLT using substring-before($url, '.aspx'). However, when using a ASP.NET form, the submit button by default adds an extension. I tried specifying the action attribute explicitly of the form, but this had no effect. The solution is to add a PostBackUrl attribute to the button control. Give it the name of the current page, without the extension. Example:

<asp:Button ID="btnSubmit" PostBackUrl="mypage"
runat="server" Text="Submit" OnClick="btnSubmit_Click" />

No comments: