关于post vars的asp问题 [英] asp question about post vars

查看:44
本文介绍了关于post vars的asp问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯用php进行编程,会话和帖子的方式已经过去了一两页的字段,直到自动发布的帖子页面我可以获得
get他们的价值很容易写入数据库或继续处理

到下一页。


我现在正在尝试学习ASP,看看我们是否可以替换我们的一些使用ASP替代的用php编写的
应用程序。然而,在google上做了很多搜索并且阅读几本ASP书籍以试图获得这个简单的任务后,我仍然没有解决方案。

>

我有几个人告诉我,我需要查询字符串,然后单独传递

表格上的所有值,但肯定有更好的

解决方案。任何人都可以告诉我使用姓氏

和firstname字段的表单的最佳方式,并通过帖子传递给结果页面然后

访问这些字段值结果页面?


谢谢,


glenn

解决方案

< BLOCKQUOTE>>我有几个人告诉我,我需要查询字符串并传递

表单上的所有值,但肯定有更好的解决方案。任何人都可以告诉我采用姓氏
和名字字段的表单并将它们通过帖子传递到结果页面然后
访问结果页面上的那些字段值的最佳方法吗?


这就像那个老笑话:我怎么去百老汇? (答案:

练习)。虽然妙语是一个笑话,但问题是类似的。

有很多方法可以到达百老汇。乘坐出租车可能不是最好的方式

如果你乘坐公共汽车。坐地铁很快,只要你在地铁站附近就好了。


所以,你要知道的第一个问题是,什么从ASP.Net应用程序中的一个页面传递到另一个页面的各种方式是什么?


1. QueryString。当你从一个页面超链接到

其他页面时,这很有用,并且没有任何安全要求规定数据不应该出现给用户


2.传统表格。是的,使用ASP.Net,您仍然可以将表单发布到另一页的

,但不是WebForm。这是一个不寻常的案例,所以我不打算用它来b / b


3. PostBack和Server.Transfer。将表单发回给自己。在

服务器端,执行Server.Tranfer将上下文传输到新页面。当你不希望用户知道你传递了什么数据时,这个

非常有用。

4. PostBack和Response.Redirect。将表单发回给自己。在

服务器端,执行Response.Redirect。这会向浏览器发送一个标题

告诉它请求第二个URL。此方法与

编号1具有相同的缺点。

5. PostBack,在会话中存储数据(或应用程序,具体取决于范围

你想要的),以及重定向或转移。这就像数字3和4,但是它使用服务器上的会话空间来存储数据。这样,不需要QueryString

,但你必须小心会话超时。


这就是我能想到的全部内容。时刻。在特定情况下选择最适合工作的方法




-

HTH,

Kevin Spencer

Microsoft MVP

..Net开发人员

跟随者和贷款人都不是。

glenn < GH ****** @ softeksoftware.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP14.phx.gbl ...我习惯用PHP编程和方式session和post vars从一个页面的字段到自动发布页面,我可以轻松地将它们的值写入数据库或继续处理
on
>到下一页。

我现在正在尝试学习ASP,看看我们是否可以替换一些用PHP替代的用php编写的应用程序。然而,在google上做了很多搜索并阅读几本ASP书籍后,尝试
来解决这个简单的任务我仍然没有解决方案。
我有几个人告诉我,我需要查询字符串并单独传递表单上的所有值,但肯定有更好的解决方案。任何人都可以告诉我采用姓氏
和名字字段的表单并将其通过帖子传递到结果页面然后
访问结果页面上的那些字段值的最佳方法吗?

谢谢,

glenn



由于使用ASP.NET实现的回发体系结构,这个

任务并不像以前那么容易。如果你需要在页面之间传递数据

有几种选择:


1.使用查询字符串变量

2.使用会话变量

3.使用应用程序变量(小心,这些是全局的)

4.使用Server.Transfer(这可能是你要找的,见下文)< br $>

Page 1

公共类Page1:System.Web.UI.Page

{

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

{

//这些可以是公共字段或公共属性

//创建公共获取私有字段的属性

//是一种更好的做法

lastName =" name1";

firstName =" name2" ;;


Server.Transfer(" page2.aspx");

}

}


Page 2

公共类Page2:System.Web.UI.Page

{

private void Page_Load(object sender,System。 EventArgs e)

{

Page1 myPage1 =(Page1)Context.Handler;

string lastName = myPage1.lastName;

string firstName = myPage2.firstName;

} < br $>
}


" glenn"写道:

我习惯用php进行编程,会话和post vars的方式从一个页面上的字段过去到自动发布的帖子页面我可以
轻松写入数据库或继续处理
到下一页。

我现在正在尝试学习ASP以确定我们是否可以替换我们的一些
用PHP编写的用ASP替代的应用程序。然而,在google上做了很多搜索并阅读几本ASP书籍以试图找出这个简单的任务之后我仍然没有解决方案。

我是'有几个人告诉我,我需要查询字符串并单独传递表单上的所有值,但肯定有更好的解决方案。任何人都可以告诉我采用姓氏
和名字字段的表单并将其通过帖子传递到结果页面然后
访问结果页面上的那些字段值的最佳方法吗?

谢谢,

glenn



我很欣赏回应,但你有点像个笑话你自己。我问b $ b问了一个问题。一个简单的问题,因为我没有回答它的书。

你回答说我问了一个愚蠢的问题并给我5种方法来做

not not一个例子或参考,所以你所做的只是告诉我我认为我知道的是什么。我知道post var是什么,你把它列为

答案但是没有办法做到这一点。我很高兴你回答了

的问题,然而,不是说下一次显而易见的事情,为什么不给你?b $ b只是保持安静,让有回答的人回答。


我不是故意粗鲁,但我不得不说微软社区是我最吵闹的人群。曾经处理过。我可以看到为什么人们希望Linux和Borland能够做到这一点。我现在已经在Borland Delphi工作了10年,而且不得不说那边的人有更多更好更多

对于试图学习新产品的人更有帮助。微软开发人员

表现得就像你自己与上帝一起工作而且不需要新用户,因此当他们问你认为什么是愚蠢的问题时,他们是粗鲁无礼的。 />

一无所获,


glenn

" Kevin Spencer" <柯*** @ DIESPAMMERSDIEtakempis.com>在消息中写道

news:O


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

解决方案

> 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. "Traditional" 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.Redirect. Post the form back to itself. On the
server side, do a Response.Redirect. 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******@softeksoftware.com> wrote in message
news:%2****************@TK2MSFTNGP14.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



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.Page
{
private void submitBtn_Click(object sender, System.EventArgs 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.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Page1 myPage1 = (Page1)Context.Handler;
string lastName = myPage1.lastName;
string firstName = myPage2.firstName;
}
}


"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



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***@DIESPAMMERSDIEtakempis.com> wrote in message
news:O


这篇关于关于post vars的asp问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆