EnableViewState = False  causes items not to write to database

Posted on 2005-05-09
Last Modified: 2010-04-16
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 ?????
Question by:jimwal1940
    LVL 1

    Expert Comment

    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.


    Author Comment

    SO Saddy currently I have the dropdowns that get populated via a database table.... and load the selections into an array such as this ...

    What would the code look like in your solution ?
    LVL 1

    Accepted Solution

    It's hard to know exactly how it's set up, but probably something like this should work:


    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.

    LVL 23

    Expert Comment

    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];
    LVL 23

    Expert Comment

    // 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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now