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.
You can use the Control Adapters of asp.net.
Here is a working example:
With the above code, and a declare on the
App_Browserswith a file calledForm.browseryou 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