Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Custom FormEngineUserControl: Value property called before Load events View modes: 
User avatar
Member
Member
Peter - 12/16/2010 9:20:21 PM
   
Custom FormEngineUserControl: Value property called before Load events
Developing a basic FormEngineUserControl utilizing a standard asp:DropDownList control for use in a custom table (for CMS Desk usage) I noticed that Kentico attempts to assign my control a value (via the Value property) BEFORE any of my control Load methods are called. This seems a bit out of sequence as the class/method that triggers the Value property assignment is CMSModules_CustomTables_Controls_CustomTableForm/OnPreRender (there is some [External Code] in between but I assume that is in some compiled DLL).

Anyway the issue is that my Load event(s) load the drop down with its name-value list (as is typical in .NET page event sequence) so my control can hardly take a value assignment prior to that (or at least should not have to). I've worked around it for now but the situation was somewhat unexpected.

My question is is that shouldn't all child control Load events be triggered long before any PreRender events? Am I missing something?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 1/3/2011 6:22:18 AM
   
RE:Custom FormEngineUserControl: Value property called before Load events
Hi,

assigning of Value should not be dependable on the time, when your dropdown list values are generated.

The Value is assigned when the control is generated therefore you need to assigne it into some variable. Please take a look at following example:


private string mValue;

public override Object Value

get
{
return ddl.SelectedValue;
}
set
{
mValue = ValidationHelper.GetString(value, null);
ddl.SelectedValue = mvalue;
}

protected void Page_Load(object sender, EventArgs e)
{
if (dropDownList.Items.Count == 0)
{
// LOAD ITEMS
...
ddl.SelectedValue = mvalue;
}
}


How to add dropdown list into custom form control is described in appropriate section of devguide as well.

Best regards,
Ivana Tomanickova