473,699 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp question about post vars

I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can
get to their values easily to write to a database or continue to process on
to the next page.

I am now trying to learn ASP to see if we can replace some of our
applications that were written in php with an ASP alternative. However,
after doing many searches on google and reading a couple ASP books to try to
figure out this simple task I'm still without a solution.

I've had a couple people tell me that I need to do query strings and pass
all the values on the form over individually but surely there is a better
solution. Can anyone tell me the best way to take a form with a lastname
and firstname field and pass them through a post to a result page and then
access those fields values on the result page?

Thanks,

glenn
Nov 19 '05 #1
10 3428
> I've had a couple people tell me that I need to do query strings and pass
all the values on the form over individually but surely there is a better
solution. Can anyone tell me the best way to take a form with a lastname
and firstname field and pass them through a post to a result page and then
access those fields values on the result page?
This is kind of like that old joke: How do I get to Broadway? (Answer:
practice). Although the punch line is a joke, the question is similar. There
are many ways to "get to Broadway." Taking a cab might not be the best way
if you're riding in a bus. Taking the subway is fast, as long as you're near
a subway station.

So, the first issue you will want to know is, what are the various ways that
data can be passed from one page in an ASP.Net app to another?

1. QueryString. This is useful when you're hyperlinking from one page to the
other, and no security requirement dictates that the data should not appear
to the user.
2. "Traditiona l" form post. Yes, with ASP.Net you can still post a form to
another page, but not a WebForm. This is an unusual case, so I won't bother
with it.
3. PostBack and Server.Transfer . Post the form back to itself. On the
server-side, do a Server.Tranfer to transfer the context to a new page. This
is useful when you don't want the user to know what data you're passing.
4. PostBack and Response.Redire ct. Post the form back to itself. On the
server side, do a Response.Redire ct. This sends a header to the browser
telling it to request the second URL. This method has the same drawbacks as
number 1.
5. PostBack, store data in Session (or Application, depending upon the scope
you want), and Redirect or Transfer. This is like numbers 3 and 4, but it
uses Session space on the server to store the data. This way, no QueryString
is needed, but you have to be careful about Session Timeouts.

That's about all I can think of at the moment. Choose the method that works
best in a given situation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"glenn" <gh******@softe ksoftware.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can
get to their values easily to write to a database or continue to process
on
to the next page.

I am now trying to learn ASP to see if we can replace some of our
applications that were written in php with an ASP alternative. However,
after doing many searches on google and reading a couple ASP books to try
to
figure out this simple task I'm still without a solution.

I've had a couple people tell me that I need to do query strings and pass
all the values on the form over individually but surely there is a better
solution. Can anyone tell me the best way to take a form with a lastname
and firstname field and pass them through a post to a result page and then
access those fields values on the result page?

Thanks,

glenn

Nov 19 '05 #2
Because of the postback architecture that was implemented with ASP.NET, this
task is not as easy as it once was. If you need to pass data between pages
there are several options:

1. Use querystring variables
2. Use session variables
3. Use application variables (careful, these are global)
4. Use Server.Transfer (this is may be what you are looking for, see below)

Page 1
public class Page1 : System.Web.UI.P age
{
private void submitBtn_Click (object sender, System.EventArg s e)
{
//these can be public fields or public properties
//Creating public properties that get private fields
//is a better practice
lastName = "name1";
firstName = "name2";

Server.Transfer ("page2.aspx ");
}
}

Page 2
public class Page2 : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
Page1 myPage1 = (Page1)Context. Handler;
string lastName = myPage1.lastNam e;
string firstName = myPage2.firstNa me;
}
}


"glenn" wrote:
I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can
get to their values easily to write to a database or continue to process on
to the next page.

I am now trying to learn ASP to see if we can replace some of our
applications that were written in php with an ASP alternative. However,
after doing many searches on google and reading a couple ASP books to try to
figure out this simple task I'm still without a solution.

I've had a couple people tell me that I need to do query strings and pass
all the values on the form over individually but surely there is a better
solution. Can anyone tell me the best way to take a form with a lastname
and firstname field and pass them through a post to a result page and then
access those fields values on the result page?

Thanks,

glenn

Nov 19 '05 #3
I appreciate the response however, you are somewhat like a joke yourself. I
asked a question. A simple question as none of the books I have answer it.
You reply that I'm asking a stupid question and give me 5 ways to do it with
not a single example or reference, so all you've done is tell me what I
already thought I knew. I know what a post var is, and you list it as an
answer but don't provide a way to do it. I am glad you answered the
question, however, instead of stating the obvious next time, why don't you
just stay quiet and let someone with an answer respond.

I don't mean to be rude, but I have to say that the Microsoft community is
the most hostile group of people I've ever dealt with. I can see why people
want Linux and Borland to do so well. I have been in Borland Delphi for 10
years now and have to say that the people over there are much nicer and much
more helpful to people trying to learn a new product. Microsoft developers
act like you work with God himself and don't need new users and are
therefore rude when they ask what you believe to be stupid questions.

Thanks for nothing,

glenn
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:O$******** ******@TK2MSFTN GP14.phx.gbl...
I've had a couple people tell me that I need to do query strings and pass all the values on the form over individually but surely there is a better solution. Can anyone tell me the best way to take a form with a lastname and firstname field and pass them through a post to a result page and then access those fields values on the result page?
This is kind of like that old joke: How do I get to Broadway? (Answer:
practice). Although the punch line is a joke, the question is similar.

There are many ways to "get to Broadway." Taking a cab might not be the best way
if you're riding in a bus. Taking the subway is fast, as long as you're near a subway station.

So, the first issue you will want to know is, what are the various ways that data can be passed from one page in an ASP.Net app to another?

1. QueryString. This is useful when you're hyperlinking from one page to the other, and no security requirement dictates that the data should not appear to the user.
2. "Traditiona l" form post. Yes, with ASP.Net you can still post a form to
another page, but not a WebForm. This is an unusual case, so I won't bother with it.
3. PostBack and Server.Transfer . Post the form back to itself. On the
server-side, do a Server.Tranfer to transfer the context to a new page. This is useful when you don't want the user to know what data you're passing.
4. PostBack and Response.Redire ct. Post the form back to itself. On the
server side, do a Response.Redire ct. This sends a header to the browser
telling it to request the second URL. This method has the same drawbacks as number 1.
5. PostBack, store data in Session (or Application, depending upon the scope you want), and Redirect or Transfer. This is like numbers 3 and 4, but it
uses Session space on the server to store the data. This way, no QueryString is needed, but you have to be careful about Session Timeouts.

That's about all I can think of at the moment. Choose the method that works best in a given situation.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.
"glenn" <gh******@softe ksoftware.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can get to their values easily to write to a database or continue to process
on
to the next page.

I am now trying to learn ASP to see if we can replace some of our
applications that were written in php with an ASP alternative. However,
after doing many searches on google and reading a couple ASP books to try to
figure out this simple task I'm still without a solution.

I've had a couple people tell me that I need to do query strings and pass all the values on the form over individually but surely there is a better solution. Can anyone tell me the best way to take a form with a lastname and firstname field and pass them through a post to a result page and then access those fields values on the result page?

Thanks,

glenn


Nov 19 '05 #4
Thank you very much. That does answer my question and I think its what we
were looking for.

glenn
"sstevens" <ss******@discu ssions.microsof t.com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
Because of the postback architecture that was implemented with ASP.NET, this task is not as easy as it once was. If you need to pass data between pages there are several options:

1. Use querystring variables
2. Use session variables
3. Use application variables (careful, these are global)
4. Use Server.Transfer (this is may be what you are looking for, see below)
Page 1
public class Page1 : System.Web.UI.P age
{
private void submitBtn_Click (object sender, System.EventArg s e)
{
//these can be public fields or public properties
//Creating public properties that get private fields
//is a better practice
lastName = "name1";
firstName = "name2";

Server.Transfer ("page2.aspx ");
}
}

Page 2
public class Page2 : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
Page1 myPage1 = (Page1)Context. Handler;
string lastName = myPage1.lastNam e;
string firstName = myPage2.firstNa me;
}
}


"glenn" wrote:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a database or continue to process on to the next page.

I am now trying to learn ASP to see if we can replace some of our
applications that were written in php with an ASP alternative. However,
after doing many searches on google and reading a couple ASP books to try to figure out this simple task I'm still without a solution.

I've had a couple people tell me that I need to do query strings and pass all the values on the form over individually but surely there is a better solution. Can anyone tell me the best way to take a form with a lastname and firstname field and pass them through a post to a result page and then access those fields values on the result page?

Thanks,

glenn

Nov 19 '05 #5
Hi glenn,
You reply that I'm asking a stupid question
Would you please point out the word "stupid" or any other words in my
message that were insulting to you? In fact, I did NOT think your question
was stupid, or I wouldn't have spent all that time enumerating the various
ways of passing data from one page to another.
not a single example or reference, so all you've done is tell me what I
already thought I knew. I know what a post var is, and you list it as an
answer but don't provide a way to do it.
Here was your question:
Can anyone tell me the best way to take a form with a
lastname
> and firstname field and pass them through a post to a result page and

then
> access those fields values on the result page?

I answered it. In detail. No, I didn't post any examples. Why should I? Did
you ask for any? When one is talking in general terms, is it wise to provide
specific examples? Should I assume that you need them? Why?
I don't mean to be rude, but I have to say that the Microsoft community
is
the most hostile group of people I've ever dealt with.
Interesting. I made a joke to lighten things up. The joke (a VERY old joke)
was in no way insulting, but that's how you took it. I would have to guess
that YOU are the hostile one. And that you lack any sense of humor.
Microsoft developers
act like you work with God himself and don't need new users and are
therefore rude when they ask what you believe to be stupid questions.
A lot of assumptions on your part, and mean-spirited ones at that. Listen,
bub. I donate my time to help people like you, and spend a good bit of it
making sure I'm giving you the right stuff. I do it out of the goodness of
my heart. Your attitude sucks. Good luck. You'll need it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"glenn" <gh******@softe ksoftware.com> wrote in message
news:u3******** ******@tk2msftn gp13.phx.gbl...I appreciate the response however, you are somewhat like a joke yourself.
I
asked a question. A simple question as none of the books I have answer
it.
You reply that I'm asking a stupid question and give me 5 ways to do it
with
not a single example or reference, so all you've done is tell me what I
already thought I knew. I know what a post var is, and you list it as an
answer but don't provide a way to do it. I am glad you answered the
question, however, instead of stating the obvious next time, why don't you
just stay quiet and let someone with an answer respond.

I don't mean to be rude, but I have to say that the Microsoft community
is
the most hostile group of people I've ever dealt with. I can see why
people
want Linux and Borland to do so well. I have been in Borland Delphi for
10
years now and have to say that the people over there are much nicer and
much
more helpful to people trying to learn a new product. Microsoft
developers
act like you work with God himself and don't need new users and are
therefore rude when they ask what you believe to be stupid questions.

Thanks for nothing,

glenn
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:O$******** ******@TK2MSFTN GP14.phx.gbl... > I've had a couple people tell me that I need to do query strings and pass > all the values on the form over individually but surely there is a better > solution. Can anyone tell me the best way to take a form with a lastname > and firstname field and pass them through a post to a result page and then > access those fields values on the result page?


This is kind of like that old joke: How do I get to Broadway? (Answer:
practice). Although the punch line is a joke, the question is similar.

There
are many ways to "get to Broadway." Taking a cab might not be the best
way
if you're riding in a bus. Taking the subway is fast, as long as you're

near
a subway station.

So, the first issue you will want to know is, what are the various ways

that
data can be passed from one page in an ASP.Net app to another?

1. QueryString. This is useful when you're hyperlinking from one page to

the
other, and no security requirement dictates that the data should not

appear
to the user.
2. "Traditiona l" form post. Yes, with ASP.Net you can still post a form
to
another page, but not a WebForm. This is an unusual case, so I won't

bother
with it.
3. PostBack and Server.Transfer . Post the form back to itself. On the
server-side, do a Server.Tranfer to transfer the context to a new page.

This
is useful when you don't want the user to know what data you're passing.
4. PostBack and Response.Redire ct. Post the form back to itself. On the
server side, do a Response.Redire ct. This sends a header to the browser
telling it to request the second URL. This method has the same drawbacks

as
number 1.
5. PostBack, store data in Session (or Application, depending upon the

scope
you want), and Redirect or Transfer. This is like numbers 3 and 4, but it
uses Session space on the server to store the data. This way, no

QueryString
is needed, but you have to be careful about Session Timeouts.

That's about all I can think of at the moment. Choose the method that

works
best in a given situation.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.
"glenn" <gh******@softe ksoftware.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
>I am use to programming in php and the way session and post vars are
>past
> from fields on one page through to the post page automatically where I can > get to their values easily to write to a database or continue to
> process
> on
> to the next page.
>
> I am now trying to learn ASP to see if we can replace some of our
> applications that were written in php with an ASP alternative.
> However,
> after doing many searches on google and reading a couple ASP books to try > to
> figure out this simple task I'm still without a solution.
>
> I've had a couple people tell me that I need to do query strings and pass > all the values on the form over individually but surely there is a better > solution. Can anyone tell me the best way to take a form with a lastname > and firstname field and pass them through a post to a result page and then > access those fields values on the result page?
>
> Thanks,
>
> glenn
>
>



Nov 19 '05 #6
Well, I'm sorry I asked such a confusing question. The second person that
responded must have read something you did not as they were much much more
polite and answered the question perfectly... Sorry for the
misunderstandin g. I'm so use to people making comments about how great
things are but providing no details that I might have jumped you too
quickly.

I apologize...

glenn
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:eO******** *****@TK2MSFTNG P14.phx.gbl...
Hi glenn,
You reply that I'm asking a stupid question
Would you please point out the word "stupid" or any other words in my
message that were insulting to you? In fact, I did NOT think your question
was stupid, or I wouldn't have spent all that time enumerating the various
ways of passing data from one page to another.
not a single example or reference, so all you've done is tell me what I
already thought I knew. I know what a post var is, and you list it as an
answer but don't provide a way to do it.


Here was your question:
Can anyone tell me the best way to take a form with a
lastname
> and firstname field and pass them through a post to a result page and
then
> access those fields values on the result page?
I answered it. In detail. No, I didn't post any examples. Why should I?

Did you ask for any? When one is talking in general terms, is it wise to provide specific examples? Should I assume that you need them? Why?
I don't mean to be rude, but I have to say that the Microsoft community
is
the most hostile group of people I've ever dealt with.
Interesting. I made a joke to lighten things up. The joke (a VERY old

joke) was in no way insulting, but that's how you took it. I would have to guess
that YOU are the hostile one. And that you lack any sense of humor.
Microsoft developers
act like you work with God himself and don't need new users and are
therefore rude when they ask what you believe to be stupid questions.


A lot of assumptions on your part, and mean-spirited ones at that. Listen,
bub. I donate my time to help people like you, and spend a good bit of it
making sure I'm giving you the right stuff. I do it out of the goodness of
my heart. Your attitude sucks. Good luck. You'll need it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.

"glenn" <gh******@softe ksoftware.com> wrote in message
news:u3******** ******@tk2msftn gp13.phx.gbl...
I appreciate the response however, you are somewhat like a joke yourself.
I
asked a question. A simple question as none of the books I have answer
it.
You reply that I'm asking a stupid question and give me 5 ways to do it
with
not a single example or reference, so all you've done is tell me what I
already thought I knew. I know what a post var is, and you list it as

an answer but don't provide a way to do it. I am glad you answered the
question, however, instead of stating the obvious next time, why don't you just stay quiet and let someone with an answer respond.

I don't mean to be rude, but I have to say that the Microsoft community
is
the most hostile group of people I've ever dealt with. I can see why
people
want Linux and Borland to do so well. I have been in Borland Delphi for
10
years now and have to say that the people over there are much nicer and
much
more helpful to people trying to learn a new product. Microsoft
developers
act like you work with God himself and don't need new users and are
therefore rude when they ask what you believe to be stupid questions.

Thanks for nothing,

glenn
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:O$******** ******@TK2MSFTN GP14.phx.gbl...
> I've had a couple people tell me that I need to do query strings and

pass
> all the values on the form over individually but surely there is a

better
> solution. Can anyone tell me the best way to take a form with a

lastname
> and firstname field and pass them through a post to a result page and

then
> access those fields values on the result page?

This is kind of like that old joke: How do I get to Broadway? (Answer:
practice). Although the punch line is a joke, the question is similar.

There
are many ways to "get to Broadway." Taking a cab might not be the best
way
if you're riding in a bus. Taking the subway is fast, as long as you're

near
a subway station.

So, the first issue you will want to know is, what are the various ways

that
data can be passed from one page in an ASP.Net app to another?

1. QueryString. This is useful when you're hyperlinking from one page to
the
other, and no security requirement dictates that the data should not

appear
to the user.
2. "Traditiona l" form post. Yes, with ASP.Net you can still post a form
to
another page, but not a WebForm. This is an unusual case, so I won't

bother
with it.
3. PostBack and Server.Transfer . Post the form back to itself. On the
server-side, do a Server.Tranfer to transfer the context to a new page.

This
is useful when you don't want the user to know what data you're
passing. 4. PostBack and Response.Redire ct. Post the form back to itself. On the
server side, do a Response.Redire ct. This sends a header to the browser
telling it to request the second URL. This method has the same drawbacks as
number 1.
5. PostBack, store data in Session (or Application, depending upon the

scope
you want), and Redirect or Transfer. This is like numbers 3 and 4, but
it uses Session space on the server to store the data. This way, no

QueryString
is needed, but you have to be careful about Session Timeouts.

That's about all I can think of at the moment. Choose the method that

works
best in a given situation.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.
"glenn" <gh******@softe ksoftware.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
>I am use to programming in php and the way session and post vars are
>past
> from fields on one page through to the post page automatically where

I can
> get to their values easily to write to a database or continue to
> process
> on
> to the next page.
>
> I am now trying to learn ASP to see if we can replace some of our
> applications that were written in php with an ASP alternative.
> However,
> after doing many searches on google and reading a couple ASP books to

try
> to
> figure out this simple task I'm still without a solution.
>
> I've had a couple people tell me that I need to do query strings and

pass
> all the values on the form over individually but surely there is a

better
> solution. Can anyone tell me the best way to take a form with a

lastname
> and firstname field and pass them through a post to a result page and

then
> access those fields values on the result page?
>
> Thanks,
>
> glenn
>
>



Nov 19 '05 #7
Thank you, glenn. Apoology accepted, and I'll be happy to help you in the
future when I can.

--

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"glenn" <gh******@softe ksoftware.com> wrote in message
news:uh******** ******@tk2msftn gp13.phx.gbl...
Well, I'm sorry I asked such a confusing question. The second person
that
responded must have read something you did not as they were much much more
polite and answered the question perfectly... Sorry for the
misunderstandin g. I'm so use to people making comments about how great
things are but providing no details that I might have jumped you too
quickly.

I apologize...

glenn
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:eO******** *****@TK2MSFTNG P14.phx.gbl...
Hi glenn,
> You reply that I'm asking a stupid question


Would you please point out the word "stupid" or any other words in my
message that were insulting to you? In fact, I did NOT think your
question
was stupid, or I wouldn't have spent all that time enumerating the
various
ways of passing data from one page to another.
> not a single example or reference, so all you've done is tell me what I
> already thought I knew. I know what a post var is, and you list it as an > answer but don't provide a way to do it.


Here was your question:
>> Can anyone tell me the best way to take a form with a
>> lastname
>> > and firstname field and pass them through a post to a result page
>> > and
>> then
>> > access those fields values on the result page?


I answered it. In detail. No, I didn't post any examples. Why should I?

Did
you ask for any? When one is talking in general terms, is it wise to

provide
specific examples? Should I assume that you need them? Why?
> I don't mean to be rude, but I have to say that the Microsoft
> community
> is
> the most hostile group of people I've ever dealt with.


Interesting. I made a joke to lighten things up. The joke (a VERY old

joke)
was in no way insulting, but that's how you took it. I would have to
guess
that YOU are the hostile one. And that you lack any sense of humor.
> Microsoft developers
> act like you work with God himself and don't need new users and are
> therefore rude when they ask what you believe to be stupid questions.


A lot of assumptions on your part, and mean-spirited ones at that.
Listen,
bub. I donate my time to help people like you, and spend a good bit of it
making sure I'm giving you the right stuff. I do it out of the goodness
of
my heart. Your attitude sucks. Good luck. You'll need it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.

"glenn" <gh******@softe ksoftware.com> wrote in message
news:u3******** ******@tk2msftn gp13.phx.gbl...
>I appreciate the response however, you are somewhat like a joke
>yourself.
>I
> asked a question. A simple question as none of the books I have answer
> it.
> You reply that I'm asking a stupid question and give me 5 ways to do it
> with
> not a single example or reference, so all you've done is tell me what I
> already thought I knew. I know what a post var is, and you list it as an > answer but don't provide a way to do it. I am glad you answered the
> question, however, instead of stating the obvious next time, why don't you > just stay quiet and let someone with an answer respond.
>
> I don't mean to be rude, but I have to say that the Microsoft
> community
> is
> the most hostile group of people I've ever dealt with. I can see why
> people
> want Linux and Borland to do so well. I have been in Borland Delphi
> for
> 10
> years now and have to say that the people over there are much nicer and
> much
> more helpful to people trying to learn a new product. Microsoft
> developers
> act like you work with God himself and don't need new users and are
> therefore rude when they ask what you believe to be stupid questions.
>
> Thanks for nothing,
>
> glenn
>
>
> "Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
> news:O$******** ******@TK2MSFTN GP14.phx.gbl...
>> > I've had a couple people tell me that I need to do query strings and
> pass
>> > all the values on the form over individually but surely there is a
> better
>> > solution. Can anyone tell me the best way to take a form with a
> lastname
>> > and firstname field and pass them through a post to a result page
>> > and
> then
>> > access those fields values on the result page?
>>
>> This is kind of like that old joke: How do I get to Broadway? (Answer:
>> practice). Although the punch line is a joke, the question is similar.
> There
>> are many ways to "get to Broadway." Taking a cab might not be the best
>> way
>> if you're riding in a bus. Taking the subway is fast, as long as
>> you're
> near
>> a subway station.
>>
>> So, the first issue you will want to know is, what are the various
>> ways
> that
>> data can be passed from one page in an ASP.Net app to another?
>>
>> 1. QueryString. This is useful when you're hyperlinking from one page to > the
>> other, and no security requirement dictates that the data should not
> appear
>> to the user.
>> 2. "Traditiona l" form post. Yes, with ASP.Net you can still post a
>> form
>> to
>> another page, but not a WebForm. This is an unusual case, so I won't
> bother
>> with it.
>> 3. PostBack and Server.Transfer . Post the form back to itself. On the
>> server-side, do a Server.Tranfer to transfer the context to a new
>> page.
> This
>> is useful when you don't want the user to know what data you're passing. >> 4. PostBack and Response.Redire ct. Post the form back to itself. On
>> the
>> server side, do a Response.Redire ct. This sends a header to the
>> browser
>> telling it to request the second URL. This method has the same drawbacks > as
>> number 1.
>> 5. PostBack, store data in Session (or Application, depending upon the
> scope
>> you want), and Redirect or Transfer. This is like numbers 3 and 4, but it >> uses Session space on the server to store the data. This way, no
> QueryString
>> is needed, but you have to be careful about Session Timeouts.
>>
>> That's about all I can think of at the moment. Choose the method that
> works
>> best in a given situation.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> Neither a follower nor a lender be.
>>
>>
>> "glenn" <gh******@softe ksoftware.com> wrote in message
>> news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
>> >I am use to programming in php and the way session and post vars are
>> >past
>> > from fields on one page through to the post page automatically where I > can
>> > get to their values easily to write to a database or continue to
>> > process
>> > on
>> > to the next page.
>> >
>> > I am now trying to learn ASP to see if we can replace some of our
>> > applications that were written in php with an ASP alternative.
>> > However,
>> > after doing many searches on google and reading a couple ASP books
>> > to
> try
>> > to
>> > figure out this simple task I'm still without a solution.
>> >
>> > I've had a couple people tell me that I need to do query strings and
> pass
>> > all the values on the form over individually but surely there is a
> better
>> > solution. Can anyone tell me the best way to take a form with a
> lastname
>> > and firstname field and pass them through a post to a result page
>> > and
> then
>> > access those fields values on the result page?
>> >
>> > Thanks,
>> >
>> > glenn
>> >
>> >
>>
>>
>
>



Nov 19 '05 #8
Having attempted to convert a GET to POST using about half the available
xfer methods (and writing a whole lot of junk code in the process), here's
my opinion on page-to-page in .Net:
1. Don't use QueryString because a) all the variables are in the URL for the
world to see, and b) you are limited by the URL length limitation (we have
an app that hangs and eventually 404s(?) when using Response.Redire ct with
long querystrings)
2. Don't use Context.Items. It seems to work, but because the item info
isn't actually persisted to either the page source (viewstate or POSTed
data) or the URL (QueryString), once the context is gone, the data is lost,
so if you go from page 1 to page 2 to page 3, and then backtrack to page 1,
the Context.Items for that page are lost forever. If it were persisted in
one of those other 3 ways, it would not be
3. Don't use Session. You'll run into some usenet posts where people
suggest that, but a) that isn't what the session is for, and b) it scales
horribly. Imagine the overhead on simply going from Page 1 to Page 2 via
Session var passing. Not too bad, since it's just some serialization of a
string, right? Change your state server to SQLServer and try now. Now put
that state server on a different machine and try again. Now add 4 machines
to your IIS cluster. Try now. Session usage should be minimized throughout
your app, IMO, as you can't count on a full set of events (End goes away in
a cluster), and performance is tremendously variable based on your
particular server configuration, which itself is dynamic while your compiled
code is relatively static.
4. Don't use ViewState for transferring the information because there's too
much work you have to do on your end to get it the data in and out of it
(it's easier to reference the data than in #5), but it's not supposed to be
used for that anyway.
5. Use Server.Transfer , with the preserveForm parameter set to "true". WHat
that last part does is tell the system to keep the various ASP.Net control
fields in the POST header. So let's say Page 1 has "public TextBox
UserName;", if you say from page1, "Server.Transfe r("Page2", true)", from
Page2, you have access to the value of UserName. The catch is that the
Request.Param key name is TextBox's UniqueID, NOT ID, so if this control is
within another control on your page,it will be
Request["ParentControl: UserName"]. I get around this by, upon
Page.PreRender, I call Page.RegisterHi ddenInput("User Name",
Request["ParentControl: UserName"]). This method seems to solve most of the
issues, although figuring out a param name takes some computation + at least
in my case, the naming issues presented by UniqueID mean we have to dump out
an additional POST field, leading to twice the data getting passed.

"sstevens" <ss******@discu ssions.microsof t.com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
Because of the postback architecture that was implemented with ASP.NET,
this
task is not as easy as it once was. If you need to pass data between
pages
there are several options:

1. Use querystring variables
2. Use session variables
3. Use application variables (careful, these are global)
4. Use Server.Transfer (this is may be what you are looking for, see
below)

Page 1
public class Page1 : System.Web.UI.P age
{
private void submitBtn_Click (object sender, System.EventArg s e)
{
//these can be public fields or public properties
//Creating public properties that get private fields
//is a better practice
lastName = "name1";
firstName = "name2";

Server.Transfer ("page2.aspx ");
}
}

Page 2
public class Page2 : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
Page1 myPage1 = (Page1)Context. Handler;
string lastName = myPage1.lastNam e;
string firstName = myPage2.firstNa me;
}
}


"glenn" wrote:
I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I
can
get to their values easily to write to a database or continue to process
on
to the next page.

I am now trying to learn ASP to see if we can replace some of our
applications that were written in php with an ASP alternative. However,
after doing many searches on google and reading a couple ASP books to try
to
figure out this simple task I'm still without a solution.

I've had a couple people tell me that I need to do query strings and pass
all the values on the form over individually but surely there is a better
solution. Can anyone tell me the best way to take a form with a lastname
and firstname field and pass them through a post to a result page and
then
access those fields values on the result page?

Thanks,

glenn

Nov 19 '05 #9
You can't say don't do this don't that, because you really don't know the
context and business requirements for each application. Rather, you should
use a recommendation. For instanace, in item 1, you list
1. Don't use QueryString because a) all the variables are in the URL for
the world to see, Well that is certainly only true if you choose not to encrypt the
querystring. Most applications that are enterprise grade do some form of
encryption in this specific case. So you could rewrite the following as:

Consider encrypting the querystring if application requirements force
querystring usage.

and so on and so forth...
--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
--------------------------------------------------
"Keith Patrick" <ri************ *******@nospam. hotmail.com> wrote in message
news:e1******** ******@TK2MSFTN GP12.phx.gbl... Having attempted to convert a GET to POST using about half the available
xfer methods (and writing a whole lot of junk code in the process), here's
my opinion on page-to-page in .Net:
1. Don't use QueryString because a) all the variables are in the URL for
the world to see, and b) you are limited by the URL length limitation (we
have an app that hangs and eventually 404s(?) when using Response.Redire ct
with long querystrings)
2. Don't use Context.Items. It seems to work, but because the item info
isn't actually persisted to either the page source (viewstate or POSTed
data) or the URL (QueryString), once the context is gone, the data is
lost, so if you go from page 1 to page 2 to page 3, and then backtrack to
page 1, the Context.Items for that page are lost forever. If it were
persisted in one of those other 3 ways, it would not be
3. Don't use Session. You'll run into some usenet posts where people
suggest that, but a) that isn't what the session is for, and b) it scales
horribly. Imagine the overhead on simply going from Page 1 to Page 2 via
Session var passing. Not too bad, since it's just some serialization of a
string, right? Change your state server to SQLServer and try now. Now
put that state server on a different machine and try again. Now add 4
machines to your IIS cluster. Try now. Session usage should be minimized
throughout your app, IMO, as you can't count on a full set of events (End
goes away in a cluster), and performance is tremendously variable based on
your particular server configuration, which itself is dynamic while your
compiled code is relatively static.
4. Don't use ViewState for transferring the information because there's
too much work you have to do on your end to get it the data in and out of
it (it's easier to reference the data than in #5), but it's not supposed
to be used for that anyway.
5. Use Server.Transfer , with the preserveForm parameter set to "true".
WHat that last part does is tell the system to keep the various ASP.Net
control fields in the POST header. So let's say Page 1 has "public
TextBox UserName;", if you say from page1, "Server.Transfe r("Page2",
true)", from Page2, you have access to the value of UserName. The catch
is that the Request.Param key name is TextBox's UniqueID, NOT ID, so if
this control is within another control on your page,it will be
Request["ParentControl: UserName"]. I get around this by, upon
Page.PreRender, I call Page.RegisterHi ddenInput("User Name",
Request["ParentControl: UserName"]). This method seems to solve most of
the issues, although figuring out a param name takes some computation + at
least in my case, the naming issues presented by UniqueID mean we have to
dump out an additional POST field, leading to twice the data getting
passed.

"sstevens" <ss******@discu ssions.microsof t.com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
Because of the postback architecture that was implemented with ASP.NET,
this
task is not as easy as it once was. If you need to pass data between
pages
there are several options:

1. Use querystring variables
2. Use session variables
3. Use application variables (careful, these are global)
4. Use Server.Transfer (this is may be what you are looking for, see
below)

Page 1
public class Page1 : System.Web.UI.P age
{
private void submitBtn_Click (object sender, System.EventArg s e)
{
//these can be public fields or public properties
//Creating public properties that get private fields
//is a better practice
lastName = "name1";
firstName = "name2";

Server.Transfer ("page2.aspx ");
}
}

Page 2
public class Page2 : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
Page1 myPage1 = (Page1)Context. Handler;
string lastName = myPage1.lastNam e;
string firstName = myPage2.firstNa me;
}
}


"glenn" wrote:
I am use to programming in php and the way session and post vars are
past
from fields on one page through to the post page automatically where I
can
get to their values easily to write to a database or continue to process
on
to the next page.

I am now trying to learn ASP to see if we can replace some of our
applications that were written in php with an ASP alternative. However,
after doing many searches on google and reading a couple ASP books to
try to
figure out this simple task I'm still without a solution.

I've had a couple people tell me that I need to do query strings and
pass
all the values on the form over individually but surely there is a
better
solution. Can anyone tell me the best way to take a form with a
lastname
and firstname field and pass them through a post to a result page and
then
access those fields values on the result page?

Thanks,

glenn


Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4520
by: Gerard van Wilgen | last post by:
I have a client-application that uses a socket to post some data to a server-application. The following piece of code in the client takes care of the posting: $sock = fsockopen("www.majstro.com", 80, $errno, $errstr, 30); if ($sock) { $data = 'a=0&b=1'; fputs($sock, "POST /Web/Majstro/SD_Server.php HTTP/1.0\r\n"); fputs($sock, "Host: www.majstro.com\r\n");
0
2459
by: Spud | last post by:
<?php // pullpage function by Nick bouton http://www.nickbouton.com/. $CustomerID = "IDHERE"; $method = "POST"; $host = "xml.mydata.com"; $usepath = "/xml.asp"; //print all vars in an array
0
1628
by: Lucas Branca | last post by:
python 2.1.3 Debian woody Apache 1.3.26 mod python 2.7.8 ## ---- formtest.html ---- ## <form action="/formtest.py/main" method="POST"> <input type="submit" value="go" name="action"> <input type="hidden" name="hide" value="A"> </form>
39
3161
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while learning Python. I have collected those thoughts. I am sure there are many discussions on the "problems" mentioned here. But I had this thoughts without looking into any forums or anything... it is kind of feedback.
6
2022
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following code: #def put_file(file_id, delete=False): # """ Function to put the file on the FTP Server # """ # print " FTP for this file started"
4
1889
by: Sylvain Girard | last post by:
Here's the situation: I need to redirect to another page and post some vars. Response.Redirect doesn't work with post vars (at least not that I know of) and a WebRequest doesn't open the new page (at least not that I know of). How can this thing be resolved? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
1
6701
by: Christopher J. Bottaro | last post by:
Hi, I can't for the life of me figure out how to get the post vars when using basehttpserver. Here's my code: <code> class MyHandler(BaseHTTPRequestHandler): def do_POST(self):
1
1509
by: David Thole | last post by:
Hey all, So far my reading is proving to be very interesting and good. This book is very helpful, and I'm generally left with quite a few questions about how I'm going to do stuff with my current setup. Basically speaking, all my stuff is currently in PHP. I need the ability for being able to interact with PHP quite a bit. My largest question right now, is say that I want to provide some information from my PHP form to the asp one...
2
1532
by: Agent Michael Scarn | last post by:
Hello, I need to be able to dynamically display all of the form names from a form I just submitted. I have a javascript which will display all the names of the form on the first page, but i need them displayed on the post page. Any help would be greatly appreciated!
0
8633
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8947
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8902
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5891
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4392
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.