How can I submit an ASP.NET web form to a new page

C

Chung

Hi all,

I have used the following code for doing the form
submission. I don't think this is a right way to submit a
from to a new aspx page because I need to add a dummy form
in between.
Could anyone tell me a proper way to do this?

Looking forward to your reply. Thanks!

Chung

My code:

<form id="Form1" method="post" runat="server">
<asp:Button id="Reset_btn" style="Z-INDEX: 125;
LEFT: 853px; POSITION: absolute; TOP: 504px"
runat="server" Width="82px" Height="59px"
Text="Postback"></asp:Button>
<form id="Dummy_Form">
</form>
<form id="Form2" method="post" action="New.aspx">
<INPUT style="Z-INDEX: 105; LEFT: 22px; WIDTH:
224px; POSITION: absolute; TOP: 11px; HEIGHT: 42px"
type="submit" value="Submit to New page">
</form>
</form>
 
S

Scott M.

In .NET your forms submit to themselves (which is called a postback). On
the second (or subsequent page load) you can retrieve the values from your
form elements like this:

Sub Page_Load()
If Not IsPostBack Then 'First time the page is loading

Else 'Second or subsequent time the
page is loading

End If
End Sub

If you want to redirect to another page, use response.redirect,
server.transfer or server.execute.
 
S

Steve C. Orr [MVP, MCSD]

Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=600

http://www.dotnetbips.com/displayarticle.aspx?id=79
 
C

Chung

Thanks Steve,

This really helps me a lot. When I am using the
context.Items control, it comes up another problem. I case
I have 100 textbox in my form then I have to add 100
context items in Context.Items.

Is there any way to get all the form control from my form
at a time? Then I can use foreach loop to get all the
value.

Chung
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top