Opinions wanted regarding efficiency and drop down list data

  • Thread starter Thread starter Wysiwyg
  • Start date Start date
W

Wysiwyg

I was hoping to get some opinions on the efficiency of various methods of
reusing the same dropdown list data.

Here is the situation:

Multiple panels on maintenance pages with TAB menus across the top showing
different panels. A DropDownList with a 50+ value/text entries exists on
more than one panel but only one will be displayed at a time. Examples might
be US states, countries, category codes, etc.

The query results the dropdownlists are bound to are stored in the
HttpContext.Current.Cache. The data isn't expected to change.

I can...

1. Create the dataset once during the initial page load and bind all
dropdown lists to the same dataset. EnableViewState = true for both
DropDownLists. Both DropDownLists will be in the viewstate sent to the
client and back to the server whether or not the panels are visible but I
won't have to rebind.

2. Turn viewstate off for and rebind the DropDownLists after each page load.
The query results are stored in the cache in an ArrayList of objects. I'd
have to rebind the controls after every load but the size of the viewstate
won't be increased by the data. The query won't be run every time as long as
the query's cache hasn't expired.

3. Put placeholders on the various panels of the web form, manually create a
complete, but non-displayed, DropDownList in code behind with the bound data
in it and store the entire control in the session state. During the
pre-render event of the appropriate panels I clear the placeholder and add
the saved DropDownList to it. I'll have to set the current selected value as
well. I'm not sure if the placeholder unique ID would have the selected
value in the Request.Form value though. I'd have to try it to see if I could
avoid manually placing a value in the viewstate when the selection is
changed. I'd want to clear the session state value when the page is
unloaded.

4. Same as #3 but use the HttpContext.Current.Cache instead of the session
state. The saved DropDownList would be shared with every session. This would
avoid even more querying when the data is fairly static.

I'd be interested in any other ways to efficiently handle DropDownList data.

Thanks for any replies,
Bill
 
Have you thought of making the list a user control (ascx file) and putting
the
fixed data in the outputcache with a long Duration value so it doesnt need
refreshing too often. You can then add mutliple controls to a web page that
uses this data in the ascx control file that wont refresh often.

e.g ascx file using bound data grid:

'Change the following duraction to something huge!
<%@ OutputCache Duration="60" VaryByParam="none" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="VB" runat="server">

Sub Page_Load(Src As Object, E As EventArgs)
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
Dim ds As DataSet

MyConnection = New
SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")
MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)

ds = New DataSet()
MyCommand.Fill(ds, "Authors")

MyDataGrid.DataSource=new DataView(ds.Tables(0))
MyDataGrid.DataBind()

End Sub

</script>

<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>



e.g. web form using multiple versions of the control:
<%@ Register TagPrefix="Acme" TagName="DataControl" Src="datactrl.ascx" %>

<Acme:DataControl runat="server" ID="Datacontrol1" NAME="Datacontrol1"/>

<p></p>
<Acme:DataControl runat="server" ID="Datacontrol2" NAME="Datacontrol1"/>
 
I'd be making a control with single DropDownList and a property to get or
set the selected value for the list. I would not be using AutoPostBack. I'd
want the existing selection retained when the displayed panel changes before
the form is submitted to be saved.

I haven't cached user controls yet so I'm wondering...

1. Is the control itself cached on the server or just the rendered html from
the control? If I don't store any protected property variables then it
probably won't matter.

2. If I cache the user control and assuming the viewstate is enabled for the
included DropDownList would each rendered instance of the DropDownList be
stored in the viewstate as well?

3. I saw one book that stated that originally there were two versions of
ASP.NET, the Premium version and the Standard version. The book states that
only the Premium version actually caches although there would be no warning
that the controls weren't actually cached. Currently IIS with ASP.NET always
has caching, correct?

If I don't hear back then I'll try caching a control and see how it behaves.

Thanks for the reply!
Bill
 
Back
Top