Button 单击了一次后. 按f5刷新又被执行以下? 有什么办法来解决 刷新执行的问题?

解决方案 »

  1.   

    这是[viewstates]的缘故。。建楼主看看页面的加载过程
      

  2.   

     //差评
        protected void LinkButton2_Click(object sender, EventArgs e)
        {
           
            int id = int.Parse(Request.QueryString["id"]);
            mp = bp.Getmod(id);
            bool b = bp.Updatehuai(id, mp.Huai);
            if (b)
            {
              
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('好评...!');</script>");
                Bind();
              
         
            LinkButton2.Enabled = false;              }
          
     
        }
      

  3.   

    把比的page_load里的代码贴出来看看?
      

  4.   

    ispostback 你设置下断点就可以看出来了,要学会自己设置断点调试。
    欢迎加入.NET 技术群 78817973 加强技术交流。
      

  5.   

            //防止缓存
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
      

  6.   

    重定向 Response.Redirect(Request.RawUrl)
      

  7.   

    一个不是好办法的办法:设定一个COOKIE,执行前读取判断
      

  8.   

    那么多个页面(例如不同窗口,或者不同iframe中的)就会冲突。
      

  9.   

    歪打正着地,我写过的一个“在服务器端保存ViewState”的代码可以在客户端刷新时抛出异常:using System;
    using System.IO;
    using System.Threading;
    using System.Web.UI;public class XVPage : Page
    {
        static private DirectoryInfo _Dir;    private DirectoryInfo Dir
        {
            get
            {
                if (_Dir == null)
                {
                    _Dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data"));
                    if (!_Dir.Exists)
                        _Dir.Create();
                    _Dir = new DirectoryInfo(Path.Combine(_Dir.FullName, "ViewState"));
                    if (!_Dir.Exists)
                        _Dir.Create();
                }
                return _Dir;
            }
        }    protected override object LoadPageStateFromPersistenceMedium()
        {
            PageStatePersister ps = this.PageStatePersister;
            ps.Load();
            if (ps.ControlState != null)
                ps.ControlState = 反序列化对象((string)ps.ControlState);
            if (ps.ViewState != null)
                ps.ViewState = 反序列化对象((string)ps.ViewState);
            return new Pair(ps.ControlState, ps.ViewState);
        }    protected override void SavePageStateToPersistenceMedium(object state)
        {
            PageStatePersister ps = this.PageStatePersister;
            if (state is Pair)
            {
                ps.ControlState = ((Pair)state).First;
                ps.ViewState = ((Pair)state).Second;
            }
            else
                ps.ViewState = state;
            if (ps.ControlState != null)
                ps.ControlState = 序列化对象(ps.ControlState);
            if (ps.ViewState != null)
                ps.ViewState = 序列化对象(ps.ViewState);
            ps.Save();
        }    private object 反序列化对象(string stateID)
        {
            if (stateID == null)
                return null;        object state = Cache[stateID];
            string fname = Path.Combine(Dir.FullName, stateID);
            if (state != null)
            {
                ThreadPool.QueueUserWorkItem(h =>
                {
                    Cache.Remove(stateID);
                    File.Delete(fname);     //这个方法恰好可以禁止浏览器端的“刷新”。
                });
                return state;
            }        return new ObjectStateFormatter().Deserialize(File.ReadAllText(fname));
        }    static long seed1 = DateTime.Now.Ticks;
        static ulong seed2 = 0;    private string 序列化对象(object obj)
        {
            string stateID = seed1.ToString() + "_" + (seed2++).ToString();
            Cache.Insert(stateID, obj, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
            string value = new ObjectStateFormatter().Serialize(obj);
            ThreadPool.QueueUserWorkItem(h =>
            {
                File.WriteAllText(Path.Combine(Dir.FullName, stateID), value);
            });
            return stateID;
        }
    }
      

  10.   

    浏览器的保护功能
    是因为点击了服务器控件,再刷新时,就会提示重试或取消,把该操作用javascript来完成,复杂的操作可以用AJAX来完成
    Response.Write(" <script>window.location.href='Test.aspx'; </script>");  
    http://topic.csdn.net/u/20090325/09/76b2590b-f4b8-420f-bee7-e4fdf77d78c6.html
      

  11.   

    “正常情况下”会执行才对
    没啥好办法解决,抛弃服务器端控件,用ajax吧
      

  12.   

    由于服务器端的ViewState(不论是Cache还是磁盘上的)都被删除,于是就会在浏览器端恶意地重复提交相同的页面时抛出异常。
      

  13.   


    用ajax,在浏览器端被按F5刷新时,又会怎样呢?