Click here to Skip to main content
15,921,250 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

try this

C#
//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"];
    }
 
Share this answer
 
v2
Use Below script it may help you

HTML
<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....
 
Share this answer
 
Comments
[no name] 30-Mar-12 10:47am    
May help with what? How does this address the question about refreshing?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900