Re: How to implement a property like ControlToValidate property?



Thanks for your help!
I have solved my problem!

“KMILO”编写:

> Im doing the same thing as you, but the following error appears "Unable to generate code for a value of type 'System.Web.UI.HtmlControls.HtmlInputHidden'. This error occurred while trying to generate the property value for CajaDeTexto"
> but I solve the situation implementing this typeconverter to a String property:
>
> #region TypeConverter
> public class HtmlControlConverter : StringConverter
> {
> public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
> {
> return true;
> }
> public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
> {
> return false;
> }
> public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
> {
> if ((context == null) || (context.Container == null))
> {
> return null;
> }
> Object[] serverControls = this.GetControls(context.Container);
> if (serverControls != null)
> {
> return new StandardValuesCollection(serverControls);
> }
> return null;
> }
> private object[] GetControls(IContainer container)
> {
> ArrayList availableControls = new ArrayList();
> foreach( IComponent component in container.Components )
> {
> Control serverControl = component as Control;
> if ( serverControl != null &&
> !(serverControl is Page) &&
> serverControl.ID != null &&
> serverControl.ID.Length != 0 &&
> IncludeControl(serverControl)
> )
> {
> availableControls.Add(serverControl.ID);
> }
> }
> availableControls.Sort(Comparer.Default);
> return availableControls.ToArray();
> }
> private bool IncludeControl(Control serverControl)
> {
> bool ReturnedVal = false;
> string ControlType = serverControl.GetType().ToString();
> switch(ControlType)
> {
> case "System.Web.UI.HtmlControls.HtmlInputHidden":
> ReturnedVal = true;
> break;
> case "System.Web.UI.HtmlControls.HtmlGenericControl":
> ReturnedVal = true;
> break;
> case "System.Web.UI.HtmlControls.HtmlInputText":
> ReturnedVal = true;
> break;
> case "System.Web.UI.HtmlControls.HtmlTable":
> ReturnedVal = true;
> break;
> }
> return ReturnedVal;
> }
> }
> #endregion
>
> And the implementation looks like this:
>
> #region TypeConverterImplementation
> private string _cajadetexto;
> [Bindable(false),Category("Controls"),TypeConverter(typeof(HtmlControlConverter))]
> //,EditorAttribute(typeof(System.Web.UI.Design.HtmlControlDesigner), typeof(System.Web.UI.HtmlControls.HtmlInputHidden))]
> public virtual string CajaDeTexto
> {
> get {return _cajadetexto;}
> set {_cajadetexto = value;}
> }
> #endregion
>
> This was a easy way to get out the trouble, if you knows any way better let me know it....
>
> Cheers
>
> KMILO
.



Relevant Pages

  • Re: Extending MembershipUser
    ... public override void Initialize(string name, ... public override bool EnablePasswordRetrieval ... public override int MaxInvalidPasswordAttempts ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to implement a property like ControlToValidate property?
    ... >> but I solve the situation implementing this typeconverter to a String ... >> public override bool GetStandardValuesSupported(ITypeDescriptorContext ... >> context) ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Hashtable
    ... public override bool Equalsund ... public override int GetHashCode(), es wunderbar klappt. ... UniqueKeyDictionary<Person, string> dic = ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Reflection in 1.1 and 2.0
    ... private string _firstName; ... public override bool CanResetValue ... public override bool ShouldSerializeValue ...
    (microsoft.public.dotnet.languages.csharp)
  • Reflection in 1.1 and 2.0
    ... private string _firstName; ... public override bool CanResetValue ... public override bool ShouldSerializeValue ...
    (microsoft.public.dotnet.framework.clr)

Loading