method post problem

B

Britney

Hi guys,
in my default.aspx file, I have following code.
when I go to browser, I enter values in both textboxs, then I hit submit
Button,
however, it didn't go to page2.aspx. instead, it was still in default page.
I thought Action will direct page to page2.aspx, no???


<form id="Form1" method="post" runat="server" action="page2.aspx">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
 
G

Guest

Hi Britney,

"Cross page postback" is not a feature of ASP.NET 1.x, as you just
discovered. It is however a feature in ASP.NET 2.0 (currently in beta
release) where a button can have a value for a PostBackUrl property. You can
read about this feature on the ASP.NET 2.0 Quickstart tutorials
http://beta.asp.net/QUICKSTART/aspnet/doc/tipstricks/default.aspx

Currently, you would have to use Server.Transfer(URL, bool) in response for
a ButtonClick event to transfer your form to another page; the bool parameter
would determine if want to keep (true) or clear (false) the Form and
QueryString collections. This link has the full syntax of the transfer
method:
http://msdn.microsoft.com/library/d...temwebhttpserverutilityclasstransfertopic.asp
 
G

Guest

With Server Controls, such as the text boxes and the button below, ASP.NET
relies on post-back capability. If you view-source on the html page you will
see that the ACTION attribute has been changed.

Alternatively, in the code-behind for the button_click event you can
server.transfer or response.redirect to the other page.
 
B

Britney

I tried the following in my code-behind cs file, but it doesn't work.

I don't see it redirect to testing2.aspx..

So this is strange, any idea?



private void Button1_Click(object sender, System.EventArgs e)

{


Server.Transfer("testing2.aspx", true);



}
 
B

Britney

oh.. I can see it's doing redirect now.
when I view source, I can see the contents of html code are from page2.aspx.

however, the URL stay the same, it's still default.aspx
I wonder why...????
 
G

Guest

Hi Britney,

Notice that server.transfer does not cause the browser Address line to
change to indicate the new URL (this is probably why you thought it did not
work), but if you put any action in the Page_Load of the new page you will
realize that the second page is running.
 
B

Britney

okay.. .you're absolutely right..
Now... the reason I want to do "action" in the form originally is because I
want testing2.aspx receive values of two textboxes from default.aspx page.
if I do server.redirect, then how can testing2.aspx remember those values I
entered from prevous page?
 
G

Guest

Hi Britney,

If you were to use Server.Transfer ("secondPage.aspx", true); in the first
page then you can access the values of the textboxes in the second page using
the forms collections, e.g. Request.Form["txtBox1"] would get you the value
inside the textbox with the id “txtBox1†that the user entered on the first
page.
 
B

Britney

Thank you very much..
Now I think I'm getting better and better on this stuff.

One more question,
I do not want user to go to secondPage.aspx directly.
in order to get into second page, user must go through firstPage.aspx first
(by submitting form)

how do I do that?


Phillip Williams said:
Hi Britney,

If you were to use Server.Transfer ("secondPage.aspx", true); in the first
page then you can access the values of the textboxes in the second page
using
the forms collections, e.g. Request.Form["txtBox1"] would get you the
value
inside the textbox with the id "txtBox1" that the user entered on the
first
page.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Britney said:
okay.. .you're absolutely right..
Now... the reason I want to do "action" in the form originally is
because I
want testing2.aspx receive values of two textboxes from default.aspx
page.
if I do server.redirect, then how can testing2.aspx remember those values
I
entered from prevous page?
 
B

Britney

On the second page, I put these code in the page_load section, however,
even if I submit first page, IsPostBack is still FALSE. why?


if (IsPostBack==false)

{

Response.Write("Must going through first page");


}

else

{

......................

}

Britney said:
Thank you very much..
Now I think I'm getting better and better on this stuff.

One more question,
I do not want user to go to secondPage.aspx directly.
in order to get into second page, user must go through firstPage.aspx
first (by submitting form)

how do I do that?


Phillip Williams said:
Hi Britney,

If you were to use Server.Transfer ("secondPage.aspx", true); in the
first
page then you can access the values of the textboxes in the second page
using
the forms collections, e.g. Request.Form["txtBox1"] would get you the
value
inside the textbox with the id "txtBox1" that the user entered on the
first
page.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Britney said:
okay.. .you're absolutely right..
Now... the reason I want to do "action" in the form originally is
because I
want testing2.aspx receive values of two textboxes from default.aspx
page.
if I do server.redirect, then how can testing2.aspx remember those
values I
entered from prevous page?


Hi Britney,

Notice that server.transfer does not cause the browser Address line to
change to indicate the new URL (this is probably why you thought it
did
not
work), but if you put any action in the Page_Load of the new page you
will
realize that the second page is running.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:



I tried the following in my code-behind cs file, but it doesn't work.

I don't see it redirect to testing2.aspx..

So this is strange, any idea?



private void Button1_Click(object sender, System.EventArgs e)

{


Server.Transfer("testing2.aspx", true);



}



Hi Britney,

"Cross page postback" is not a feature of ASP.NET 1.x, as you just
discovered. It is however a feature in ASP.NET 2.0 (currently in
beta
release) where a button can have a value for a PostBackUrl
property.
You
can
read about this feature on the ASP.NET 2.0 Quickstart tutorials
http://beta.asp.net/QUICKSTART/aspnet/doc/tipstricks/default.aspx

Currently, you would have to use Server.Transfer(URL, bool) in
response
for
a ButtonClick event to transfer your form to another page; the bool
parameter
would determine if want to keep (true) or clear (false) the Form
and
QueryString collections. This link has the full syntax of the
transfer
method:
http://msdn.microsoft.com/library/d...temwebhttpserverutilityclasstransfertopic.asp

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

Hi guys,
in my default.aspx file, I have following code.
when I go to browser, I enter values in both textboxs, then I hit
submit
Button,
however, it didn't go to page2.aspx. instead, it was still in
default
page.
I thought Action will direct page to page2.aspx, no???


<form id="Form1" method="post" runat="server"
action="page2.aspx">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</form>
 
B

Britney

I think IsPostBack doesn't work with Server.Transfer.

In version 1.1, the transfer is not considered part of the postback and Page.IsPostBack is set to false even if Server.Transfer transfers back to itself.
http://support.microsoft.com/?kbid=821758

what should I do to get around this problem?


Britney said:
On the second page, I put these code in the page_load section, however,
even if I submit first page, IsPostBack is still FALSE. why?


if (IsPostBack==false)

{

Response.Write("Must going through first page");


}

else

{

.....................

}

Britney said:
Thank you very much..
Now I think I'm getting better and better on this stuff.

One more question,
I do not want user to go to secondPage.aspx directly.
in order to get into second page, user must go through firstPage.aspx
first (by submitting form)

how do I do that?


Phillip Williams said:
Hi Britney,

If you were to use Server.Transfer ("secondPage.aspx", true); in the
first
page then you can access the values of the textboxes in the second page
using
the forms collections, e.g. Request.Form["txtBox1"] would get you the
value
inside the textbox with the id "txtBox1" that the user entered on the
first
page.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

okay.. .you're absolutely right..
Now... the reason I want to do "action" in the form originally is
because I
want testing2.aspx receive values of two textboxes from default.aspx
page.
if I do server.redirect, then how can testing2.aspx remember those
values I
entered from prevous page?


Hi Britney,

Notice that server.transfer does not cause the browser Address line to
change to indicate the new URL (this is probably why you thought it
did
not
work), but if you put any action in the Page_Load of the new page you
will
realize that the second page is running.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:



I tried the following in my code-behind cs file, but it doesn't work.

I don't see it redirect to testing2.aspx..

So this is strange, any idea?



private void Button1_Click(object sender, System.EventArgs e)

{


Server.Transfer("testing2.aspx", true);



}



Hi Britney,

"Cross page postback" is not a feature of ASP.NET 1.x, as you just
discovered. It is however a feature in ASP.NET 2.0 (currently in
beta
release) where a button can have a value for a PostBackUrl
property.
You
can
read about this feature on the ASP.NET 2.0 Quickstart tutorials
http://beta.asp.net/QUICKSTART/aspnet/doc/tipstricks/default.aspx

Currently, you would have to use Server.Transfer(URL, bool) in
response
for
a ButtonClick event to transfer your form to another page; the bool
parameter
would determine if want to keep (true) or clear (false) the Form
and
QueryString collections. This link has the full syntax of the
transfer
method:
http://msdn.microsoft.com/library/d...temwebhttpserverutilityclasstransfertopic.asp

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

Hi guys,
in my default.aspx file, I have following code.
when I go to browser, I enter values in both textboxs, then I hit
submit
Button,
however, it didn't go to page2.aspx. instead, it was still in
default
page.
I thought Action will direct page to page2.aspx, no???


<form id="Form1" method="post" runat="server"
action="page2.aspx">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</form>
 
G

Guest

Hi Britney,

Regarding your two questions:

1- you can prevent going to the second page without the first by checking
the Request.UrlReferrer. However, you should probably design your
application to use the natural asp.net postback programming model (i.e.
posting to the page itself, instead to a second page). You will find it
much easier this way to reference the objects on the page. For example
instead of transferring the form of the first page to another page you can
simply have a function within your first page to do every thing that the
second page would do. You would call this function from the Button1_Click
method. This way you refer to the objects by their id directly instead of
referring to them by Request.Form[id]. It will also prove advantageous in
processing events fired by the different controls on the form.


2- IsPostBack is a property of the page that is handling the request. In
your example the second page only received data transferred from the first
page but it did not post back yet. This is another reason why you should
have used the first page to handle all functions that require you determining
whether a page is postback or not.
In summary you would find it much easier to have your ASP.NET web forms
handle their own postback, instead of trying to emulate the ASP model of
posting the form to another web page. It is good to know however that you
can transfer to another page if you needed to.

You might also look up the many samples written on asp.net on the msdn and
will feel comfortable using the Postback to the same page strategy. It might
help you too if you find a book about Object Oriented Programming to be able
to utilize the many powerful features of programming the asp.net environment.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Britney said:
On the second page, I put these code in the page_load section, however,
even if I submit first page, IsPostBack is still FALSE. why?


if (IsPostBack==false)

{

Response.Write("Must going through first page");


}

else

{

......................

}

Britney said:
Thank you very much..
Now I think I'm getting better and better on this stuff.

One more question,
I do not want user to go to secondPage.aspx directly.
in order to get into second page, user must go through firstPage.aspx
first (by submitting form)

how do I do that?


Phillip Williams said:
Hi Britney,

If you were to use Server.Transfer ("secondPage.aspx", true); in the
first
page then you can access the values of the textboxes in the second page
using
the forms collections, e.g. Request.Form["txtBox1"] would get you the
value
inside the textbox with the id "txtBox1" that the user entered on the
first
page.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

okay.. .you're absolutely right..
Now... the reason I want to do "action" in the form originally is
because I
want testing2.aspx receive values of two textboxes from default.aspx
page.
if I do server.redirect, then how can testing2.aspx remember those
values I
entered from prevous page?


Hi Britney,

Notice that server.transfer does not cause the browser Address line to
change to indicate the new URL (this is probably why you thought it
did
not
work), but if you put any action in the Page_Load of the new page you
will
realize that the second page is running.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:



I tried the following in my code-behind cs file, but it doesn't work.

I don't see it redirect to testing2.aspx..

So this is strange, any idea?



private void Button1_Click(object sender, System.EventArgs e)

{


Server.Transfer("testing2.aspx", true);



}



Hi Britney,

"Cross page postback" is not a feature of ASP.NET 1.x, as you just
discovered. It is however a feature in ASP.NET 2.0 (currently in
beta
release) where a button can have a value for a PostBackUrl
property.
You
can
read about this feature on the ASP.NET 2.0 Quickstart tutorials
http://beta.asp.net/QUICKSTART/aspnet/doc/tipstricks/default.aspx

Currently, you would have to use Server.Transfer(URL, bool) in
response
for
a ButtonClick event to transfer your form to another page; the bool
parameter
would determine if want to keep (true) or clear (false) the Form
and
QueryString collections. This link has the full syntax of the
transfer
method:
http://msdn.microsoft.com/library/d...temwebhttpserverutilityclasstransfertopic.asp

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

Hi guys,
in my default.aspx file, I have following code.
when I go to browser, I enter values in both textboxs, then I hit
submit
Button,
however, it didn't go to page2.aspx. instead, it was still in
default
page.
I thought Action will direct page to page2.aspx, no???


<form id="Form1" method="post" runat="server"
action="page2.aspx">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</form>
 
B

Britney

thank you.. you're very nice.

Phillip Williams said:
Hi Britney,

Regarding your two questions:

1- you can prevent going to the second page without the first by checking
the Request.UrlReferrer. However, you should probably design your
application to use the natural asp.net postback programming model (i.e.
posting to the page itself, instead to a second page). You will find it
much easier this way to reference the objects on the page. For example
instead of transferring the form of the first page to another page you can
simply have a function within your first page to do every thing that the
second page would do. You would call this function from the Button1_Click
method. This way you refer to the objects by their id directly instead of
referring to them by Request.Form[id]. It will also prove advantageous in
processing events fired by the different controls on the form.


2- IsPostBack is a property of the page that is handling the request. In
your example the second page only received data transferred from the first
page but it did not post back yet. This is another reason why you should
have used the first page to handle all functions that require you
determining
whether a page is postback or not.
In summary you would find it much easier to have your ASP.NET web forms
handle their own postback, instead of trying to emulate the ASP model of
posting the form to another web page. It is good to know however that you
can transfer to another page if you needed to.

You might also look up the many samples written on asp.net on the msdn and
will feel comfortable using the Postback to the same page strategy. It
might
help you too if you find a book about Object Oriented Programming to be
able
to utilize the many powerful features of programming the asp.net
environment.


--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Britney said:
On the second page, I put these code in the page_load section, however,
even if I submit first page, IsPostBack is still FALSE. why?


if (IsPostBack==false)

{

Response.Write("Must going through first page");


}

else

{

......................

}

Britney said:
Thank you very much..
Now I think I'm getting better and better on this stuff.

One more question,
I do not want user to go to secondPage.aspx directly.
in order to get into second page, user must go through firstPage.aspx
first (by submitting form)

how do I do that?


Hi Britney,

If you were to use Server.Transfer ("secondPage.aspx", true); in the
first
page then you can access the values of the textboxes in the second
page
using
the forms collections, e.g. Request.Form["txtBox1"] would get you the
value
inside the textbox with the id "txtBox1" that the user entered on the
first
page.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

okay.. .you're absolutely right..
Now... the reason I want to do "action" in the form originally is
because I
want testing2.aspx receive values of two textboxes from default.aspx
page.
if I do server.redirect, then how can testing2.aspx remember those
values I
entered from prevous page?


Hi Britney,

Notice that server.transfer does not cause the browser Address line
to
change to indicate the new URL (this is probably why you thought it
did
not
work), but if you put any action in the Page_Load of the new page
you
will
realize that the second page is running.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:



I tried the following in my code-behind cs file, but it doesn't
work.

I don't see it redirect to testing2.aspx..

So this is strange, any idea?



private void Button1_Click(object sender, System.EventArgs e)

{


Server.Transfer("testing2.aspx", true);



}



message
Hi Britney,

"Cross page postback" is not a feature of ASP.NET 1.x, as you
just
discovered. It is however a feature in ASP.NET 2.0 (currently
in
beta
release) where a button can have a value for a PostBackUrl
property.
You
can
read about this feature on the ASP.NET 2.0 Quickstart tutorials
http://beta.asp.net/QUICKSTART/aspnet/doc/tipstricks/default.aspx

Currently, you would have to use Server.Transfer(URL, bool) in
response
for
a ButtonClick event to transfer your form to another page; the
bool
parameter
would determine if want to keep (true) or clear (false) the Form
and
QueryString collections. This link has the full syntax of the
transfer
method:
http://msdn.microsoft.com/library/d...temwebhttpserverutilityclasstransfertopic.asp

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

Hi guys,
in my default.aspx file, I have following code.
when I go to browser, I enter values in both textboxs, then I
hit
submit
Button,
however, it didn't go to page2.aspx. instead, it was still in
default
page.
I thought Action will direct page to page2.aspx, no???


<form id="Form1" method="post" runat="server"
action="page2.aspx">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</form>
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top