避免在javascript中使用刷新按钮 [英] avoid refresh button in javascript

查看:85
本文介绍了避免在javascript中使用刷新按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要避免页面refresh.so,如果用户刷新页面,我需要重定向错误页面.实际上,在我的项目中,当用户单击提交"按钮以执行某些操作时,我重定向了另一页面以显示计时器.我们设置了计时60秒内,用户ve在此时间内填写表格.当时间到时,表格消失并自动提交.但是,当用户单击刷新"按钮时,它将再次显示该表格.

因此,我需要避免执行刷新操作并重定向错误页面.我该怎么办?

I want to avoid page refresh.so , if user refresh the page i need to redirect error page .Actually in my project when user click submit button for some action , i redirect another page to show the timer.we set the timing 60 sec and user ve to fill the form within that time .when the time is over the form get disappear and submit automatically.but when the user click refresh button ,it shows the form again.

so i need to avoid the refresh action and redirect the error page. How can i do?

推荐答案

尝试一下

try this

//this is only c# code
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"];
    }


使用以下脚本可能会帮助您

Use Below script it may help you

<script type="text/javascript">  
    function initAll()  
    {      
        alert("Welcome Sucker");  
    }  
    function alertUser()  
    {  
        inputelement = document.getElementsByTagName("input");      
        alert(inputelement[0].value);  
        return false;
    }  
    </script>  
</head>  
<body onload=initAll()>  
<h3 align="center">  
Welcome  
<br /><br />  
<form onSubmit="return alertUser()">  
<input type="text" name="entry">  
<input type=submit name="oneButton" value="Press Me!">  
</form>  
</h3> 



谢谢....



Thanks....


这篇关于避免在javascript中使用刷新按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆