History control

Last post 04-27-2008 10:03 AM by nomadsolo. 19 replies.

Sort Posts:

  • History control

    01-20-2008, 8:31 PM
    • Loading...
    • wsyeager
    • Joined on 06-26-2002, 7:42 PM
    • Weston, Florida, USA
    • Posts 435

    I've downloaded the latest Futures version for ASP.Net AJAX for use with VS 2005. I looked at the example on this site to use the control for paging with a datagrid.

    However, I am trying to get this control to work underneath a simple condtion. I have page 1 and page 2 each with some asp.net controls on them. When I go to page 2 and then go back to page 1, I simply want the form data to reappear for all the controls on the form. Am I missing something with this control or what? This should be something very simple to do. Having form data to not be able to reappear for a page would be useless if AJAX cannot accomplish this.

    Could somebody shed some light on this subject and post some simple code for it.

    Thanks so much....

    Thanks,

    Bill Yeager MCP.Net, BCIP
  • Re: History control

    01-20-2008, 11:14 PM
    • Loading...
    • stefan.sedich
    • Joined on 08-29-2007, 10:30 AM
    • Perth, Australia
    • Posts 83

    Bill,

    Are you storing your state in the history control, for example when you perform a search on page1 you need to store the parametres that will be needed to restore the pages state into the history state. My example will use a search form which has only one search field

    So step 1 add a history control to your page like so:

    <cc1:History ID="History1" runat="server"></cc1:History>


    Step 2, when you perform your search store params in history state:

    ' Some search code here to pull in my results...
    History1.AddHistoryPoint("search", txtSearch.Text)

    Step 3, hook into the server side Navigate event of the History control, retrieve your parametre and rebuild the state of your form:

    Private Sub History1_Navigate(ByVal sender As Object, ByVal args As Microsoft.Web.Preview.UI.Controls.HistoryEventArgs) Handles History1.Navigate
            If (args.State.ContainsKey("search")) Then
                Dim search As String = args.State("search").ToString()
                ' Perform your search again here using the param we got from state.

                txtSearch.Text = search
            End If
    End Sub


    That should be all your need to be able to use the History control and handle back button support. Let me know if that helped.



    Thanks
    Stefan

  • Re: History control

    01-21-2008, 7:03 AM

    Bill,

           history control does not save state just like browser save for synchronous post back.using history control you can store your history points which may be any serializable object. as soon as  you add history points your back button enable and now you can recover your state programatically.


     Private Sub History1_Navigate(ByVal sender As Object, ByVal args As Microsoft.Web.Preview.UI.Controls.HistoryEventArgs) Handles History1.Navigate

     event will keep track of back/forward button click .

    example given by stefan is enough to understand the working of history control.

    Thanks

    Shikhar 

  • Re: History control

    01-21-2008, 9:51 AM
    • Loading...
    • wsyeager
    • Joined on 06-26-2002, 7:42 PM
    • Weston, Florida, USA
    • Posts 435

    Stefan, thanks for the simple & concise response. I'll try it when I get home later tonite.

    So all three steps would be performed on page 1, correct?

    What about if you have several controls on page 1 (like name, address, city, state, phone, etc) and the user presses the browser "BACK" button on page 2 to go back to page 1? Would you have to duplicate steps 2 & 3 for each different control you want to restore data to?

    Would you use the control any differently with VS 2008 as opposed to VS 2005?

    Thanks for your input...

    Thanks,

    Bill Yeager MCP.Net, BCIP
  • Re: History control

    01-21-2008, 10:01 AM
    • Loading...
    • wsyeager
    • Joined on 06-26-2002, 7:42 PM
    • Weston, Florida, USA
    • Posts 435

    So instead of duplicating steps 2 & 3 (as per Stefan's post) for each control, I can create a collection object with name/value pairs and add all my values to it?

    Once all my values have been collected, I can place this collection object as a key value within the History object?

    Then, on the History Navigate method, I can loop through the collection (from the args.State) and restore the values inside this state to the proper controls on the page?

    Thanks,

    Bill Yeager MCP.Net, BCIP
  • Re: History control

    01-21-2008, 5:32 PM
    • Loading...
    • stefan.sedich
    • Joined on 08-29-2007, 10:30 AM
    • Perth, Australia
    • Posts 83
    The history state is already a key value collection. So you can use history.AddHistoryPoint("a", "a"); history.AddHistoryPoint("b", "b"); and so on. You would do this for each field/value you need to be able to restore the pages state.

    The use of the control is the same in 2005 and 2008

    Thanks
    Stefan
  • Re: History control

    01-21-2008, 8:53 PM
    • Loading...
    • wsyeager
    • Joined on 06-26-2002, 7:42 PM
    • Weston, Florida, USA
    • Posts 435

    Stefan, thanks so much for your clear & concise answers.

     I understand perfectly now Big Smile

    Thanks,

    Bill Yeager MCP.Net, BCIP
  • Re: History control

    01-21-2008, 9:13 PM
    Answer
    • Loading...
    • stefan.sedich
    • Joined on 08-29-2007, 10:30 AM
    • Perth, Australia
    • Posts 83

    Bill,

    Could you please mark this post as answered.


    Thanks
    Stefan

  • Re: History control

    01-23-2008, 12:03 AM

     Dear Bill,

                   you are not required to add name/value pair for each control as it will not work.

    the main concept of history control is it store data in browser's history as a one dimensional array.e.g.

    history.add("a","a");

    will add one history point. if in next step u add history.add("b","b"); it will add next history point, but when u will click on back/forward button you will be

    able to recover state of one object only.i hope you understand what i mean to say.

    so instead of adding individual name/value pair for control in history point create a serializable class in which you define as many field you want to store.

    like

    [serializable]

    class myhistorypoint
    {
    private string name,address,phoneno,emailid,sex;
    myhistorypoint()
    {
    name="";
    address="";
    phoneno=''";
    emailid="";
    sex="";
    }
    public string getname
    {
    get
    {
    getname=name;
    }
    set
    {
    name=value;
    }
    } and create property for other filed as well

    now on you aspx.vb page  create object of this class like

    myhistorypoint  newpoint=new myhistorypoint ();

    and store your state in this object.now your this single object has all the state like name,address,phoneno,emailid,sex.then add this object as history point

    e.g.

    History1.AddHistoryPoint("mypoint", (myhistorypoint)newpoint);

    now you can easily recover you entire state.

    so enjoy now.

    thanks 

    shikhar 

  • Re: History control

    01-23-2008, 12:12 AM

     one more thing I missed in my response ,that is there is no history control in VS 2008 .instead of history control VS 2008 use

    <asp:ScriptManager runat="server" id="ScriptManager1"> </asp:ScriptManager>
    to perform same task..

    i hope my this post is helpful to you.

    thanks

    shikhar 

  • Re: History control

    01-23-2008, 11:21 AM
    Answer
    • Loading...
    • wsyeager
    • Joined on 06-26-2002, 7:42 PM
    • Weston, Florida, USA
    • Posts 435

    shikhar , I understand --- thanks.

    The point is to have a class containing all the property values that you want state stored and add that class to the history point. Upon coming back to a page, I would reference the class in my history and put the values back on the page.

     

    Thanks,

    Bill Yeager MCP.Net, BCIP
  • Re: History control

    01-23-2008, 11:24 AM
    • Loading...
    • wsyeager
    • Joined on 06-26-2002, 7:42 PM
    • Weston, Florida, USA
    • Posts 435

    There is no history control is VS 2008???

    I found this following text in red on the website for the July CTP 2007 version:

    Important: this version of the browser history feature is now outdated and should not be used. Instead, please download the ASP.NET 3.5 Extensions Preview, which contains the new version.

    If I'm using VS 2005, do I need to download this? I already have the CTP July 2007 release and am using it with VS 2005...

     

    What control would I use for History for VS 2008?

    Thanks,

    Bill Yeager MCP.Net, BCIP
  • Re: History control

    01-23-2008, 12:03 PM
    • Loading...
    • stefan.sedich
    • Joined on 08-29-2007, 10:30 AM
    • Perth, Australia
    • Posts 83

    shikhar,

    It is possible to add asmany items to historystate as you want and you can retrieve all of them perfectly fine. i.e.

    AddHistoryPoint("a", "a");
    AddHistoryPoint("b", "b");
    AddHistoryPoint("c", "c");
    AddHistoryPoint("d", "d");


    And when you click back onto a page that set these history points you will be able to retrieve a,b,c and d, there is no need for a seperate class.


    As for a history control in VS2008 just download the latest futures extensions for .net 3.5 and it will work perfectly fine: http://www.asp.net/downloads/futures/



    Thanks
    Stefan

     

  • Re: History control

    01-23-2008, 7:36 PM
    Answer
    • Loading...
    • wsyeager
    • Joined on 06-26-2002, 7:42 PM
    • Weston, Florida, USA
    • Posts 435

    Thanks Stefan...

    At least I know I can do it both ways depending upon what situation I need.

    Thanks,

    Bill Yeager MCP.Net, BCIP
  • Re: History control

    01-24-2008, 12:30 AM

     hi stefan,

                     i am sorry. i haven't checked this way of adding history points so i was confused.and as u discussed abt history control in VS2008

    i read a post before few days which state that microsoft has omit history control in VS2008. instead of history control "scriptmanager" is given functionality of history control.

    Thanks

    Shikhar
     

Page 1 of 2 (20 items) 1 2 Next >