回发和页面加载的区别 [英] Difference of postback and pageload

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

问题描述

嗨...
我知道什么是回发,但不知道为什么需要回发.几乎页面加载还会将我们的页面详细信息加载到服务器,那么回发有什么用?请解释两者的区别...

Hi...
I got the idea of what is postback,but dont know why we need it. Almost pageload also loads our page details to server,then what is the use of postback? Plz explain difference of both...

推荐答案


在每次页面加载中,您都不想加载数据.这就是为什么我们使用
Hi,
In every page load you do not want to load the data.thats why we use
Ispostback

属性.

请阅读以下帖子.

http://delphi.about.com/library/weekly/aa051705a.htm [ ^ ]

在ASP.NET中检测刷新或回发 [ ^ ]

property.

plese read following posts.

http://delphi.about.com/library/weekly/aa051705a.htm[^]

Detecting Refresh or Postback in ASP.NET[^]


PostBack是为将ASP.NET页提交到服务器进行处理的过程而指定的名称.如果要根据数据库检查页面的某些凭据(例如,验证用户名和密码),则执行PostBack.这是客户端计算机无法完成的事情,因此这些详细信息必须回发"到服务器. MSDN在以下链接中非常清楚地描述了页面生命周期.请仔细检查.

http://msdn.microsoft.com/en-us/library/ms178472.aspx [ ^ ]

其他一些参考资料:

http://www. shoutasp.net/discussions/p344/What-methods-are-fired-during-the-page-load-in-ASP-Net.aspx [ ^ ]

http://www.c-sharpcorner.com/uploadfile/2f73dd /what-is-postback-in-Asp-Net/ [ http://www.evagoras.com/2011/02/10 /how-postback-works-in-asp-net/ [
PostBack is the name given to the process of submitting an ASP.NET page to the server for processing . PostBack is done if certain credentials of the page are to be checked against a database (such as verification of username and password). This is something that a client machine is not able to accomplish and thus these details have to be ‘posted back’ to the server. MSDN describes the page life cycle very clearly in the following link. Please go through it.

http://msdn.microsoft.com/en-us/library/ms178472.aspx[^]

Some other references:

http://www.shoutasp.net/discussions/p344/What-methods-are-fired-during-the-page-load-in-ASP-Net.aspx[^]

http://www.c-sharpcorner.com/uploadfile/2f73dd/what-is-postback-in-Asp-Net/[^]

http://www.evagoras.com/2011/02/10/how-postback-works-in-asp-net/[^]

Regards,
Vani




PageLoad和PostBack都是页面生命周期事件..

首先发生PageLoad事件,然后发生PostBack.

回发是页面加载的一部分,只有在加载页面时才会发生..


换句话说,如果没有页面加载,则意味着没有按钮之类的html元素
已加载,并且由于未加载任何按钮,因此没有单击事件,因此不会发生回发.



例如:

受保护的空白Page_Load(对象发送者,EventArgs e)
{
if(!Page.IsPostBack)//表示没有回发..page第一次加载
{
//此循环仅在首次加载页面时发生..
//在这里,您可以将只需要运行一次的代码或函数放入
FunctionPageFirstLoad() ;
}

if(Page.IsPostBack)//其回发..page已被加载一次
{
//此循环仅在页面加载后才出现
//是点击事件,可能来自按钮点击,
FunctionPageEventClickLoad() ;
}
}


私人void FunctionPageFirstLoad()
{
//第一次加载页面时,仅调用一次此函数.
}
私人void FunctionPageEventClickLoad()
{
//每当任何按钮或其他元素发生点击事件时,都会调用此函数.
}


Both PageLoad and PostBack are page life cycle event..

The PageLoad event occurs first and then PostBack.

Post back is a part of page load which can happen only when the page is loaded..


in other words if there is no page load then it means no html elements like buttons
are loaded and since no buttons are loaded so no click event and so no postback can happen.



for eg:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) //means no postback..page loaded first time
{
//this loop will happen only when the page is loaded for first time..
//here u can put the code or function which you want only once to run
FunctionPageFirstLoad();
}

if (Page.IsPostBack) //its a postback..page has already beenloaded once
{
//this loop will happen only when the page has loaded and then there
//is a click event, may be from button click,
FunctionPageEventClickLoad();
}
}


private void FunctionPageFirstLoad()
{
//this function will be call only once when the page is loaded for the first time.
}
private void FunctionPageEventClickLoad()
{
//this function will be called every time when there is a click event from any button or other element.
}


这篇关于回发和页面加载的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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