SamuraiProgrammer.Web.UI - v0.5
One of my friends suggested that I should provide a download for all of the little code snippets, controls, etc. that I throw up on my blog so people don't have to constantly copy/paste into their IDE of choice.
I thought about it and it sounded like a good idea but I think I'll do things a little bit different. I fully intend to provide code downloads for each of my blog entries, but in addition to that, I'm going to expand upon them in a separate download. The reason for this is that many times, I post very very simple solutions to common problems or issues. I always leave it as an exercise for the reader to further enhance the simple code I provide.
I like the way this works, but a lot of times I do the enhancing myself. So, I might as well make that code available as well. In this initial release (arbitrarily set as v0.5), I provide the following controls:
- ValueCheckBox - This was a control that I described here and is simply a CheckBox with an additional property (CheckBoxValue) that can be used in a grid/list/anywhere where you want to store an actual useful value for quick reference later.
- ConditionalDisplayPanel - This was a control that I initially described here and was a simple way to hide portions of a templated control from the user at runtime. Since its first creation, though, I've actually enhanced this quite a bit. Using something similar to the GridView/SQLDataSource binding model, I have made this control a lot more flexible and extensible.
When you add this control to your page, you can specify in your XHTML a SuccessTemplate and a FailureTemplate. Within each template, as with most templated controls, you can specify the controls/HTML to appear for each condition. For example:<sp:ConditionalDisplayPanel
runat="server" ID="cdpTest"
EvaluationSourceId="cesCustomCheck">
<FailureTemplate>
<asp:Label runat="server"
ID="lblFailure"
Text="Failure"></asp:Label>
</FailureTemplate>
<SuccessTemplate>
<asp:Label runat="server"
ID="lblSuccess"
Text="Success"></asp:Label>
</SuccessTemplate>
</sp:ConditionalDisplayPanel>
- EvaluationSource - In order to provide looser coupling between the uses of this control and the control itself, these simple controls provide a nice abstracted method of providing the condition for which the FailureTemplate and SuccessTemplate appear. All EvaluationSource controls implement the IEvaluationSource interface which provides a method of evaluating success or failure. The EvaluationSources included in this release are:
RoleEvaluationSource: Provides a method to evaluate against a user's role membership. <sp:RoleEvaluationSource runat="server"
ID="resRoleCheck"
RoleName="Test">
</sp:RoleEvaluationSource>FieldEvaluationSource: Provides a method to evaluate against a a null or empty field value in a DataView.<sp:FieldEvaluationSource runat="server"
ID="fesAttributeName"
FieldName="AttributeName">
</sp:FieldEvaluationSource>CustomEvaluationSource: Allows the developer to specify their own logic to be evaluated. <sp:CustomEvaluationSource runat="server"
ID="cesCustomCheck">
</sp:CustomEvaluationSource>Then, in the code behind, you simply handle the CustomValidate event raised in the control to provide your own logic to evaluate. Protected Sub cesCustomCheck_CustomValidate( _
ByVal source As Object, _
ByVal args As CustomValidateEventArgs) _
Handles cesCustomCheck.CustomValidate
args.IsValid = True
End Sub
- ControlPersister - This allows you to specify the values in one or more controls on a page and save them to a cookie when a certain event is raised by another control on the page. In addition, the control will place the values back into the controls when the user next visits that page. An example of the XHTML would be useful here perhaps:
<sp:ControlPersister runat="server"
id="fpSearchFields"
PersistenceKey="Search"
PersistenceTypeName="cookie">
<Sources>
<sp:ControlSource ControlName="txtSearchCriteria"
ControlProperty="Text"
Name="SearchCriteria1"
Type="String" />
<sp:ControlSource ControlName="ddlSearchCriteria2"
ControlProperty="SelectedValue"
Name="SearchCriteria2"
Type="String" />
<sp:ControlSource ControlName="chkSearchCriteria3"
ControlProperty="Checked"
Name="SearchCriteria3"
Type="Boolean" />
</Sources>
<SaveTriggers>
<sp:SaveTrigger ControlId="btnSearch"
Name="SearchButton" />
</SaveTriggers>
<ResetTriggers>
<sp:ResetTrigger ControlId="btnReset"
Name="ResetButton" />
</ResetTriggers>
</sp:ControlPersister>
Here is an explanation of each property on the base ControlPersister control:
PersistenceKey: A string value representing the name of the cookie for this page. This is useful if you have more than one ControlPersister on a page.
PersistenceTypeName: A string value representing the medium in which these values should be stored. For this version of the control, only a "cookie" is available. In future versions, you will be able to store the values in Session, Database or even using a File Based persistence model.
Here is an explanation of each property on the ControlSource object:
ControlName: A string value representing the name of the control to persist.
ControlProperty: A string value representing the property of the control from which you should persist the values of the control. This property is also used to *set* the value of the property on the initial page load.
Name: A string value representing the name of the instance of the ControlSource.
Type: A string value representing the type of data to be stored.
Here is an explanation of each property on the SaveTrigger object:
ControlId: A string value representing the name of the control that would trigger the save operation of this control. The control referenced here must implement the IButtonControl interface which exposes the Click event.
Name: A string value representing the name of the instance of the SaveTrigger.
Here is an explanation of each property on the ResetTrigger object:
ControlId: A string value representing the name of the control that would trigger the reset operation of this control. When the user clicks this button, any values being persisted would be cleared and would not load the next time the page loaded. The control referenced here must implement the IButtonControl interface which exposes the Click event.
Name: A string value representing the name of the instance of the ResetTrigger.
I think that's it for this version of the SamuraiProgrammer.Web.UI. You can download the assembly here. I'll try to get some samples posted within the next week or so.
Any questions or comments, please feel free to comment or contact me via the link on this page.
Enjoy!