zoukankan      html  css  js  c++  java
  • 防刷新.

    一.不错的方法:
    首先.网上关于防刷新的很多. 通用性强的不多,其中有一篇,说出了方法.但是没起到效果. http://www.cnblogs.com/lizhimin/archive/2007/04/24/725337.html

    它是根据: F5 或刷新 不会刷新 客户端 的 Button Click 脚本. 这种方法,当Button 连续点两次,Button 的Click 就不起作用了. 而且. Session无辜的浪费了服务器内存.
    用法:
                if (IsRefreshed == false )
                
    {
                    
    this.Label1.Text = DateTime.Now.ToString();
                }



    二. 更简单的方法:
    Response.Write("<script>window.location = window.location;</script>");

    这种方法也有适用性: 当在当前页面显示出错信息时,或输出内容时, 就不行了. 但是, 可以用 alert 方式.

    三. VS2008 下, 可以用 Ajax1.0 来防刷新. 其实,原理是利用了 不会刷新 客户端脚本.

    只是该方法只能更新 UpdatePannel 里的控件内容, 无法使用 Response 或 UpdatePannel 控件外面的值 .

    尝试的方法失败: 还是利用 客户端不会刷新:

    写一个 Javascript 来提交. 客户端用 HTML 元素来显示操作. 用 服务器端控件来执行方法( 服务器.syle.diplay = "none" )  .

    function __doPostBack_Ex(eventTarget, eventArgument) 
    {
        
    var theform;
        
    if (window.navigator.appName.toLowerCase().indexOf("netscape"> -1{
            theform 
    = document.forms[0];
        }

        
    else {
            theform 
    = document.forms[0];
        }


        
    if(!theform.__EVENTTARGET)
        
    {            
            theform.appendChild(document.createElement(
    "<input type='hidden' name='__EVENTTARGET'>"));
        }

        
        
    if(!theform.__EVENTARGUMENT)
        
    {            
            theform.appendChild(document.createElement(
    "<input type='hidden' name='__EVENTARGUMENT'>"));                        
        }

        
        theform.__EVENTTARGET.value 
    = eventTarget.split("$").join(":");
        theform.__EVENTARGUMENT.value 
    = eventArgument;
        
    if ((typeof(theform.onsubmit) == "function")) 
        
    {
            
    if(theform.onsubmit()!=false)
            
    {
                theform.submit();    
            }

        }

        
    else
        
    {            
            theform.submit();    
        }

    }

    客户端的 Button 里写.
    __doPostBack_Ex(document.getElementById("服务器端控件ID").name) ;

    这样, 还是不能防止刷新.因为. 还是变相的采用提交.

    看来:
    从适用性上来说. 第二种最好.
    从便利性上来说. 第三种最好.


    alarm   作者:NewSea     出处:http://newsea.cnblogs.com/    QQ,MSN:iamnewsea@hotmail.com

      如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。
  • 相关阅读:
    C#中的多态
    反编译工具
    富文本粘贴图片
    [Silverlight入门系列]用TransformToVisual和Transform取得元素绝对位置(Location)
    Silverlight在IIS中的配置
    HubbleDotNet开源全文搜索数据库项目技术详解
    Thank you for choosing Telerik RadRichTextBox
    Asp.net读取AD域信息的方法<转>
    Sharepoint学习笔记—ECMAScript对象模型系列1、ECMAScript对象模型的引入
    SharePoint WebService
  • 原文地址:https://www.cnblogs.com/newsea/p/1108756.html
Copyright © 2011-2022 走看看