Changing the Action of a form

  • Thread starter Thread starter Paul Hodgson
  • Start date Start date
P

Paul Hodgson

Anyone know how to access the main Form of a page programmatically, in order
to change its Action property? I seem to be up against two difficulties:
1. Can't find any obvious property on the Page class that lets me get to the
form.
2. I've noticed that even if I hard-code a different Action in the .aspx
page by saying <Form runat="server" Action="OtherPage.aspx" ... etc., the
new Action seems to get lost in the server processing and the current page
gets substituted instead.
(Before anyone asks, I'm not using the Viewstate.).

Thanks!
 
A WebForm always posts back to itself, regardless of what you do. That is
its behavior. I think what you need to do is to re-examine your
requirements, and see what options are available to you for meeting them, as
obviously this is not one of them.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Hi Paul,


Thank you for using Microsoft Newsgroup Service. Based on your description,
you want to know how to operate the sever form in the page object and also
you are wanting to change the "action" attribute so as to let the page be
submited to another page. Please correct me if my understanding is not
quite accurate.

For the first question, the ASP.NET page class does hasn't any buildin
property or methods to control to server form in the page. In fact, the
server form represent the page since an ASP.NET page only have one server
form.

As for the second question, since the ASP.NET 's program mode is event
driven and post back. You do need to use the older style in ASP such as use
the "action" to forward or post data to another page. There are serveral
buildin methods of the page object to do this. For example, you can use the
"Response.Redirect" or "Server.Transfer" to redirect to another page, also
when using the "Server.Transfer", you can store some datas in the request
form area. If you do want to change the form's "action" attribute to post
to another page, maybe you can try using some client side script, here is a
tech article on "Post an ASP.NET form with JavaScript":

http://www.codeproject.com/aspnet/jsnopostback.asp?print=true


Please check out the preceding suggestions. If you have any questions,
please feel free to let me know.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Paul,


Have you had a chance to try my suggestion or the weblink I provided in the
last reply? If you need any assistant, please feel free to post here.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top