[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
Once we have separated the ControlPanel modes into Views, we will need to modify the way we used to navigate between the modes into the Views navigation. Let us again start by looking how we would typically change the ControlPanel mode in Sitefinity versions prior to 3.6. We will examine this approach on the built-in Lists module.
For example, in order to create a new list, we would provide our user with a following control:
Then, in the ControlPanel class we would wire the Command event of this LinkButton as follows:
|<asp:LinkButton ID="newListButton" runat="server" cssClass="CmsButLeft new" Text="<%$Resources:CreateNewList %>"></asp:LinkButton> |
And finally, in the Button_Command event handler, we would handle the “NewList” command as follows:
|this.cntAll.NewListButton.CommandName = "NewList"; |
|this.cntAll.NewListButton.Command += new CommandEventHandler(Button_Command); |
Which would then start the process of recreating child controls, this time with the Mode property being set to “NewList”? We have outlined numerous times the drawbacks of this approach. Let us know see how would we rewrite this same button for the new backend architecture introduced in Sitefinity 3.6.
|this.Mode = DisplayMode.NewList; |
First of all, instead of LinkButton we will now have HyperLink since, by clicking on the button we actually wish to go to a different url, not just perform a postback.
Secondly, we will not wire the control to any events, but will simply set it’s NavigateUrl property as follows:
|<asp:HyperLink ID="newListButton" runat="server" cssClass="CmsButLeft new" Text="<%$Resources:CreateNewList %>"></asp:HyperLink> |
And we are done. We will have to repeate this procedure for all the buttons which purpose used to be to switch the current mode of a given ControlPanel class.
|NewListButton.NavigateUrl = this.CreateHostViewCommand<ListInsert<AllListsView>>(); |