c#中的页面退出功能 [英] page exit function in c#

查看:69
本文介绍了c#中的页面退出功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai大家,

我是faizel,我现在正在做一个网站。我只是想知道是否有像page_load()函数一样的页面退出函数。当我退出网页时,任何人都可以告诉我一种使用静态变量重置计数器的方法。我尝试在页面加载功能中执行此操作,但是当我单击一个按钮时它会重置。我希望计数器在页面退出时重置。这是我的代码。

hai everybody,
I am faizel and i am right now doing a website. i just want to know whether there is any page exit function just like page_load() function. can any one tell me a way to reset a counter using static variable when i exit a webpage. i tried to do it in the page load function but when i click a button it resets .i want the counter to reset when the page is exited.here is my code.

static int x;

    protected void Page_Load(object sender, EventArgs e)
    {
x=0;
}
//button click
protected void Button8_Click(object sender, EventArgs e)
    {
        
        x = x + 6;
        
    }
 protected void Button7_Click(object sender, EventArgs e)
    {
        x = x - 6;
        
    }

推荐答案





在page_load方法中添加ispostback条件。



Hi,

add ispostback condition in page_load method.

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
        x=0;
}







这将解决您的问题。



谢谢。




It will solve your problem.

Thanks.


是的,有写page_unload方法,你可以在页面即将卸载你的方法时进行编码将被称为...问候:)
yes there is write page_unload method where you can do your coding when page is about to unload your method will be called...regards :)


看到它..

http://stackoverflow.com/questions/375406/programmatically-close-aspx-page-from-code-behind [ ^ ]


这篇关于c#中的页面退出功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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