问题描述
您好,专家,
我正在开发c Sharp asp.net应用程序.
其中有一页 subscribe.aspx
在此页面中,用户填写信息.经过所有验证后,当用户单击提交"时,我会将这些数据发送到subscribepost.aspx
页面进行进一步处理.此页面包含页面加载时的插入代码和其他一些代码.
现在我很困惑.我已经在简单的页面加载中编写了此代码.
这是正确的方法还是我必须在 IsPostBack block
中编写它
请帮帮我.
预先感谢
Hi Expert ,
I am developing c sharp asp.net application.
In this there is one page subscribe.aspx
In this page user fill information. after all validation, when user clicks submit, I am sending this data to subscribepost.aspx
page for further processing. This page contains insert code on page load and some other code.
Now I am confused. I had written this code on simple pageload.
IS it right approach or I have to write it in IsPostBack block
Please help me.
Thankssssssssssss in advance
推荐答案
If(!IsPostBack)
{
//Write that code which is to be called only on first page load and not
//everytime page postback occurs.
}
//Rest of the code will go here after the curly braces.
//Remember, this code will be called everytime page loads
//May it be Postback, first page load.
希望这会有所帮助.
一切顺利.
Hope this helps.
All the best.
IsPostBack property indicates that whether this is the first time user has requested for the page or it is reloaded based on any response on postback.
This property checks for __VIEWSTATE or __EVENTTARGET parameter in Request object. if these parameters are absent that means it is requested for the first time and if these parameters are present then this request is not first request.
ispostback内部的代码将首次执行,如果您单击页面上的任何其他控件(如按钮单击),则不会调用ispostback部分内部的代码.
Code inside the ispostback will execute the first time,if you are clicking any other control of the page like button click then code inside the ispostback section would not called.
这篇关于如何确定IsPostBack的代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!