Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8613609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:55:14+00:00 2026-06-12T04:55:14+00:00

I have a form as <form id=form action= method=post runat=server> When accessing in C#

  • 0

I have a form as

<form id="form" action="" method="post" runat="server">

When accessing in C# code-behind via

HtmlForm form = (HtmlForm)this.FindControl("form");

and attempting to change the action with

form.Attributes.Add("action","./newpage.aspx?data=data");

or

form.Attributes["action"] = "./newpage.aspx?data=data");

no change is made. The form still routes to the same page. How can I dynamically change the form’s action in codebehind?

EXTRA DETAILS:
I have a page that has a get variable. That get variable needs to be sent in the action portion of the form. So, page1 response has getvar1. The form on page1 needs to send its post data and getvar1. I was going to adjust this via code-behind in the action of the form, but wanted to avoid using InnerHtml to write the whole form. Holly suggested javascript, but I haven’t found a good way of getting GET vars with javascript. ….. just more information for the masses.

ANSWER EXPLANATION: I chose to go the route that @HollyStyles mentioned. I used javascript to change the form action after the ajax call completed. However, the answer marked correct is the right way to do this via code-behind.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:55:16+00:00Added an answer on June 12, 2026 at 4:55 am

    You can use the Control Adapters of asp.net.

    Here is a working example:

    public class RewriteFormHtmlTextWriter : HtmlTextWriter
    {
        public RewriteFormHtmlTextWriter(HtmlTextWriter writer)
            : base(writer)
        {
            this.InnerWriter = writer.InnerWriter;
        }
        public RewriteFormHtmlTextWriter(System.IO.TextWriter writer)
            : base(writer)
        {
            base.InnerWriter = writer;
        }
    
        public override void WriteAttribute(string name, string value, bool fEncode)
        {
            if (name == "action")
            {
                value = "Change here your value"            
            }
    
            base.WriteAttribute(name, value, fEncode);
        }
    }
    

    With the above code, and a declare on the App_Browsers with a file called Form.browser

    <browsers>
      <browser refID="Default">
        <controlAdapters>
          <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="FormRewriterControlAdapter" />
        </controlAdapters>
      </browser>
    </browsers>
    

    you can change the form. Of course this code called in every form render.

    Relative : http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: <form Name=AddPlace ID=AddPlace action=AddPlace.aspx class=niceform method=post runat=server> That when i
I have a user control which contains the following code: <form id=CurrencyForm method=post runat=server>
I have a form as <form action= method=post> <input name=Descripcion type=hidden value= id=Descripcion runat=server
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
I have form like this: <form method=POST action=<?php echo base_url() ?>admin/admin_search> <fieldset> <label for=nalozi>Nalozi</label><input
I have the following code: <div id=header> <h1>HEADER TEXT</h1> <div id=members> <form action= method=post>
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have a form on home.aspx that is this: <form name=search method=post action=searchresults.aspx id=searchform
In a php-script i have a form, method is post, action-attribute is empty, which
I have an HTML form: <form action='process.php' method='post'> <input type='checkbox' name='check_box_1' /> Check me!<br>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.