• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

EnableViewState = False causes items not to write to database

I was building an application that queries a database to populate 10 pulldowns.  One issue is that each of these 10 dropdowns has about 5000 drug names in each one.  I was getting a " Maximum Request Length Exceeded" but was adviced to turn off view state on each drop down so I did and it seemed to allow the record to write.  I just found out though that those dropdowns that I made EnableViewState = false aren't writting or being placed into the array variables to be written to the database... When I make EnableViewState = True they are assigned to the variales but since the Event Viewis so long I continue to get the above error...

Thoughts Any one ?????
0
jimwal1940
Asked:
jimwal1940
  • 2
  • 2
1 Solution
 
saddy1Commented:
Instead of using the Dropdowns as controls and accessing their data that way, I would use the more traditional way of checking the POST object, via Request.Form.  So if your Dropdown is called "DD1", you can access what was selected using Request.Form["DD1"], which doesn't require the Viewstate.  Passing thousands of unused dropdown selections is really inefficient anyway, at will probably slow down your site significantly, since the user has to download each entry twice - once in the dropdown itself, and once in the Viewstate.

--saddy1--
0
 
jimwal1940Author Commented:
SO Saddy currently I have the dropdowns that get populated via a database table.... and load the selections into an array such as this ...
values.Add(drp_meds1.SelectedValue);
values.Add(drp_meds2.SelectedValue);
 values.Add(drp_meds3.SelectedValue);
values.Add(drp_meds4.SelectedValue);
values.Add(drp_meds5.SelectedValue);
values.Add(drp_meds6.SelectedValue);
values.Add(drp_meds7.SelectedValue);
values.Add(drp_meds8.SelectedValue);
values.Add(drp_meds9.SelectedValue);
values.Add(drp_meds10.SelectedValue);

What would the code look like in your solution ?
0
 
saddy1Commented:
It's hard to know exactly how it's set up, but probably something like this should work:

values.Add(Request["drp_meds1"]);
values.Add(Request["drp_meds2"]);
...
values.Add(Request["drp_meds10"]);

If you have this inside a User Control, it might be more complicated.  In which case, set Trace="true" in the <%Page section of your Web Form, and scroll down to the "Request" section, which will tell you what string to use as the key to Request.

--saddy1--
0
 
b1xml2Commented:
If you switch off viewstate, then you must reconstruct the dropdownlist across every postback and obtain the data of the dropdownlist from the RequestForm collection.

The proper way to get this is the following:
// get the name via the UniqueID property, the same would generally apply for controls inside UserControls
// if the controls are inside any control implementing the INamingContainer, then the property will not be accurate in giving the name for retrieval.
string name = ddl.UniqueID;
string value = Request.Form[name] == null ? string.Empty : Request.Form[name];
0
 
b1xml2Commented:
// if the controls are inside any control implementing the INamingContainer, then the property will not be accurate in giving the name for retrieval. <-- will not apply to controls found imemdiately inside the UserControl
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now