当前位置:  开发笔记 > 编程语言 > 正文

在C#中防止页面刷新

如何解决《在C#中防止页面刷新》经验,为你挑选了1个好方法。



1> Saber..:

感谢您的评论并对不起我的错误,我在以下网址找到了此代码:http: //www.codeproject.com/KB/aspnet/Detecting_Refresh.aspx 此次测试;)

    private bool _refreshState;
    private bool _isRefresh;

    protected override void LoadViewState(object savedState)
    {
        object[] AllStates = (object[])savedState;
        base.LoadViewState(AllStates[0]);
        _refreshState = bool.Parse(AllStates[1].ToString());
        _isRefresh = _refreshState == bool.Parse(Session["__ISREFRESH"].ToString());
    }

    protected override object SaveViewState()
    {
        Session["__ISREFRESH"] = _refreshState;
        object[] AllStates = new object[2];
        AllStates[0] = base.SaveViewState();
        AllStates[1] = !(_refreshState);
        return AllStates;
    }

    protected void btn_Click(object sender, EventArgs e)
    {
        if (!_isRefresh)
            Response.Write(DateTime.Now.Millisecond.ToString());
    }

推荐阅读
kikokikolove
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有