什么是回发? [英] What is Postback?

查看:95
本文介绍了什么是回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已经被问过并被回答了数千次。作为一个事实,我知道我需要说


如果不是Page.IsPostBack那么

''做一些东西

结束如果需要由Web服务器处理的东西需要
。我仍然很难理解这个回发逻辑,并希望有一些

大师可以帮助我澄清我的困惑。

我确实读过很多关于此的文章/帖子,但仍然无法清楚地理解这个术语。


MSDN文档以下网址说:

http://msdn.microsoft.com/library/de...tBackTopic.asp

Page.IsPostBack Property

获取一个值,该值指示是否正在加载页面以响应

a客户端回发,或者是否正在加载和访问第一个页面

时间。

I know that this has been asked and answered thousands of times. As a
matter of fact, I know that I need to say

If Not Page.IsPostBack Then
''Do something
End If

for things that needs to be processed by the web server. I am still
struggling to understand this postback logic, and hope that some kind
gurus out there could help me clarify the confusion I have.

I did read quite some articles/posts about this, but still could not
clearly understand this terminology.

The MSDN documentation at the following URL says:

http://msdn.microsoft.com/library/de...tBackTopic.asp

Page.IsPostBack Property
Gets a value indicating whether the page is being loaded in response to
a client postback, or if it is being loaded and accessed for the first
time.


>根据我的理解,毫无疑问postback"意味着
>From my understanding, there is no doubt that "postback" means that



一些信息已经从客户端的
传输到Web服务器。


但究竟是什么意思是正在加载和访问第一个

时间?如何第一次界定?如果我填写

页面上的表格并将其提交给服务器,这是回复还是不回复?当

服务器处理表单并将其返回给客户端时,这是

第一次还是没有?由于返回的页面可能与原始页面不同。


例如,如果我有一个名为test.aspx的页面。当用户将以下URL的

放入他/她的浏览器的地址栏时:

http://www.someserver.com/test.aspx

Web服务器获取此请求并编译test.aspx页面和

将生成的HTML发送回客户端。


到目前为止,好的,没有问题。这绝对是访问或加载test.aspx的第一个

时间。


现在,假设用户在
test.aspx页面并点击提交页面用于更新他/她的个人资料的按钮。

通常在这种情况下,我们附上提交按钮的

EventHandler的实现


如果不是Page.IsPostBack然后

''做点什么

结束如果


这正是它困惑的地方我(也许还有很多其他人)。

这个如果没有条件与我对

逻辑的理解完全相反。相反,我认为应该是,


如果Page.IsPostBack然后

''做点什么

结束如果


因为,在用户填写他/她的个人资料信息并点击

提交之后按钮,这个数据提交是不是一个回发?所以,当然,我们应该在我们的代码中说明,如果这是一个回发,请执行此操作并且

这个。

但是,与我的理解相反,为了使网络服务器真正更新用户配置文件,我们需要声明,如果这是

不是回发,请执行此操作。嘿,如果来自客户的更新请求

不是回发,那么什么是回发?


任何一位大师请澄清回发?

some bits of information has been transmitted to the Web server from
the client.

But what exactly is meant by "being loaded and accessed for the first
time"? How is "for the first time" defined? If I fill up the forms on
a page and submit it to server, is this a postback or no? And when the
server processes the form and returns it to the client, is this the
first time or no? Since the returned page would likely be different
from the original one.

For example, if I have a page called test.aspx. When a user puts the
following URL into the address bar of his/her browser:

http://www.someserver.com/test.aspx

The web server gets this request and compiles the test.aspx page and
sends the resulting HTML back to the client.

Up to this point, OK, there is no problem. This is absolutely the first
time that test.aspx is being accessed or loaded.

Now, suppose that the user enters some user profile information on
test.aspx page and hits the "Submit" button to update his/her profile.
And usually in this case, we enclose our implementation of the
EventHandler of the Submit button with

If Not Page.IsPostBack Then
''Do something
End If

This is exactly where it confuses me (and maybe many others out there).
This "If Not" condition is exactly opposite to my understanding of the
logic. Instead, I think it should be,

If Page.IsPostBack Then
''Do something
End If

Because, after the user fills up his/her profile info and hits the
"Submit" button, isn''t this data-submission a postback? So, naturally,
we should state in our code, "if this is a postback, please do this and
this."

But, contrary to my understanding, in order for the web server to
really update the user profile, we are required to state, "if this is
not a postback, please do this and this." Hey, if an updating request
from a client is NOT a postback, then what is a postback?

Any kind guru please clarify postback?

推荐答案

你的混淆根本不是关于回发的内容,我认为你这个b $ b有足够的清晰度。您的混淆就是If语句用于



If Not Page.IsPostBack中的代码第一次加载页面

时执行块。这用于设置页面中

控件的初始值。当页面加载回发时,你不希望

初始化控件,因为你希望它们从用户发布的

数据中获取它们的值。


如果您想在页面加载

回发时想要做某事,可以使用If Page.IsPostBack。声明,正如你想象的那样。但是,这并没有被大量使用,这就是为什么你在例子中很少看到

的原因。通常你使用提交按钮的click事件来

在回发时执行任何操作。

*********** @ yahoo.com 写道:
Your confusion is not at all about what a postback is, I think that you
have that clear enough. Your confusion is just what the If statement is
used for.

The code in the "If Not Page.IsPostBack" block is executed when the page
is loaded for the first time. This is used to set the initial values for
controls in the page. When the page loads for a postback, you don''t want
to initialise the controls as you want them to get their values from the
data that the user posted.

If you instead want to do something when the page is loaded for a
postback, you use an "If Page.IsPostBack" statement, just as you
thought. This is not used very much, though, that''s why you rarely see
it in examples. Usually you use the click event for the submit button to
perform anything on postback.

an***********@yahoo.com wrote:

我知道这有被问到并回答了数千次。作为一个事实,我知道我需要说


如果不是Page.IsPostBack那么

''做一些东西

结束如果需要由Web服务器处理的东西需要
。我仍然很难理解这个回发逻辑,并希望有一些

大师可以帮助我澄清我的困惑。

我确实读过很多关于此的文章/帖子,但仍然无法清楚地理解这个术语。


MSDN文档以下网址说:

http://msdn.microsoft.com/library/de...tBackTopic.asp

Page.IsPostBack Property

获取一个值,该值指示是否正在加载页面以响应

a客户端回发,或者是否正在加载和访问第一个页面

时间。
I know that this has been asked and answered thousands of times. As a
matter of fact, I know that I need to say

If Not Page.IsPostBack Then
''Do something
End If

for things that needs to be processed by the web server. I am still
struggling to understand this postback logic, and hope that some kind
gurus out there could help me clarify the confusion I have.

I did read quite some articles/posts about this, but still could not
clearly understand this terminology.

The MSDN documentation at the following URL says:

http://msdn.microsoft.com/library/de...tBackTopic.asp

Page.IsPostBack Property
Gets a value indicating whether the page is being loaded in response to
a client postback, or if it is being loaded and accessed for the first
time.

>>根据我的理解,毫无疑问回发意味着
>>From my understanding, there is no doubt that "postback" means that



一些信息已经从客户端的
传输到Web服务器。


但究竟是什么意思是正在加载和访问第一个

时间?如何第一次界定?如果我填写

页面上的表格并将其提交给服务器,这是回复还是不回复?当

服务器处理表单并将其返回给客户端时,这是

第一次还是没有?由于返回的页面可能与原始页面不同。


例如,如果我有一个名为test.aspx的页面。当用户将以下URL的

放入他/她的浏览器的地址栏时:

http://www.someserver.com/test.aspx

Web服务器获取此请求并编译test.aspx页面和

将生成的HTML发送回客户端。


到目前为止,好的,没有问题。这绝对是访问或加载test.aspx的第一个

时间。


现在,假设用户在
test.aspx页面并点击提交页面用于更新他/她的个人资料的按钮。

通常在这种情况下,我们附上提交按钮的

EventHandler的实现


如果不是Page.IsPostBack然后

''做点什么

结束如果


这正是它困惑的地方我(也许还有很多其他人)。

这个如果没有条件与我对

逻辑的理解完全相反。相反,我认为应该是,


如果Page.IsPostBack然后

''做点什么

结束如果


因为,在用户填写他/她的个人资料信息并点击

提交之后按钮,这个数据提交是不是一个回发?所以,当然,我们应该在我们的代码中说明,如果这是一个回发,请执行此操作并且

这个。

但是,与我的理解相反,为了使网络服务器真正更新用户配置文件,我们需要声明,如果这是

不是回发,请执行此操作。嘿,如果来自客户的更新请求

不是回发,那么什么是回发?


任何一位大师请澄清回发?

some bits of information has been transmitted to the Web server from
the client.

But what exactly is meant by "being loaded and accessed for the first
time"? How is "for the first time" defined? If I fill up the forms on
a page and submit it to server, is this a postback or no? And when the
server processes the form and returns it to the client, is this the
first time or no? Since the returned page would likely be different
from the original one.

For example, if I have a page called test.aspx. When a user puts the
following URL into the address bar of his/her browser:

http://www.someserver.com/test.aspx

The web server gets this request and compiles the test.aspx page and
sends the resulting HTML back to the client.

Up to this point, OK, there is no problem. This is absolutely the first
time that test.aspx is being accessed or loaded.

Now, suppose that the user enters some user profile information on
test.aspx page and hits the "Submit" button to update his/her profile.
And usually in this case, we enclose our implementation of the
EventHandler of the Submit button with

If Not Page.IsPostBack Then
''Do something
End If

This is exactly where it confuses me (and maybe many others out there).
This "If Not" condition is exactly opposite to my understanding of the
logic. Instead, I think it should be,

If Page.IsPostBack Then
''Do something
End If

Because, after the user fills up his/her profile info and hits the
"Submit" button, isn''t this data-submission a postback? So, naturally,
we should state in our code, "if this is a postback, please do this and
this."

But, contrary to my understanding, in order for the web server to
really update the user profile, we are required to state, "if this is
not a postback, please do this and this." Hey, if an updating request
from a client is NOT a postback, then what is a postback?

Any kind guru please clarify postback?


G?ran Andersson写道:
G?ran Andersson wrote:

你的混淆根本不是关于回发是什么,我认为你

已经足够清楚了。您的混淆就是If语句用于



If Not Page.IsPostBack中的代码第一次加载页面

时执行块。这用于设置页面中

控件的初始值。当页面加载回发时,你不希望

初始化控件,因为你希望它们从用户发布的

数据中获取它们的值。


如果您想在页面加载

回发时想要做某事,可以使用If Page.IsPostBack。声明,正如你想象的那样。但是,这并没有被大量使用,这就是为什么你在例子中很少看到

的原因。通常你使用提交按钮的click事件来支持
在回发时执行任何操作。
Your confusion is not at all about what a postback is, I think that you
have that clear enough. Your confusion is just what the If statement is
used for.

The code in the "If Not Page.IsPostBack" block is executed when the page
is loaded for the first time. This is used to set the initial values for
controls in the page. When the page loads for a postback, you don''t want
to initialise the controls as you want them to get their values from the
data that the user posted.

If you instead want to do something when the page is loaded for a
postback, you use an "If Page.IsPostBack" statement, just as you
thought. This is not used very much, though, that''s why you rarely see
it in examples. Usually you use the click event for the submit button to
perform anything on postback.



非常感谢你。但我还不清楚。所以你建议在

普通英语中,If Not Page.IsPostBack只是意味着如果这个页面是

第一次加载?


所以,换句话说,如果我有


如果不是Page.IsPostBack那么

''用最新存储的会话值填充文本框。

结束如果


我说,如果这个页面是第一次加载,请填写

文本框与用户刚刚提供的任何信息?


然后,在什么样的情况下,页面不被认为是首次加载



Thank you so much. But I am still not clear. So you suggest that in
plain English, "If Not Page.IsPostBack" simply means "If this page is
being loaded for the first time"?

So, in other words, if I have

If Not Page.IsPostBack Then
''populate the textboxes with the latest stored session values.
End If

I am saying, "If this page is loaded for the first time, please fill up
the textboxes with whatever info the user has just supplied?"

Then, in what kind of situations, a page is NOT considered being loaded
for the first time?

< an *********** @ yahoo.comwrote in message

news:11 *************** ****** @ i42g2000cwa.googlegro ups.com ...
<an***********@yahoo.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...

然后,在什么样的情况下,页面不被视为正在加载

第一次?
Then, in what kind of situations, a page is NOT considered being loaded
for the first time?



当它被回发时。


考虑一个显示从数据库获取的记录的页面,以便

的用户可以编辑它。


1)当页面首次加载时(即它没有被回复给自己

服务器端处理),它从数据库中获取记录,并且

显示其各个字段供用户编辑,可能在TextBox中,

DropDownList,CheckBox webcontrols或者其他。


2)用户进行更改等,然后单击保存按钮。


3)单击保存按钮会导致要回发给自己的页面,

持久保存新编辑的值,以便将它们写回

数据库。

非常你想在这里做的最后一件事是来自

数据库的当前记录,可能会覆盖所有用户必须的编辑

制作!!!


因此,执行该操作的代码被IsPostBack逻辑包围,因此

当页面被回发时它不会运行。


现在这是否清楚。 ..?

When it''s being posted back.

Consider a page which displays a record fetched from a database so that the
user can edit it.

1) When the page first loads (i.e. it is NOT being posted back to itself for
server-side processing), it fetches the record from the database and
displays its various fields for the user to edit, maybe in TextBox,
DropDownList, CheckBox webcontrols or whatever.

2) The user makes the changes etc and then clicks the Save button.

3) Clicking on the Save button causes the page to post back to itself,
persisting the newly edited values so that they can be written back to the
database.
THE VERY LAST THING YOU WANT TO DO HERE IS FETCH THE CURRENT RECORD FROM THE
DATABASE AND POTENTIALLY OVERWRITE ALL THE EDITS THAT THE USER HAS JUST
MADE!!!

Therefore, the code which does that is surrounded by the IsPostBack logic so
that it DOES NOT RUN when the page is being posted back.

Is this clear now...?


这篇关于什么是回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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