本文介绍了如何禁用页面刷新按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友....

我在开发项目时遇到问题,请尝试帮助我...
问题是如何在页面加载后禁用刷新键(F5和Enter键)?

Hi Friends....

I have a problem with developing a project, Please try to help me...
That problem is how to disable the refresh key(F5 & Enter key) after page loaded?

推荐答案

<div>
       <asp:label id="Label1" runat="server" text="Label" xmlns:asp="#unknown"></asp:label><br />
       <br />
       <asp:button id="Button1" runat="server" onclick="Button1_Click" text="Button" xmlns:asp="#unknown" /></div>





protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
       }


   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
       {
           Label1.Text = "Hello";
           Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
           string str = "your code will save here or call save() method here";

       }
       else
       {
           Label1.Text = "Page Refreshed";
                   }

   }
   protected void Page_PreRender(object sender, EventArgs e)
   {
       ViewState["CheckRefresh"] = Session["CheckRefresh"];
   }



此代码不会禁用F5& EnterKey按钮

刷新浏览器或F5时可以保存您的代码保存的句柄.



this code not disable F5 & EnterKey button

it''s handle to save ur code safly when browser refresh or F5.


这篇关于如何禁用页面刷新按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:03