<form action="value"> is changing
version .net 1.1
thanks to fishcake, i have page.registerhiddenfields working so I can transfer some information to another website.
problem is, i have set the forms' action= variable to the website where this info is supposed to be going but when the 'submit' button is clicked the action value is being reset to 'my' aspx page and not what I've set up in the html form.
what's happening here and why ?
Re: <form action="value"> is changing
Create an sub-class of the HtmlForm class, and either remove the "action" attribute, or give it your own value :)
Sample...
PHP Code:
using System;
namespace CG
{
/// <summary>
/// Removes the "Action" attribute, or replaces it with the value provided by the <see cref="ActionUrl"/> property.
/// </summary>
public sealed class HtmlActionlessForm: System.Web.UI.HtmlControls.HtmlForm
{
private string _actionUrl = string.Empty;
private const string ATTRIBUTE_NAME = "name";
private const string ATTRIBUTE_METHOD = "method";
private const string ATTRIBUTE_ACTION = "action";
private const string ATTRIBUTE_ID = "id";
/// <summary>
/// Gets or sets the URL to replace the original action value with.
/// </summary>
public string ActionUrl
{
get
{
return _actionUrl;
}
set
{
if (value == null)
throw new ArgumentNullException("ActionUrl");
_actionUrl = value;
}
}
/// <summary>
/// Initialises a new instance of the <see cref="HtmlActionlessForm"/> class.
/// </summary>
public HtmlActionlessForm(): base()
{
}
/// <summary>
/// Used to remove or modify the "action" attribute of the form tag based on the <see cref="ActionUrl"/> property.
/// </summary>
/// <param name="writer"></param>
protected override void RenderAttributes(System.Web.UI.HtmlTextWriter writer)
{
base.Attributes.Remove(ATTRIBUTE_NAME);
base.Attributes.Remove(ATTRIBUTE_METHOD);
base.Attributes.Remove(ATTRIBUTE_ACTION);
writer.WriteAttribute(ATTRIBUTE_NAME, this.Name);
writer.WriteAttribute(ATTRIBUTE_METHOD, this.Method);
this.Attributes.Render(writer);
if (this.ActionUrl.Length > 0)
writer.WriteAttribute(ATTRIBUTE_ACTION, this.ActionUrl);
if (base.ID != null)
writer.WriteAttribute(ATTRIBUTE_ID, base.ClientID);
}
}
}
And in your aspx...
PHP Code:
<!-- Add the directive... -->
<%@ Register TagPrefix="fm" Namespace="CG" Assembly="CG" %>
<!-- other content here... -->
<fm:HtmlActionlessForm id="Form1" method="post" runat="server" ActionUrl="myotherformtarget.aspx">
</fm:HtmlActionlessForm>
Re: <form action="value"> is changing
problem in 1.1 is that there is no 'post away' -
it will always post back to your page...
2.0 has now made this available.... looks like an upgrade...again....