Try our conversational search powered by Generative AI!

Hur gör man ( EPiServer.Web.PropertyControls )

Vote:
 
Hej Jag har gjort flera hemsnickrade Properties i nya EpiServer (som ärrver ifrån EPiServer.Web.PropertyControls.PropertyStringControl), och har då använt mig av kontroller i stil med: System.Web.UI.HtmlControls.HtmlSelect som den kontroll jag visar i Edit läget. Inga problem, funkar precis som det skall. När jag däremot försöker att skapa en helt egen control (som består av lite javascript, html element etc) kommer inte detta ut på sidan, vad är det jag missar eller inte förstår här ? Se kod nedan på ungefär hur jag försöker göra. Kontrollen jag försöker använda funkar såklart som den skall när jag använder den i en aspx sida, även såklart i en EpiServer aspx sida ... Väldigt tacksam för svar using System; using System.Collections.Generic; using System.Text; using EPiServer; using EPiServer.Core; using EPiServer.DataAbstraction; using EPiServer.Web.PropertyControls; using EPiServer.Web.WebControls; namespace MyNamespace { /// /// PropertyControl implementation used for rendering CustomProperty1 data. /// public class MyCustomControlPropertyControl : EPiServer.Web.PropertyControls.PropertyStringControl { protected MyCustomControl theControl = new MyCustomControl(); // obs, MyCustomControl-> ärver ifrån System.Web.UI.Control public override void CreateEditControls() { theControl = new MyCustomControl(); /* Försökte även med detta, men inte heller det tycks bita EPiServer.Core.PropertyControlClassFactory.Instance.RegisterClass( typeof(EPiServer.Core.PropertyString), typeof(MyCustomControl)); */ if(this.PropertyData.Value == null) { theControl.MyValue = "0,0"; } else { theControl.MyValue = this.PropertyData.Value.ToString(); } theControl.Visible = true; this.Controls.Add(theControl); } public override void CreateOnPageEditControls() { } public override void ApplyEditChanges() { base.SetValue(theControl.MyValue); } public MyCustomControlProperty MyCustomControlProperty { get { return PropertyData as MyCustomControlProperty; } } } }
#15858
Nov 07, 2007 3:01
Vote:
 
Tillägg Mitt problem är alltså att kontrollen (ingen av dess element förutom det namn jag tilldelat densamme i instansen av editfältet) inte ens visas i Epi's edit läge. Någon borde ha en hum om detta ? Tillägg 2 är att jag inte heller provat att göra liknande saker i tidigare versioner av Epi vad jag kan minnas, men jag tänker att någon kanske har en idé iallafall. Gör jag tex ett "typiskt" .NET fel, eller är det EpiServer som buggar eller vad ?
#16505
Nov 08, 2007 21:16
Vote:
 
You're missing the PageDefinitionTypePlugIn attribute. Your code should look similar to this model: [Serializable] [PageDefinitionTypePlugIn(DisplayName="Name of your custom control")] public class MyCustomControlCore : EPiServer.Core.PropertyString { public override IPropertyControl CreatePropertyControl() { return new MyCustomControl(); } } public class MyCustomControl : EPiServer.Web.PropertyControls.PropertyStringControl { /* Override CreateXXXControls to control the appearance of the property data in different rendering conditions. public override void CreateDefaultControls() - Used when rendering the view mode. public override void CreateEditControls() - Used when rendering the property in edit mode. public override void CreateOnPageEditControls() - used when rendering the property for "On Page Edit". */ }
#16506
Nov 11, 2007 11:36
Vote:
 
Ok So you mean that the special type of control that I /describe/want to do/ should work if I do like you do recommend ? Why are simpler properties working then ? Is there any explanataion to that ? See my earlier : " Jag har gjort flera hemsnickrade Properties i nya EpiServer (som ärrver ifrån EPiServer.Web.PropertyControls.PropertyStringControl), och har då använt mig av kontroller i stil med: System.Web.UI.HtmlControls.HtmlSelect som den kontroll jag visar i Edit läget. Inga problem, funkar precis som det skall. När jag däremot försöker att skapa en helt egen control (som består av lite javascript, html element etc) kommer inte detta ut på sidan, vad är det jag missar eller inte förstår här ? "
#16507
Nov 20, 2007 12:11
Vote:
 
Hi! I have investigated this some and have no problem with adding sub controls to the property. I do, however, get some problems with load order of posted data which means that the data is not updated correctly. I have not yet had time to solve this problem but I'll post the code I have used so far as it might you get you started. (We have other properties that uses sub controls that does not have this problem but I havn't found the difference yet.) In my code I have just customized the built in PropertyStringControl but just take the code and make a custom property out of it... using System; using System.Collections.Generic; using System.Text; using System.Web.UI.WebControls; using EPiServer.Core; namespace EPiServer.Web.PropertyControls { /// /// Property control that stores a short string (less than 255 characters). /// public class PropertyStringControl : PropertyTextBoxControlBase { private MyCustomWebControl _innerControl; public override void CreateEditControls() { _innerControl = new MyCustomWebControl(); _innerControl.Value = PropertyData.Value == null ? String.Empty : PropertyData.Value.ToString(); Controls.Add(_innerControl); } public override void ApplyEditChanges() { SetValue(_innerControl.GetValue()); } } public class MyCustomWebControl : WebControl { private string _value; private TextBox _inputBox; public TextBox InputBox { get { return _inputBox; } set { _inputBox = value; } } public string Value { get { return _value; } set { _value = value; } } protected override void CreateChildControls() { _inputBox = new TextBox(); _inputBox.Text = Value; Controls.Add(_inputBox); } public string GetValue() { EnsureChildControls(); return InputBox.Text; } } }
#16508
Nov 20, 2007 17:38
Vote:
 
I think that I have finally found the solution to the problem with loading posted data. Add the INamingContainer interface to your web control (in this case MyCustomWebControl) like this: public class MyCustomWebControl : WebControl, INamingContainer
#16509
Dec 05, 2007 9:52
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.