user1814380
user1814380

Reputation:

Change Form id and form action at run time in ASP.NET

How to change the Form Action and Form id at run time. the form tag implemented on master page. please give any solution?

Upvotes: 2

Views: 1244

Answers (2)

Levi Botelho
Levi Botelho

Reputation: 25214

Sounds like you need to use JavaScript. You can do it as follows:

<script>
    var myForm = document.getElementById("oldFormId");
    myForm.action = "newAction";        
    myForm.id = "newFormId"​​;
<script>

Note that this will only change the id and action of the form on the given page and will not affect your actual code (because it is a client-side change). If you wanted, you could encapsulate this logic in a function which is included in your master page itself, which would make it accessible from anywhere on the site.

Upvotes: 1

Murali Murugesan
Murali Murugesan

Reputation: 22619

Try this

    Page.Form.ID = "newFormId";
    Page.Form.Action = "NewPage.aspx";

Note: Used ASP.Net 4.0, Have no idea about previous versions will it work

Upvotes: 1

Related Questions