asp.net dropdown displaying incorrectly in chrome - c#

I have asp.net web forms page that has a asp.net dropdownlist control on it with an autopostback. When a user makes a selection in the drop down a get request is made to the same page with a query string parameter.
On postback I read the query string parameter and load / populate additional controls.
When a user presses the browsers back button the previous request is submitted (along with its query string). In the code behind I read the query string and load / populate additional controls, which works fine. I also try to select the appropriate item in the drop down (by value).
The issue I am seeing in the browser is that appropriate option text is not shown in the select. By inspecting the source I can see the the correct option has the selected="selected" attribute, so setting the selected item in the code behind was successful. But the text is incorrectly still the same as before the back button was pressed.
Curiously this only happens in chrome. ie and firefox both behave as expected.
Has anyone had any issues with asp.net drop down lists and chrome?
I'm stumped here.
I have created a simple example that demonstates this problem. src can be found at https://github.com/beembow/AspDotNetDropDownInChrome.git
Reproduce the error by selecting some values in drop down then pressing back button.

In which Page Event are you setting the selected value of the drop-down? It could be that you are setting it once the page is loaded, and that is why you don't see the dropdown set with the selected value.

They only fix I have found is similar to the one suggested ASP.NET - Google Chrome caching DropDownList selections.
I essentially add a global variable that holds the value of the option to select in the drop down. I do this via Page.RegisterStartupScript in the code behind.
I then have some js that looks for this global value, and if it finds it selects the appropriate option in the select via jquery.
This makes me think that the issue is something to do with how chrome treats some asp.net generated javascript / viewstate. It may also be something to do with chrome caching policies. curious that it works in both firefox and ie.
Either way, the solution described above is definitely an ugly hack. Would be interested in any solutions other people find.

Related

ASP.Net Controls Don't Work if I used link to get to the page

I Just noticed this odd bug. I have a Webpage with 2 drop down-lists, one of them will populate with data depending on what item the first one has selected.
I noticed if I get to the page by using the hyperlink I have in my website's menu, the controls will not update when an item is changed, but if I get to the page any other way everything works perfectly.
I have been looking for a solution but I have not been able to find a way to fix the problem.
I am using autopostback to update the page when selected index changes.
Seems to work for a while after I refresh, but a new session it will stop working even though it has nothing to do with a session.

JS Redirect to page w/ postback or cache

I have a webforms site that has 2 menus.
On a page you click a button, has some c# events fired by a webservice (ajax) then redirects you to another page with history.go(-1). The only problem is that in the webservice I create a sesion that makes the menus switch, the default one hides and the other one shows. The menu switch in done in the Page_Load of the Master page.
My problem is that with history.go(-1) you get to the previous page, but the old menu is present instead of the new one. How can I fix it?
the problem is that the browser is not actually loading the previous page it is using the cached page. is there a reason you can not have both menus hidden and then decide what one to show client side? this way you can let the JS .ready take care of what menu to show and then you should get the desired results when using the history.go(-1).
This artical speakes to setting cookie from the server then checking in on the client.
you could use something like this and then check the cookie to determine if the page was loaded from cache and then force a postback.
location.reload()
My fix was to add in a session the previos link, and when I need a redirect w/ cache I redirect to another aspx page, that redirects depengind on the url params where I need it to go... it was the simpler method I could thing of...

Stop ASP.NET PostBacks Showing As Separate Pages?

I have an ASP.NET form that the user can make lots of changes to, each time they make a change the page PostsBack and the details are updated.
If the user hits the browser back button they go back through all the previous versions of the page.
Is it possible to stop each PostBack being treated by the browser as a new page?
So the would make any changes they like and if they hit the back button it brings them to the previous form and not the same form but a different version?
I know I could use AJAX to update values but I'm not an advanced coder so trying to keep things simple as I haven't used AJAX before.
Ajax is your only solution.
There is no way to remove a page from the browser history. Javascript is explicitly denied the capability.
Now, you could, potentially, stop them from using the back button at all. Although this might result in unhappy users and I'm not 100% certain it works in all browsers.
function body_onload(){
window.history.forward(1);
}
You could use a trick to do it.
On postback you can set a session bit to true saying they submitted that form. On your postback check to see if that value is set. If it is they are trying to do it again and you can just abort it. It wouldn't prevent the postback per se but you could control the logic and prevent it from DOING anything.
I personally would explore ajax as Jquery provides some nice ways to do it and it'd be a learning experience but I suppose this would work as you are asking. On a per session basis. If you only want 1 submission ever use a database to store the activity.
You could use UpdatePanel: http://msdn.microsoft.com/en-us/library/bb386454.aspx

BeautyTips - Refresh after postback

I'm using the BeautyTips jQuery plugin in a template column in my RadGrid to show additional information.
Everything is working well, but I have one issue: After the user applies some changes and clicks the update button (which causes a partial page update), the BeautyTips plugin still shows the outdated info.
I've put a breakpoint on the code that loads the info it uses, and it is not hit after initally loading them; so BeautyTips is caching that result somewhere.
Is anybody aware of a way I can force those to refresh?
OK; I figured this one out:
There's an option in BeautyTips called ajaxCache which will cache the results of ajax calls.
Setting this to false (the default is true) solved my problem.

ASP.NET Menu control changing position after postback

I am currently testing a menu in ASP.NET I've recently made using asp:menu control.
The menu is just as I want it to be right now, but whenever there is a postback that updates the whole page, it moves a little downwards (only once, a second postback won't move it a little bit more).
It's not CSS - > I've removed all CSS from this menu)
It's not any property -> I've commented out everything related to customizing the menu
It's not any other element above it enlarging -> I've specially put it inside a table, in which the only content is the asp:menu control
It moves a lot downwards in IE6, a little in IE8, and it doesn't move at all in Firefox 4.
What could I do ? Are there any alternatives ? Is there any property I can use, or any outer element I could put it inside in order for it to stay still ?
And yes, every single machine this is going to run in is using Internet Explorer. The nightmare of any web developer.
---[update]-----
I've built a menu in a separate project, and the effect wasn't there! I've copied the exact same files into my project, and ran it, and the issue was there.
Could it be a difference in the asp.net version ?
Did you check using IE web developer toolbar to see what's the html looks like in that area before and after the postback? It seems more like a browser issue so the toolbar would give you details as what is coming in the gap or may be what's pushing it down.
If the app is in asp.net 4.0, look at the source code of the page after it renders the first time, and then after the postback. Make sure it renders as divs on both or tables on both.
I currently have a similar issue where my menu "spreads out" on the postback. Before the postback, it renders divs. After the postback, it renders tables.
There is specifically a property on the menu "RenderingMode" which is suppose to control this, but it is not working for me.
I had the same problem. My navigation menu sits in an UpdatePanel, and I changed the UpdateMode from Always to Conditional - problem solved. This was in my master page.

Categories