asp.net dropdownlist too big, viewstate probably full, postback - asp.net

I got a page with multiple dropdownlist. Each of them are fill with a lot of stock.I need the selected value of each of them on postback.
My problem is, at the end of the post back it take so much time to refresh(show) the page.
and I saw that the viewstate is fill with a lot of thing.
I try to disable viewstate for my dropdownlist, but that erase my value on postback.
I already have a conpressor for viewstate.
can you help me.

You can use Page Caching - based on OutputCache property of page
Link Sample : http://msdn.microsoft.com/en-us/library/hdxfb6cy%28v=vs.100%29.aspx
Link Configuration : http://msdn.microsoft.com/en-us/library/ms178606%28v=vs.100%29.aspx

Page Caching or disable viewstate and add selected values to session and get that values at pageload again.

Related

Controls that don't have ViewState

I am very new to Asp.Net.
Almost all the controls i have seen till now has ViewState.
So, my question is Are there any controls that don't have ViewState ? What are they.
I have googled, but din't find the correct solution.
Thank you !!
Every control has ViewState because that is where all attribute values are stored.
To avoid ViewState you can disable it on the control (EnableViewState=false) and make sure when you set any properties (like Text, Visible etc.) you do that yourself on every postback (so that ViewState is not needed) - so in events like Page_Load instead of Button_Click.

ViewState Management in ASP.Net

i was recently surfing the msdn for the session state management tools, i came accross viewstate, which can be used the retain the page or controls value accross the page postback, so i created a simple application, which contains a asp:textbox and asp:button now i made the EnableViewState="false" for textbox and run the page, entered some values and clicked on the button, the page postbacked but the value was retained, i thought that would be because the pages viewstate property is enabled, so i changed the EnableViewState="false" in the page directives, and run the page, still the textbox value was retained in the textbox accross the postback, can anyone tell me with small example how the does viewstate work in my scenario
ViewState can probably not be explained with a small example ;-)
I'd recommend to read this article: Truly Understanding ViewState
The TextBox is rendered as input control, so the value is post back and set again to the TextBox.
The viewstate have a meaning on the TextBox for the other attributes that you can set it pro grammatically, or in case that you make it hidden and you like to keep the content of it.

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.

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.

Listbox values are persisting across postbacks

I am having a listbox in ASP.net. I am populating the listbox values from another listbox in a page dynamically. During postbacks the values of output listbox are not persisted.
(while going to another page and come back to this page).
Please suggest some good answer. EnableViewstate = "true" is not working.
Are you doing anything in Page_Load that should be in a
if(!IsPostBack) {}
Initialization code in load needs to only be called when the page is first loaded, not on postbacks.
If you are going to another page and then coming back to this page, I think you need to preserve the information yourself in the Session and then restore it when you come back to the page.
The viewstate is only preserved as long as your on the same page doing postbacks.
As Lou Franco wrote
if(!IsPostBack) {}
You use this on the initial pagerequest to fill in the data. if you wish to preserve the data across pages using the session to store the values is the best bet.
preferably you fill in the data in your listbox before the SaveViewState event thats in PreInit as far as I recall.
Initialize the content of your controls in your Page's Init event (Page_Init). That way any values the user supplies are not overwritten by your defaults.
EnableViewState will just repopulate the output listbox with the values that it had when the page first rendered, since they're still the ones stored in the viewstate. The browser sends only the selected value in the postback, so there's no way for the server to know what other values you added on the client.
You can work around this by adding a hidden input to the page and populating it with the dynamic values when you update the listbox. Your page can then check that value during a postback and repopulate the list properly.
Changes made to the listbox on the client side are not persisted during a postback, you need to record that information in hidden fields and then configure the control during the page_load event to make the changes stick during the rest of the postback.

Resources