Today I had an interesting problem, how can you get a Form post from ASP.NET to classic ASP? At first this would seem to be a simple thing, just use Server.Transfer, well as I discovered you can’t do that.
Here is some example code:
default.aspx
<body>
<form id="form1" runat="server">
<asp:TextBox ID="send_this" runat="server"></asp:TextBox><asp:Button ID="send"
runat="server" Text="send" onclick="send_Click" />
</div>
</form>
</body>
default.aspx.cs
protected void send_Click(object sender, EventArgs e)
{
Server.Transfer("receive.asp");
}
receive.asp
<body>
Got: <%=Request.Form("send_this")%>
</body>
Will return you an “Error executing child request for receive.asp” error. Checking with Microsoft it turned out that this is by design.
Request.Redirect was no good, as it won’t send any information over HTTP and playing around the HTTP streams was fun but again would not pass control over to the other page.
One possible solution
The solution you can use is to capture the information on the way into your ASP.NET code and using JavaScript redirect the post to the other page. First you will need to add the page body to ASP.NET by adding and id and runat=“server”.
<body id="body1" runat="server">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="send_this" runat="server"></asp:TextBox><asp:Button ID="send"
runat="server" Text="send" onclick="send_Click" />
</div>
</form>
</body>
Then in the ASP.NET code behind inject some javascript and an action method to your form.
protected void send_Click(object sender, EventArgs e)
{
form1.Action="receive.asp";
form1.Method = "post";
body1.Attributes["onload"] = "document.forms[0].submit();";
}
This will give you the best of both worlds… ability to use all ASP.NET controls on the main page and then post the values to classic ASP. I can’t wait for the day there won’t be any need to use classic ASP again!