当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - ScriptManager.AddHistoryPoint - page is displaying original page state first, then saved state

问题描述:

I'm using an UpdatePanel and the ScriptManager's AddHistoryPoint method to save my page state in the browser's history. The page is a simple search/results page with 2 states:

  • STATE 1 - showing search filters
  • STATE 2 - showing search results

When I navigate back to the page (by clicking the back button in my browser), the page shows the initial state (STATE 1) but then the update panel posts back and the page flips to the search results (STATE 2).

This looks untidy and it feels like I'm missing something here in my implementation. How can I tell the page to either just load the saved state, or hide the page content until the saved state has been loaded?

网友答案:

as I know in ScriptManager event OnNavigateHistory you must handle there that example you add HistoryPoint for state one and two same key ID only the value is different and thene OnNavigateHistory base on e.State["YourKey"] you make decision wich state to stay. example

string indexString = e.State["YourKey"]; 
    if (String.IsNullOrEmpty(indexString)) { 
         SetToStateOne();
    }
    else { 
        int index = int.Parse(indexString); 
        SetToStateTwo();
    }

Sorry for my bad english

分享给朋友:
您可能感兴趣的文章:
随机阅读: