Is it possible to 'DataBind' a single property of a user control?
Before I get to the question, let me give a bit of background. I'm trying t开发者_如何学JAVAo develop a custom caching mechanism that I can apply to custom built user controls. (Please be aware that I know that there are some built in caching mechanism in .NET) Depending on certain flags set declaratively in the mark-up the control should load a cached version of its previously rendered content or execute normally (and if certain flags are set it should generate a cache of its content for next time it loads). I would like to be able to pass certain flags declaratively in the mark-up and being able to check their value at Page Init and, depending on the flag value, determine whether the control should load a cached version or not.
<uc:MyUC ID="N1" runat="server"
CacheProp='<%# SomeEnum.A | SomeEnum.B |SomeEnum.C %>'
PropA='<%# this.SomePropA %>'
PropB='<%# (this.SomePropB %>'
PropC='<%# this.SomePropC %>'
/>
The problem that I'm facing is that as far as I'm aware I can only get the value of the properties declaratively assigned in the mark-up if I called the DataBind(). However I'm faced with two problems:
Firstly calling this.DataBind()
from within MyUC
will trigger the binding of all its child controls which would defeat the purpose of the cache; also all user controls have been built so that they will not call DataBind()
before the LoadComplete
event has fired, so to make sure that the parent controls they live in has done its initialisation and has computed the properties that are declaratively passed to the child user control (ie PropA
, PropB
, PropC
).
And now the question: is there a way to bind the CacheProp
property so to retrieve its value without data binding all other properties and without triggering the data binding of all its child controls?
Thanks for helping!
Giuseppe
This should work:
<uc:MyUC ID="N1" runat="server" CacheProp="A|B|C"... >
Code behind:
strRawValue = N1.Attributes["CacheProp"];
string[] arrValues = strRawValue.Split('|');
SomeEnum value = (SomeEnum)Enum.Parse(typeof(SomeEnum), arrValues[0]);
for (int i = 1; i < arrValues.Length; i++)
value |= (SomeEnum)Enum.Parse(typeof(SomeEnum), arrValues[i]);
精彩评论