页面上有5个点击上传文件的按钮,都能够进行文件上传。当点击其中一个按钮后,按F5刷新会重复上传。因为要保证回传后其他文本框的值保留不变,不能点击按钮后重定向 。  这问题怎么解决?

解决方案 »

  1.   

    重定向回当前页面可以解决该问题
    或改用Ajax上传文件吧.
      

  2.   

    异步上传才行,或者用iframe来做每一个上传,有多少附件就用多少个iframe
      

  3.   

    我的也是和你一样的 做了个商品信息的管理 没有用ajax  直接用的if(!ispostback) 这是可以的
      

  4.   

    实在不行在想办法用ajax。。
      

  5.   

    因为有5个按钮哦,如果if(!ispostback),那么只能上传一个文件啊 !!!!!
    请高手指点!!
      

  6.   

    不知道 用viewstate能不能实现?
      

  7.   

    我就郁闷了!我写的!直接屏蔽F5!
    网上有案例都不行!
    <script type="text/javascript">
    function doZoom(size) {
    document.getElementById('zoom').style.fontSize=size+'px';
    }
    </script>
    <script type="text/javascript">
    window.onload=function()
    {
     window.onkeydown=function(e)
     {
       if(e.which)
       {
         if(e.which==116)
     {    
           return false;    
     }
       }
     else if(event.keyCode)
     {
      if(event.keyCode==116)
      {
        return false;   
      }
     }
     } 
    }
    </script>直接添加在方案里就ko!不用AJAX!瞎说!
      

  8.   

    http://blog.163.com/mengfanzong@126/blog/static/1294871382010238312318/
      

  9.   

    javascript治标不治本啊,如果把javascript给屏蔽 了,就不起作用了
      

  10.   

    找到不错的代码了!using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;namespace Space
    {
        public class RefreshPage : System.Web.UI.Page
        {
            //private static ILog log = LogManager.GetLogger(typeof(RefreshServe));
            private readonly string REFRESH_TICKET_NAME = "__RefreshTicketArray";
            private readonly string HIDDEN_FIELD_NAME = "__RefreshHiddenField";
            private readonly string HIDDEN_PAGE_GUID = "__RefreshPageGuid";        /// <summary>        
            /// 为True表示页面刷新,False为正常提交        
            /// </summary>
            /// 
            public bool IsPageRefreshed
            {
                get
                {
                    if (IsPostBack && !CheckRefreshFlag())
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }        /// <summary>        
            /// 呈现前更新标识       
            /// /// </summary>        
            /// <param name="e"></param> 
            /// 
            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
                UpdateRefreshFlag();
            }        private void UpdateRefreshFlag()
            {
                #region Cookie模式
                //注册页面唯一标识并返回
                string pageGuid = SetCurPageGuid();
                HttpCookie cookie = GetRefreshTicket();
                if (cookie.Values.Count > 0)
                {
                    cookie.Values.Remove(pageGuid);
                }
                string submitTime = DateTime.Now.ToString("hhmmss.fffff");            //当前提交时间保存到隐藏域     
                ClientScript.RegisterHiddenField(HIDDEN_FIELD_NAME, submitTime);
                cookie.Values.Add(pageGuid, submitTime);
                for (int i = 0; i < cookie.Values.Count; i++)
                    Response.AppendCookie(cookie);
                #endregion
            }        private bool CheckRefreshFlag()
            {
                HttpCookie cookie = GetRefreshTicket();
                string pageGuid = GetCurPageGuid();
                if (cookie.Values.Count > 0)
                {
                    bool flag;
                    if (cookie.Values[pageGuid] != null)
                        flag = cookie.Values[pageGuid].IndexOf(GetCurSubmitTime()) > -1;
                    else
                        flag = true;//防止出现异常,总是可以提交 
                    return flag;
                }
                return true;
            }
            private HttpCookie GetRefreshTicket()
            {
                #region Cookie模式,返回值为Cookie
                HttpCookie cookie;
                if (Request.Cookies[REFRESH_TICKET_NAME] == null)
                {
                    cookie = new HttpCookie(REFRESH_TICKET_NAME);
                    Response.AppendCookie(cookie);
                }
                else
                {
                    cookie = Request.Cookies[REFRESH_TICKET_NAME];
                }
                return cookie;
                #endregion
            }        private string GetCurSubmitTime()
            {
                string submitTime = Request.Params[HIDDEN_FIELD_NAME] == null ? "" : Request.Params[HIDDEN_FIELD_NAME].ToString();
                return submitTime;
            }        private string SetCurPageGuid()
            {
                string guid;
                if (!IsPostBack)
                {
                    if (Request.Params[HIDDEN_PAGE_GUID] == null)
                    {
                        guid = System.Guid.NewGuid().ToString();
                    }
                    else
                        guid = GetCurPageGuid();
                }
                else
                {
                    guid = GetCurPageGuid();
                }
                ClientScript.RegisterHiddenField(HIDDEN_PAGE_GUID, guid);
                return guid;
            }        private string GetCurPageGuid()
            {
                string pageGuid = Request.Params[HIDDEN_PAGE_GUID] == null ? "none" :
                    Request.Params[HIDDEN_PAGE_GUID].ToString();
                return pageGuid;
            }
        }
    }
      

  11.   

    也来看看, 我也遇到过页面刷新重复提交的问题, 费了点力气在网上找了点资料, 开始什么都不知道, 
      (!ispostback) 根本就不能解决Submit, 它只能对于页面加载中的操作进行限制, 不能限制Submit 事件触发的, 使用脚本没有试过, 每次刷新页面的时候都会触发页面周期里面的  Page_PreRender事件,    private string Identifier
        {
            get
            {
                var x = ViewState["code"];
                if (x == null)
                {
                    x = Guid.NewGuid().ToString();
                    ViewState["code"] = x;
                }
                return (string)x;
            }
        }    private int NextNum1
        {
            get
            {
                var x = Session["Identifier"];
                if (x == null)
                {
                    x = NextNum2;
                    Session["Identifier"] = x;
                }
                return (int)x;
            }
            set
            {
                Session["Identifier"] = value;
                NextNum2 = value;
            }
        }    private int NextNum2
        {
            get
            {
                var x = ViewState["step"];
                if (x == null)
                {
                    x = 1;
                    ViewState["step"] = x;
                }
                return (int)x;
            }
            set
            {
                ViewState["step"] = value;
            }
        }    public bool IsRefresh
        {
            get
            {
                return NextNum2 < NextNum1;
            }
        } protected void Page_PreRender(object sender, EventArgs e)
        {
            NextNum1++;
        }
    protected void Button1_OnClick(object sender, EventArgs e)
        {
            if (IsRefresh)
            {
                Response.Write(DateTime.Now.ToLongTimeString()); 
            }    }大家可以试试 有意见可以给我留言 ! ,