I have a page with several gridviews. For usability, I have put these gridviews into a series of jquery tabs. Tabs works by creating anchor links that go to containers with certain ids, so after clicking on a given tab, the url might change from
host.com/page.aspx
to
host.com/page.aspx#tab2
The issue is that if any elements inside the tabs cause a postback, like trying to sort or page the grid for example, upon loading, the selected tab is lost, and reverts back to the first tab in the list. So in that case I would have sorted the right grid, but I'd have to click the correct tab again to see it.
To fix the issue, I want to track what anchor I'm at as the postback occurs, so that I can change the url I'm loading to include it. The only way I can think to do it is a Redirect, which I really don't want to incur the cost of.
Is there some better way to specify which anchor to load on postback?
On the forms onsubmit event, modify the action attribute to include the relevant anchor (which you'll need to keep track of yourself)
If the page is posting back to itself then instead of making the post back to foo.aspx you need to make it postback to foo.aspx#anchor.
You could also do this via cookies if you must but anchors is much better. Cookies are more useful for things like customizing the Yahoo page to focus on a particular tab on each visit.
Related
I am creating a .net website in c#.
The master page contains a fixed footer bar from which you can display 'bookmarks'. I also have a remove function for each bookmark.
Some aspx pages may have a add bookmark/remove bookmark function (a button control) on them.
I use update panels throughout so button controls are always encapsulated by one.
If I add/remove a bookmark from an aspx page, I can trigger an update to the fixed footer panel. A delegate event is triggered in the aspx page which calls a method on the master page to update the fixed footer panel, so everything is sync'd dynamically.
It doesn't seem possible to do the same the other way around. If i remove a bookmark from the fixed footer, I would need to know if the current aspx page was displaying a bookmark control. Pretty much impossible I would have thought, but I'm open to suggestions.
With that in mind the question really is does anyone have a technique that they use to deal with these scenarios, such as calling a full page update or something similar, or is it a case of doing nothing until the next page load/postback?
Thanks in advance.
I have two modal popups on a page, both inside user controls, and both have different names, and different behavior id's. Also, the hidden buttons used with them have different id's. I use javascript to click those buttons to show the popup.
On load of the page, the first popup is hidden, but the second one is not, and is at the bottom of the page completely visible. When I click the link that is supposed to show the second popup, the first one is shown instead, but the javascript to load the default values into the first popup does not run, so I'm confused as to what is going on. Any ideas?
I have solved the issue. My situation is bit different. for you both pop ups are in a user control. But for me only one is in user control and other one is in the page itself. hope this will shed some light on your issue.
I gave different id's for
Hidden Target button (TargetControlID)
OK button (OkControlID)
Popup Panel (pnlPopup)
Model Popup control
Still if you are not sure, try your page in firefox with firebug installed. This will help you to identify any java-script errors.
Hope this helps.
I've got a master page with a section for subnavigation links on it:
<div id="sub_nav" runat="server"></div>
I programatically populate this with Hyperlinks when my main asp:Menu data is bound depending on the address of the page I'm on.
This works fine and all my correct submenu stuff shows up on each page. The problem is that when one of these pages does a postback, I lose all the links that were in my sub_nav div.
Now, I could just populate the div with links every time regardless of whether the master page load is a postback or not, but I figured there is a better way of doing this. I was thinking enabling the viewstate on the div and links inside it might persist them through postbacks, but apparently that is not how viewstate works.
What is the correct way of doing this?
Viewstate only stores the current state of a control and not the controls by themselves. If you are dynamically adding controls make sure to add them on page init method irrespective of postback
This MSDN sample should help you.
According to the excellent article TRULY Understanding ViewState, that's not really the purpose of ViewState. Furthermore, ViewState costs additional bandwidth so in general we want to avoid it if possible. It sounds like this data should be "cheap" to obtain (cacheable or whatnot), so I'd definitely populate it on every request and disable ViewState on those controls.
To understand the main purpose of ViewState consider a page with two buttons, btnA and btnB and two labels lblA and lblB.
When the user clicks btnA , the page posts back and sets lblA to "You clicked A!".
When the user clicks btnB, the page posts back and sets lblB to "You clicked B!".
With ViewState, the page remembers that lblA.Text was set to "You clicked A!" previously and restores that value. Without ViewState, if the user clicked A and then B, the page would only display "You clicked B!" because there's nothing to store the previous value of lblA.
in my ajaxified page i have used several user control shifting from one user control to anothe r and then pressing the back button takes me to first page instead of previously filtered page
how to solve this
all this filters are linkbuttons i am also using listview these filters are actually filtering the content of this listview
You may take a look at the jquery history plugin. If you are using UpdatePanel to perform the AJAX requests you might find this article helpful as well as this video.
I am using a ListView for displaying list of items in a List page. I am also using DataPager control in my page for paging.
PROBLEM
While I am in the middle of the List let 5th page out of 10 pages and going to another page then clicking browser back button I am again comming back to my list page with page number showing 1st page out of 10.
What could be the solution.
Thanks in advance.
ASP.NET uses PostBacks to manipulate the state of the form, such as paging. What this means is that every interaction on the page - a button click, a LinkButton click - is really just submitting (posting) a form back to the same page. Hence the name, postback. An unfortunate downside of this approach is that it breaks the back button.
One possible fix is to use the Post/Redirect pattern which is becoming more common with ASP.NET MVC, but the principles still apply. However, I'd strongly discourage using widely in your application, as it would essentially double the amount of requests.