Form and asp.net

  • Thread starter Thread starter Amir Ghezelbash
  • Start date Start date
A

Amir Ghezelbash

Hey guys
why does asp.net do this
its really annoying

you cannot set an action attribute to a from that is running on server

for example when i do this on Default.aspx page
form id="form1" runat="server" action="AnotherPage.aspx?qu=1"

it doesnot work ..any one konw why ?

when you run the page and you go to source code you will see this

form id="form1" action="Default.aspx" method="Post"

you can specify action attribute in any language its an standard html
tag....why does asp.net overrides it ?

any help would greatly be appricated
 
It does that so you have access to the event model on your pages. In order to
use the events such as buttonClick the page must post back to itself. If you
do not need or want to use these events you can use a client side form and
change the action that way or set it explicity. Simply remove the
runat="server" on your form. Again, by doing this though you lose access to
those page events.

HTH
 
for example when i do this on Default.aspx page
form id="form1" runat="server" action="AnotherPage.aspx?qu=1"

it doesnot work ..any one konw why ?

This is due to ASP.NET's event model.

In code behind, you can use a response.redirect to forward the user.

Or remove the runat=server table and convert the form to a plain HTML
form... of course you'll lose access to all of ASP.NET's goodies : (
 
Back
Top