[Original address] tip/TRICK: Enabling back/forward-button support for ASP. NET Ajax updatepanel
[Original article publication date] Thursday, September 14,200 6
Nikhil recently wrote a good post about a new ASP. Net Control called historycontrol that supports Ajax. After it is added to the page, developers can use programming methods to add a logical view to the browser's historical records ). This will make Ajax-enabled websites more useful and follow the standard forward/backward navigation practices of traditional Web applications.
For example, with historycontrol of Nikhil, developers can write an encoding similar to the following to respond to a list selection change and add the list selection as an identifier to the browser's historical records:
Private void contentlist_selectedindexchanged (Object sender, eventargs e ){
History. addentry (contentlist. selectedindex. tostring ();
}
Once you add a new item to the history control, the back/forward button in the browser is activated. The history control of Nikhil provides a navigate event. When you press the back/forward button in the browser, this event will be triggered, at the same time, it provides the identifier used to add the logic View to the browser's historical records in the event processing function parameters. Then you can use this identifier to restore the page to the page status corresponding to this historical record:
Private void historycontrol_navigate (Object sender, historyeventargs e ){
Int selectedindex = 0;
If (string. isnullorempty (E. identifier) = false ){
Selectedindex = int32.parse (E. identifier );
}
// Update the content being displayed in the page
Contentlist. selectedindex = selectedindex;
// Mark the update panels as needing an update
Mainupdatepanel. Update ();
}
In this way, you can also use the forward/backward button for navigation when using Ajax applications. You can download the code of the Nikhil history control here and use it in your project.
I hope this article will help you,
Scott
Tags: ASP. NET,. net, Atlas, tips and tricks
(Translated by Si GUI)