I am currently having an issue with a C# User Control when I post to a form - IsPostback is always set to false. The back end of my User Control checks IsPostback and redirects to another url if it is true, but because IsPostback is continuously false the page just refreshes.
A few details about the issue:
- This is a webforms project using .NET version 3.5
- The form is created on the Master page which contains the User Control. IsPostback is false on both the Master page and the User Control.
- I am currently letting .NET populate the action of the form. If the form action is overridden and set to a subdirectory action the redirect fails, but if the form action is overridden and set to a specifiec page (ex - index.aspx) it redirects correctly
- I have verified that when the form is submitted, in the Network tab of developer tools (Chrome) the request is a post
- If the name of the page is included at the end of the url, IsPostback is set to true and the page redirects correctly (ex - Submitting the form on mysite.com will cause a refresh, but submitting on mysite.com/index.aspx will successfully redirect)
- In the web.config file, commenting out the AmbientData HttpModule fixes the issue and the page redirects correctly (on both mysite.com and mysite.com/index.aspx)
- The redirect works fine locally, but the AmbientData.HttpModule is commented out
Here's the form:
<form id="form1" runat="server" method="post">
<MyForm:SubmitForm ID="ctlSubmitForm" runat="server" />
</form>
My User Control code:
<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="SubmitForm.ascx.cs" Inherits="UserControls.SubmitForm" %>
<div id="SubmitForm">
<fieldset>
<input type="text" name="SubmitFormInput" id="SubmitFormInput" runat="server" />
<button type="submit" title="Submit">submit</button>
</fieldset>
</div>
And the User Control page load:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
// Hits here when Ambient Data HttpModule is commented out in Web.config
Log.Debug("Submit Form Control IsPostBack");
Response.Redirect("http://www.google.com");
}
else
{
Log.Debug("Submit Form Control NOT IsPostBack");
}
}
Web.config httpModules/modules sections:
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="Tridion.ContentDelivery.AmbientData.HttpModule" type="Tridion.ContentDelivery.AmbientData.HttpModule" />
<add name="Tridion.ContentDelivery.Preview.Web.PreviewContentModule" type="Tridion.ContentDelivery.Preview.Web.PreviewContentModule" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
<modules>
<remove name="ScriptModule" />
<remove name="WebDAVModule" />
<remove name="FileAuthorization" />
<remove name="UrlRoutingModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="Tridion.ContentDelivery.AmbientData.HttpModule" type="Tridion.ContentDelivery.AmbientData.HttpModule" />
<add name="PreviewContentModule" type="Tridion.ContentDelivery.Preview.Web.PreviewContentModule" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
My question is: Why does removing the AmbientData HttpModule from the Web.config file fix this issue?