Results 1 to 3 of 3

Thread: <form action="value"> is changing

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    <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 ?

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    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 HtmlActionlessFormSystem.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_NAMEthis.Name);
                
                
    writer.WriteAttribute(ATTRIBUTE_METHODthis.Method);

                
    this.Attributes.Render(writer);

                if (
    this.ActionUrl.Length 0)
                    
    writer.WriteAttribute(ATTRIBUTE_ACTIONthis.ActionUrl);

                if (
    base.ID != null)
                    
    writer.WriteAttribute(ATTRIBUTE_IDbase.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

  3. #3

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    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....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width