C# 如果页面没有回发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8836697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
If page is not postback
提问by el ninho
I know this:
我知道这个:
if (!IsPostBack)
{
do something
}
But what if I need to do something if page is NOT postback? Do I use else or there is other/better way??
但是,如果页面没有回发,我需要做些什么呢?我是使用 else 还是有其他/更好的方法?
采纳答案by ridvanzoro
You can "add return;"
您可以“添加退货”;
if (!IsPostBack)
{
do something
return;
}
//it means else
回答by Lost_In_Library
If page is not post back, you(server-side) don't want to do anything... (For this user)-> Server have to wait until new command comes from client-side(user).
如果页面没有回发,你(服务器端)不想做任何事情......(对于这个用户)-> 服务器必须等到新命令来自客户端(用户)。
If you want to do a thing() that is not accourding with user-request, you can do it with a server-service etc. ( An ex.; Server service: server side folder(image resizer) <-> there is no need to postback )
如果你想做一个不符合用户请求的东西(),你可以用服务器服务等来做(例如;服务器服务:服务器端文件夹(图像调整器)<->没有需要回发)
Sorry for my english, but you get the idea, Am I right?
对不起我的英语,但你明白了,我说得对吗?
回答by Dennis Traub
The most obvious solution would probably look something like this:
最明显的解决方案可能看起来像这样:
if (IsPostBack) {
// It is a postback
} else {
// It is not a postback
}
回答by George Johnston
Using elseis the solution to your problem here.
使用else是这里问题的解决方案。
if (!IsPostBack)
{
} else {
{
// Is a post back
}
回答by AFatBunny
There are several different solutions:
有几种不同的解决方案:
Using two separate ifstatements:
使用两个单独的if语句:
if (IsPostBack){
// is a post back
}
if (!IsPostBack){
// is not a post back
}
Using either of the following ifelsestatements:
使用以下任一ifelse语句:
if (IsPostBack){
// is a post back
} else {
// is not a post back
}
OR
或者
if (!IsPostBack){
// is not a post back
} else {
// is a post back
}
Using either of the following returnstatements:
使用以下任一return语句:
if (IsPostBack){
// is a post back
return;
}
// is not a post back
OR
或者
if (!IsPostBack){
// is not a post back
return;
}
// is a post back

