Question

I have an ASP webpage that has 52 custom control all maintaining ViewState by loading in the PreInit routine

It is a report generator page that depending on which report, up to 5 of the custom controls are visible but not all of them.

For instance,

  • The Client report does not need the Employee questions.
  • And the Employee report does not need the Client questions.
  • But both need the Date Range questions.

(and all this works perfectly)

BUT...

I would like to instead LOAD ONLY the controls that are appropriate for the report that the user is running. (Which sound to me) like I need to store information on WHICH controls to load in the ViewState.

Problem is... viewstate is not available in the PreInit routine, so I cannot use it to determine which controls to load.

My options are then to store the information on WHICH controls to load in:

  1. SessionState.
  2. Database
  3. URL argument.
  4. Something else I haven't thought of.

Each of which carries its own problems for doing what I need.

What (in your opinion) is the best practice for this.

My code (snip)

Private Sub WebForm2_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

    ReportOptions.Controls.Add(UserControl1)
    ReportOptions.Controls.Add(UserControl2)
    ReportOptions.Controls.Add(UserControl3)
    Etc...

End Sub

My HTML (snip)

<div id="ReportOptions" class="ReportOptions" runat="server"/>
Était-ce utile?

La solution

Viewstate is not an option because you must reconstruct your page exactly as it was (controls and all) in order to read the view state correctly on a post back.

Session sux. (single threaded in asp.net provider)

Database is way to heavy and an overkill.

URL method is stateless and probably your best bet.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top