DropdownList losing items on postback in iframe - asp.net

Having a very strange issue regarding postback in ASP.NET. I have page dynamically populating DropdownLists on Page_Load, only if it's not a postback. I also have several textboxes on the page for user input.
If I postback, either by clicking a submit button or via a SelectedIndexChanged event, the textboxes maintain their values, but the DropdownLists lose all their items - but only IF the page is loaded via an iFrame. If I load the page directly, everything works fine. If I load it via an iFrame, everything but the dropdowns works.
Has anyone run into this behavior before? I don't think it matters, but I'm on Windows7, IIS7, ASP.NET 3.5 and browing with IE8. ViewState is enabled, which is apparent from the textboxes having their values persisted. The ASP.NET page is in a WebApp hosted on localhost. The containing page, with the IFrame tag is just a dummy HTML file sitting on my desktop for testing. Is this perhaps just an IE security issue?
UPDATE:
I actually just moved the "dummy" container page into the Webapp and it seems to work fine, even via the iFrame. Still, I'd like to know why this is happening if the containing page is outside the Webapp as I intend on having people load the page in and iFrame via other domains..

This is probably a ViewState issue. The values in the TextBox controls come from the post data, not the ViewState, so it is no indication that it is working correctly.

Related

JQueryMobile dialog shows twice because of a postback

I have an asp.net page with a timer embedded in an UpdatePanel (UpdateMode="Conditional", ChildrenAsTriggers="false"). The timer is responsible for updating some components of that page every few seconds.
There are also some HyperLink controls on the page and they open a JQueryMobile dialog when clicked (data-rel="dialog"). The problem is that the timer i mentioned causes postback every few seconds. So when a dialog is opened and then closed, the first such postback after then causes the dialog to open once again.
Using the rel="external" as another attribute of the HyperLinks I mentioned solves the problem, but this is no solution for me. This causes full redirection to the dialog page instead of showing it using AJAX (as if on top of current page).
My idea was to stop the timer when any hyperlink is clicked. This solves the problem, but I have no idea how to start the timer again when the dialog closes. Is it possible to detect when a JQueryMobile dialog is closed? I know, this sounds stupid, but I can't come up with a better idea. Will you help me, please?
So basically, I don't want the JQueryMobile dialog page to show up for the second time after a timer tick. Could you please advise me how to achieve that?
jQuery Mobile with asp.net Web Forms and an UpdatePannel? This just sounds like a horrible combination.
jQuery Mobile and Web Forms fundamentally don't work well together. The specific issue that Web Forms requires a single <form /> element that wraps all controls (and most content). jQuery Mobile attempts to build up the DOM with "virtual" pages via ajax loading. This breaks the PostBack model by submitting the entire form instead of the individual form found within each page template. Now throw UpdatePanels in there...
Your only hope is go exclusively with Single page templates and to disable all ajax loading data-ajax="false" on both links and forms. And just say no to UpdatePanels.
asp.net MVC would give you much greater control over these issues.

how to cause refresh to ASP.net Page when page Postback

When the ASP.net Page is Postback the controls inside the table is disappear,
but when i click on button that has that code which cause transfer to the page:
Server.Transfer("~/Admins/EditUsers.aspx");
all controls appear easy with no problems.
Then,is there is need to make refresh to the page, or what can i do?
Thanks
A postback already performs a page refresh automatically.
If controls are disappearing, that suggests that you might not be creating them on the postback. Note that tables do not store their contents in ViewState. Is there any chance you are testing for IsPostBack in your page Load handler? If so, you must recreate the table on every load, whether a postback or not.
Beyond that, you'd probably need to provide a bit more specific information.

Go back previous page (keep viewstate) with ASP.NET UpdatePanel control

ASP.NET 4.0 Webform website
master page:
left side panel (navigation menu purpose): use UpdatePanel control (AJAX), so when selecting new menu, the whole page won't reload. Only content part will be updated.
My question is -- I want to be able to use browser back button to go back to previous menu (with form state saved). However, when looking into the viewstate, it's always the same. Is there any way to do this? Thanks.
I guess one work around would be, when a user selects a menu item from the menu, put that selection in a session variable and in the page load. Then when the user hits the browser back button, you can set the menu in the page load, since you have values in your session variable.
What pst is referring to is "cross-page posting".
On your source page, you will need to set the asp button's postbackurl to your target page url.
In the target page c# onload method, set page.previouspage to your source page. Check if the previouspage's post was a crosspagepost.
If true, get zource page's viewstate.
How do you get access to the source page's viewstate from the target page? Save the source page's viewstate in the source page before going to the target page. Save the viewstate in an asp hidden variable on the source page, then get it in the target page using previouspage.findcontrol("variable name").
After getting the source page's viewstate, save it in an asp hidden variable on the target page.
When you want to return to the source page, you will do everything above in reverse, in a way.
The "back to previous page" link button will use the source page url for the postbackurl value.
In the source page's onload c# method, set the page.previouspage url to the target page's url. Check if the previouspage's post was a cross-page post.
If true, in the source page (after returning from target page) use previouspage.findcontrol("savedSourcePageViewstate") to get the saved viewstate of the source page.
I am not exactly sure yet how to then change the source page's viewstate to the saved viewstate. you might actually have to do it in the target page's backttopreviouspage button's click handler.
I am working at developing this process right now in a project i'm developing at work.
When i get it working, i'll create a full walkthrough for this, with code examples, and post the link to the walkthrough here.
However, i already haveworking the cross-page posting process of getting data from the source page in the target page.
It is secure, and is the best method that i have come across for getting data from one page to anotherin an asp.net webforms application.

control values on refresh

I have set an asp.net page to refresh every after sometime. The problem is that once the page is refresh, the state of the controls are lost, like the dropdown loses all its item. I checked the viewstate property of the controls but they are set to be enabled. Any idea why is it so?
Thanks,
Because a web form is also an HTML form. You need to POST the form instead of refreshing.

Cross Page Postback doesn't work for client-side enabled button

I am using a cross page postback for Page A to pass data to Page B.
The button that causes the postback has its postbackurl set but is disabled until the user selects a value from a DDL at which point the button is enable using javascript. However this prevents the cross page postback from occurring, Page A just postbacks to itself.
If the button is never disabled it works fine. Anyone know how to solve this?
It looks like when the button is disabled .Net doesn't bother adding the necessary bits to handle the cross page postback on the client, so they will be missing when the button is enable client-side.
I guess one solution would be to have the button enabled to start with (so that .Net adds the cross page postback controls) and then disable it using javascript as soon as the control loads on the client. But this sounds a bit clunky.

Resources