How can present a form in a user control for reuse throughout the Web site?
Versions:
4.70,
FAQ number:
11,
Old FAQ number: 929
Q: I want to present a form in a user control for reuse throughout the Web site. How could this be done?
A: A nice way to use a form on the first page that can be changed at any time is to have a reference on the startpage to another page containing the form. If you are using an <episerver:property id="StartPageForm" runat="server" /> tag the content of the property can be loaded from code-behind.
Page_Init()
{
PageData remoteFormPage = GetPage((PageReference)CurrentPage["RemoteFormProperty"]);
PropertyForm form = (PropertyForm)remoteFormPage.Property["RemoteForm"];
StartPageForm.InnerProperty = form;
}
Problem: When I am submitting it the form isn't saved in the database.
A: The problem might be that the function CreateChildControls is executed before the Page_Load() event when you post data. The solution is to set up the form in the Page_Init() event. You also have to handle the form posting in your page. This is normally done in the method Page_PreRender in Form.ascx.cs in the sample project.