Fluent API for inserting Controls
The Fluent API does not allow for the insertion of a Control into a Page Object.
App.WorkWith().Page(myPage).Controls().add(MyControl,
"placeholder"
)
Yup second that! Need to be able to populate the page as well as create it :)
Just watched your fluent API screencast Lino, was a great intro, thanks!
Matt
Thanks a million Matt, I am glad you liked it :)
Hi Lino,
You are right, there is still no fluent api for that. We have plans to have this too :)
Actually the fluent API is there but it is not visible at this level for this facade. You may add controls on page creation:
App.WorkWith()
.Page()
.CreateNew()
//create new page, working with Page facade
.Do(p => p.Name =
"Page1"
)
.Control()
//access to Control facade
.CreateNew()
//Create new Control, working with Control facade
.Do(c => c.Caption =
"My New Control in placeholder1"
)
.Do(c => c.PlaceHolder =
"Placeholder1"
)
.Done()
//Exit the Control facade, we are now back to Page facade
.Control()
.CreateNew()
.Do(c => c.Caption =
"My New Control in placeholder2"
)
.Do(c => c.PlaceHolder =
"Placeholder1"
)
.Done()
//Exit the control facade
.CreateNew()
//will be called for the page facade
.Do(p => p.Name =
"Page2"
)
.SaveChanges();
Thanks Georgi,
Hi Lino,
We are keep working on the API and makes some changes. We appreciate your input here and we will make the changes that will give you more flexibility using the API. Apart from that there is a way to add a control on a page to a given holder with standard API. You can use mgr.CreateControl<PageControl>(control, holderID). Then you can call PageNode.Page.Controls.Add(mycontrol); and save the changes with SaveChanges() of PageManager class.
Regards,
Ivan Dimitrov
the Telerik team
Thanks Ivan,
Hi Lino,
Let me shed some light on the pages API. Actually the CreateNew(...) method is meant to be protected and I guess the example that Georgi wrote is a bit older. You should call CreateNewStandardPage() or CreateNewPageGroup() method to create new page. We are going to also introduce external page soon. The reason these are separate methods is because they return different facades. Although, in both cases we are working with page nodes both have very different characteristics, for example controls don't make sense for page groups.
Here is the correct code:
App.WorkWith()
.Page()
.CreateNewStandardPage()
// returns standard page facade
.Do(pn =>
pn.Title =
"My Test Page"
;
)
.CheckOut()
// creates a draft vresion and locks the page
.Control()
// the fluent API allows adding conrols only to drafts
.CreateNew(
new
Label() Text =
"My Test Label"
,
"Content"
)
.Done()
.Publish()
.SaveChanges();
Be aware that currently there is no easy way to control the order of the controls within a place holder with the API. This is due to the fact that the controls in a place holder can be mixed with controls coming from a chain of inherited page templates. Sitefinity allows you to insert controls between controls defined in a base template. Currently we rely on the UI layer to get information about the siblings of a control, but we are going to move this logic to the fluent API.
I hope this can help you better understand our ideas. We are open for suggestions and now is the best time for discussing the API design.
Greetings,
Bob
the Telerik team
Thanks Bob,
Hello Lino,
That's correct..
We'll have this in the Dev. Manual by the end of the week!
Sorry for the inconvenience.