如何在用户返回该页面时进行页面回发? [英] How to make a page postback when user comes back to that page?

查看:72
本文介绍了如何在用户返回该页面时进行页面回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有一些HTML页面。我写了代码,当页面没有回发时,就是第一次加载时。它会在数据库中存储一些东西。它工作正常。但我的问题是,当我点击后退按钮并再次加载页面时,它认为它只是不回发。因此,它再次将数据存储在数据库中。我不想要的。如何在用户返回页面时回页?

我试着在每页上写下代码。但它不起作用。

Hello. I have some html pages. On which I have wrote code that, when page is not postback, that is when it loads for the first time. It will store something in database. It is working fine. But my issue is, when I click on back button and the page again loads, it considers it as Not postback only. So, it again store data in database. Which i don't want. How to make a page postback when user goes back to it?
I tried to write below code on every page. But it isn't working.

<script language='text/javascript'>
setTimeout('__doPostBack('__Page','')', 10)
</script>





我需要在另一次加载后进行页面回发。

Thnak you。



I need to make a page postback after it is loaded fr the another time.
Thnak you.

推荐答案

我得到的解决方案实际上我在理解你的问题时犯了一个错误,抱歉不方便。

现在你的问题的解决方案:实际上在javascript函数之前执行代码后面的page_load事件,所以你可以做的是使用如下的会话变量。



In你想要回复的页面

使用下面的代码



I got the solution actually i make a mistake in understanding your question sorry for inconvinience.
Now Solution for your problem: actually page_load event in code behind gets executed before javascript function so what you can do is use a session varibale like below.

In your page in which you want to make it post back
use below code

protected void Page_LoadComplete(object sender, EventArgs e)
{
    if (Session["MakePostBack"] == null )
    {
        if (!IsPostBack)
            FillGrid();
    }
}









和休息所有你从这个页面重定向的页面







And in rest all pages where ever you are redirectiong to from this page

Session["MakePostBack"] = "PostItBack";





希望这有助于!!!



Hope This Helps!!!


这篇关于如何在用户返回该页面时进行页面回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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