SIGN UP MEMBER LOGIN:    
ARTICLE

Posting to another .aspx using ASP.NET

Posted by Santhi Maadhaven Articles | ASP.NET Programming March 19, 2005
ASP.NET wont allow to post back to another aspx page. It will post back to itself. If you specify action attribute it will ignore it. If you omit the method attribute, it will be set to method="post" by default.
Reader Level:

As we know, ASP.NET wont allow to post back to another aspx page. It will post back to itself. If you specify action attribute it will ignore it. If you omit the method attribute, it will be set to method="post" by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET. An aspx can contain only one <form> tag.

There is one workaround for posting to another .aspx page. Omit the runat="server" attribute. What Runat attribute does is it will override the action attribute to the file name submitted. If you omit the runat attribute, action will take to another aspx page with the form values posted. But one disadvantage is there, we cant use server controls inside the first page. Those values cant be posted to another .aspx page. But one good thing is we can use HTML controls. Runat=server in HTML controls will allow us to access those values in the posted page.

Let us see one example, First.aspx

<html>
<
head><title>First Page</title></head>
<
body>
<
form name="frmFirstPage" action="Second.aspx" method="post">
<
input type="text" name="FirstName" id="FirstName" runat="server"/>
<
input type="text" name="LastName" id="LastName" runat="server"/>
<
input name="Submit" type="Submit" runat="server" ID="Submit1"/>
</
form>
</
body>
</
html>

Second.aspx

<html>
<
head><title>Second Page</title></head>
<
body>
<
form id="frmFirstPage" method="post" runat="server">
FirstName:<%=Response.Write(Request["FirstName"])%>
LastName:<%=Response.Write(Request["LastName"])%>
</form>
</
body>
</
html>

If u enter Naveena as FirstName and Maadhaven as second name in the First.aspx, you can see the output in second.aspx as

FirstName : Naveena
LastName : Maadhaven

This is the very simple example but this shows whatever we did using ASP is still available in ASP.NET. But you should go for this approach when you don't need any web server or rich controls in your application. Hope this article will be useful to you.

Login to add your contents and source code to this article
share this article :
post comment
 

I need to post data, which are placed in several tables, to another page. The problem is that the data is produced in First.aspx.cs file and I want 1) to send them to the Second.aspx.cs file, 2) to sort them 3) to show them at the Second.aspx file, in a specific position can you help me with that???

Posted by kiki Oct 02, 2007
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Gauge for SharePoint
Become a Sponsor