Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net doesn't populate action="" of the server form when released

Tags:

I have an ASP.net webforms site, with a server form in the masterpage, as all pages require it.

When debugging the action parameter is populated at runtime along with the id, but when deployed on my server with IIS7 it doesn't appear... but still works. It's not causing the site issues, but its making my W3C HTML5 validation fail, as it needs to be populated.

Debug source:

<form method="post" action="index.aspx" id="aspnetForm">

Live source:

<form method="post" action="" id="aspnetForm">

Form declaration in masterpage:

<form runat="server">
.. some divs
</form>

I know the form tag doesnt have ID/action defined etc, because ASP configures the default at runtime and thats fine, although for some reason it messes up on my server. I've tried using the action="<% Path etc %>", to get the path name but it doesn't work.

What am I doing wrong? Am I missing something, or is it just bad practise to use a form in a masterpage?

Thanks.

Update

Ok, to solve the issue pointed out in the answer I just set the Form.Action on the Masterpage Page_Load, finally got that W3C green light!

Note: I'm using Intelligencia Rewriter, but you can pull the URL using Request.Url

public partial class myMasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Form.Action = Intelligencia.UrlRewriter.RewriterHttpModule.RawUrl;
    }
}