Current Site Version: 1.0.0.0

Variable Substitution Context

A control to use when you need to define the constraints around replacing variables in a given piece of text.

Here is an example of defining a VariableSubstitutionContext:

<cf:VariableSubstitutionContext runat="server" ID="PhoneBookVariableSubstitutionContext">
    <cf:VariableSubstitutionDefinition Identifier="firstName" Description="The Individual's First Name"/>
    <cf:VariableSubstitutionDefinition Identifier="lastName" Description="The Individual's Last Name"/>
</cf:VariableSubstitutionContext>

Then you would apply the VariableSubstitutionContext to a string, lets use a hard-coded string as as example:

var rawText = "Your name would appear in the phone book as '{lastName}, {firstName}'";

PhoneBookVariableSubstitutionContext.Set("firstName", "Brian");
PhoneBookVariableSubstitutionContext.Set("lastName", "Pegram");

PhoneBookVariableSubstitutionContextResult.Text = PhoneBookVariableSubstitutionContext.Apply(rawText);

The result of our variable substitution is:

Your name would appear in the phone book as 'Pegram, Brian'


Variable Substituted CMS Editable Region

A derivation of CMSEditableRegion (which is Kentico's way of offering configurable text/html) that utilizes a VariableSubstitutionContext.

Here is an example of defining a VariableSubstitutedCmsEditableRegion:

<cf:VariableSubstitutedCmsEditableRegion runat="server" ID="BirthDayConfigurableMessage">
    <cf:VariableSubstitutionDefinition Identifier="birthDay" Description="The Individual's birthday"/>
    <cf:VariableSubstitutionDefinition Identifier="daysUntilBirthDay" Description="Number of days until Individual's birthday"/>
</cf:VariableSubstitutedCmsEditableRegion>

You set values in the same way as a VariableSubstitutionContext and the underlying variable substitution context is ultimately applied to the CMSEditableRegion:

var birthDay = new DateTime(1986, 5, 10);
var birthDayThisYear = new DateTime(DateTime.Now.Year, 5, 10);
var birthDayNextYear = birthDayThisYear.AddYears(1);
var nextBirthDay = DateTime.Now > birthDayThisYear ? birthDayNextYear : birthDayThisYear;
var daysUntilBirthDay = (nextBirthDay - DateTime.Now).Days;
var ageOnNextBirthday = nextBirthDay.Year - birthDay.Year;

BirthDayConfigurableMessage.Set("birthDay", birthDay.ToString("MMM dd, yyyy"));
BirthDayConfigurableMessage.Set("daysUntilBirthDay", daysUntilBirthDay.ToString());
BirthDayConfigurableMessage.Set("ageOnNextBirthday", ageOnNextBirthday.ToString());

The "template" configured in the CMSEditableRegion's content is:

The CMSEditableRegion will render it's text with the variable substitution applied:


Animated Update Panel

You should use an AnimatedUpdatePanel to display a "loading" spinner overlay during processing.

<cf:AnimatedUpdatePanel runat="server"
    <ContentTemplate>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus velit quis nunc ultrices, et rhoncus lectus placerat. Phasellus varius diam quis nibh volutpat, nec tincidunt risus gravida. Nulla non libero sed nulla congue fermentum. Curabitur at congue sem, at viverra ante. Curabitur nec aliquet lectus. Phasellus a tempus justo. Donec tincidunt augue sit amet iaculis ornare. In hac habitasse platea dictumst. Quisque tincidunt, augue tincidunt porttitor suscipit, nunc elit tempor metus, vitae faucibus felis lacus in ipsum. Etiam lacinia leo in dui consectetur laoreet.</p>
        
        <asp:Button runat="server" OnClick="AnimatedUpdatePanelSubmit" CssClass="btn btn-primary" Text="Submit"/>
    </ContentTemplate>
</cf:AnimatedUpdatePanel>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus velit quis nunc ultrices, et rhoncus lectus placerat. Phasellus varius diam quis nibh volutpat, nec tincidunt risus gravida. Nulla non libero sed nulla congue fermentum. Curabitur at congue sem, at viverra ante. Curabitur nec aliquet lectus. Phasellus a tempus justo. Donec tincidunt augue sit amet iaculis ornare. In hac habitasse platea dictumst. Quisque tincidunt, augue tincidunt porttitor suscipit, nunc elit tempor metus, vitae faucibus felis lacus in ipsum. Etiam lacinia leo in dui consectetur laoreet.

You can use the Message and DisplayMessageAfter properties to display a message, after some delay, during processing.

<cf:AnimatedUpdatePanel runat="server" Message="Five seconds have elapsed, sorry for the delay!" DisplayMessageAfter="5000">
    <ContentTemplate>
        <p>Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam aliquet tellus a feugiat feugiat. Sed facilisis rutrum eros, in posuere neque iaculis in. Praesent iaculis urna metus, sed egestas arcu fringilla eget. Aenean cursus nulla non arcu maximus ornare. Sed quis egestas neque. Quisque efficitur eu magna id fringilla. Etiam sed viverra leo, eget ullamcorper libero. Vivamus commodo pellentesque purus, ut dictum dolor sodales sed. In nulla mauris, venenatis efficitur tristique et, congue id mauris. Nunc ornare urna quis arcu viverra consequat. Fusce sit amet posuere nibh. Curabitur ante dolor, accumsan eu neque a, maximus tempus tortor.</p>
        
        <asp:Button runat="server" OnClick="AnimatedUpdatePanelDisplayMessageSubmit" CssClass="btn btn-primary" Text="Submit"/>
    </ContentTemplate>
</cf:AnimatedUpdatePanel>

Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam aliquet tellus a feugiat feugiat. Sed facilisis rutrum eros, in posuere neque iaculis in. Praesent iaculis urna metus, sed egestas arcu fringilla eget. Aenean cursus nulla non arcu maximus ornare. Sed quis egestas neque. Quisque efficitur eu magna id fringilla. Etiam sed viverra leo, eget ullamcorper libero. Vivamus commodo pellentesque purus, ut dictum dolor sodales sed. In nulla mauris, venenatis efficitur tristique et, congue id mauris. Nunc ornare urna quis arcu viverra consequat. Fusce sit amet posuere nibh. Curabitur ante dolor, accumsan eu neque a, maximus tempus tortor.