RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
你可能遇到了下面的问题
关闭右侧工具栏
Extend Dynamic TextBox Control View State To Store
  • 作者:zhaozj
  • 发表时间:2020-12-23 11:03
  • 来源:未知

  Download C# Source Code
Only a developer would know the absolute joy of moving a heavily database centric desktop application to a web environment.  Can you smell the sarcasm?  Aside from storing data in cache, session, or static objects there is no storage place in memory for us to put data for fast access and hold onto it until the user closes the application the same way a desktop application can.  Thus, we end up having to run expensive queries to retrieve meta data (information stored in our database that helps describe our data) each time the page loads as well as when it posts back to itself.  Wouldn't it be nice to store this information somewhere so we don't have to run the same query again on page post back?
This nice to have feature has really become a bit of a necessity for a rather complex project our team has been working on that is a little bit out of the norm.  Let me briefly summarize the requirements of our data entry pages.  The entire data entry page is database driven and in many cases this includes user specific settings for each data entry point.  A typical page might have 40 or so dynamically generated data entry points.  A wide variety of settings or meta data exists for each data entry point that range from display oriented settings, server side calculation settings, relational settings to combinations of data entry points, and settings determining how and when to save the data.  As you can see, this can get rather complicated.
Let's also review the application environment.  A typical user analysis model would consist of around a 100 of these data entry pages.  The Web site itself supports an unlimited number of analysis models.  Thus, the database is quite large and the process of obtaining the meta data is quite complex.  Running more queries than absolutely necessary can be a real drag on performance.  Also keep in mind that a typical user will spend anywhere from 15 - 45 minutes on a single data entry page completing that section of the analysis model.
Before trying to implement the ViewState solution described below, I looked into utilizing session, static objects, and the application cache.  Each of these had their pros and cons as it applied to our specific situation.  I opted for this solution but it is important to note that if your requirements aren't quite as complex and particularly if the meta data is fairly static, then I'd look towards loading it up in a static object or use the cache.  The ViewState solution I've come up with is strictly for those times when you need to attach additional properties to controls and maintain the state of the control and the state of the extended properties together.  In other words, I've opted to show you that this can be done.  It doesn't mean that you always should.  The performance impact of having larger than normal ViewState and the process of managing ViewState isn't necessarily prohibitive but if you are trying to squeeze out every once of performance, doing this without it being necessary could hurt your cause.