Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Setting Visibility with Community Server Forms

Form Controls are new to Community Server 2007 as part of Chameleon and bring new capabilities to the business-as-usual process of creating ASP.NET forms.   One of the features of Chameleon Form Controls I like is the ease in setting the visibility of individual controls. 

The Chameleon Form I created today demonstrates how to easily display success messages on submit using the <SuccessActions /> and  SetVisibilityAction control.  Observing the bold code below we see that the "SuccessMsg" CSResourceControl displays on form success and the "FormArea" CSPlaceholder control is hidden.  Each property can act on multiple controls. 

 

<DBVTSiteControl:AdvertiseForm
    AdvertisePostsDropDownListId="advertisePostsDropDownList"
    AdvertiseYearDropDownListId="advertiseYearDropDownList"
    DirectoryDropDownListId="directoryDropDownList"
    SubmitButtonId="SubmitButton" runat="server" CssClass="BigForm">

    <SuccessActions>
        <CSControl:SetVisibilityAction runat="server" ControlIdsToShow="SuccessMsg"
         ControlIdsToHide="FormArea" ID="VisibilityControl" />
    </SuccessActions>

    <FormTemplate>
    <CSControl:PlaceHolder runat="server" ID="FormArea">
    .....
    </CSControl:PlaceHolder>
    <CSControl:ResourceControl ID="SuccessMsg" runat="server"
        ResourceName="AdvertiseForm_SuccessMessage"
        CssClass="BigMessage" Visible="false" />
    </FormTemplate>
</DBVTSiteControl:AdvertiseForm>
   

 

This is also extensible as demonstrated in, for example, the blog contact form which hides the Username and Email Address for registered users.  A custom property can be created, as in this case, a ControlIdsToHideFromRegisteredUsers property.  This will add the controls to hide in the Form Control's AttachChildControl() method and sets visibility to false in the Databind() method.

 

protected override void AttachChildControls()
{
    .....
    string[] controlIds = ControlIdsToHideFromRegisteredUsers.Split(',');
    ControlsToHideFromRegisteredUsers = new List<Control>();
    if (controlIds != null && controlIds.Length > 0)
    {
    foreach (string controlId in controlIds)
    {
        Control c = WeblogControlUtility.Instance().FindControl(this, controlId);
        if (c != null)
        ControlsToHideFromRegisteredUsers.Add(c);
    }
    }
}

public override void DataBind()
{
    .....
    if (Page.Request.IsAuthenticated)
    {
    foreach (Control c in this.ControlsToHideFromRegisteredUsers)
    {
        c.Visible = false;
    }
    }
}

Comments (2) | Post RSS RSS comment feed

Posted on 8/13/2007 8:42:42 PM by Dave Burke
Categories: .NET | Community Server
Tags:

Related posts

Comments (2) -

8/22/2007 8:59:02 AM Permalink

Do Chameleon controls only work in the new theme? ive tried using them wihtin the lean and green theme but they do't seem to be working? im running cs2007

Lee |

8/22/2007 10:24:56 AM Permalink

Lee, I know for sure that they work in lean and green.  It's probably something that will be obvious once you find out what the trouble is.  Good luck.  

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke