Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > context is null in my TypeConverter.ConvertFrom() method

Reply
Thread Tools

context is null in my TypeConverter.ConvertFrom() method

 
 
lucianoluke@bol.com.br
Guest
Posts: n/a
 
      05-05-2006
Hi all,

I am trying to have a collection serialized to a property of the parent

control in HTML.


The collection items are controls found in the page. When the designer
is being loaded, My TypeConverter.ConvertFrom is called. The problem is

that ITypeDescriptorContext context is null.


I tryied creating a ControlDesigner and overriding
DesignTimeHtmlRequiresLoadComplete to always return true; No good. The
ConvertFrom is called BEFORE my ControlDesigner constructor's is even
called.


Is there any spell that I can cast to solve this problem?


my property attributes are:
Code:
-----------------------------------------
[Description("The tabs displayed on this control")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

[PersistenceMode(PersistenceMode.Attribute)]
[TypeConverter(typeof(TabCollectionTypeConverter))]
[Editor(typeof(TabCollectionUITypeEditor), typeof(UITypeEditor))]
public TabCollection TabPanels
{
get
{
object tabs = this.ViewState["TabPanels"] as
TabCollection;
if (tabs != null)
{
return (TabCollection) tabs;
}
return new TabCollection();
}
set
{
this.ViewState["TabPanels"] = value;
}



}


------------------------------------------------------
TabCollectionTypeConverter
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
TabCollection tc = new TabCollection();

if (context != null && value is string)
{
string[] v = ((string)value).Split(new char[] {','});
foreach (string s in v)
{
ComponentCollection components =
context.Container.Components;
foreach (IComponent component in components)
{
if (!(component is Control))
{
continue;
}


HPTabPanel ctrl =
(HPTabPanel)component;
if ((ctrl.ClientID != null) &&
(ctrl.ClientID.Length != 0) &&
ctrl.ClientID == s)
{
tc.Add(ctrl);
}
}
}
}


return tc;


}


-------------------------------------  UITypeEditor
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService editorService =
(IWindowsFormsEditorService)
provider.GetService(typeof(IWindowsFormsEditorService));
if (editorService == null)
{
return value;
}

// get forms editor service
IWindowsFormsEditorService wfes =
provider.GetService(typeof(IWindowsFormsEditorService)) as
IWindowsFormsEditorService;


// create our form
TabCollectionEditorForm form = new
TabCollectionEditorForm(context,
value as TabCollection);


// show our form
wfes.ShowDialog(form);


// Force designer update
context.OnComponentChanged();


// return updated value
return form.Tabs;
}


// just in case
return base.EditValue(context, provider, value);


}


------------------------------
Notice that I dont want to have InnerProperties and the like. I want my

control data string stored in a property.


Thanks for any input that may help.


Luciano Bargmann

 
Reply With Quote
 
 
 
 
Chris A.
Guest
Posts: n/a
 
      05-17-2006
See MSDN online help...

"Note Do not rely on the presence of this interface when you design a type
converter. If a particular interface, property, or service is necessary but
not available, the type converter should return a null reference (Nothing in
Visual Basic) rather than throw an exception. This interface's properties can
return a null reference (Nothing) at any time, and you should plan for this."

Meaning that context may (or not) always be null or undefined.
Unfortunately, this is a MS design SOOL that control authors must tolerate.

"(E-Mail Removed)" wrote:

> Hi all,
>
> I am trying to have a collection serialized to a property of the parent
>
> control in HTML.
>
>
> The collection items are controls found in the page. When the designer
> is being loaded, My TypeConverter.ConvertFrom is called. The problem is
>
> that ITypeDescriptorContext context is null.
>
>
> I tryied creating a ControlDesigner and overriding
> DesignTimeHtmlRequiresLoadComplete to always return true; No good. The
> ConvertFrom is called BEFORE my ControlDesigner constructor's is even
> called.
>
>
> Is there any spell that I can cast to solve this problem?
>
>
> my property attributes are:
>
Code:
> -----------------------------------------
> [Description("The tabs displayed on this control")]
> [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
>
> [PersistenceMode(PersistenceMode.Attribute)]
> [TypeConverter(typeof(TabCollectionTypeConverter))]
> [Editor(typeof(TabCollectionUITypeEditor), typeof(UITypeEditor))]
> public TabCollection TabPanels
> {
>         get
>         {
>                 object tabs = this.ViewState["TabPanels"] as
> TabCollection;
>                 if (tabs != null)
>                 {
>                         return (TabCollection) tabs;
>                 }
>                 return new TabCollection();
>         }
>         set
>         {
>                 this.ViewState["TabPanels"] = value;
>         }
>
>
>
> }
>
>
> ------------------------------------------------------
> TabCollectionTypeConverter
> public override object ConvertFrom(ITypeDescriptorContext context,
> CultureInfo culture, object value)
> {
>         TabCollection tc = new TabCollection();
>
>         if (context != null && value is string)
>         {
>                 string[] v = ((string)value).Split(new char[] {','});
>                 foreach (string s in v)
>                 {
>                         ComponentCollection components =
> context.Container.Components;
>                         foreach (IComponent component in components)
>                         {
>                                 if (!(component is Control))
>                                 {
>                                         continue;
>                                 }
>
>
>                                 HPTabPanel ctrl =
> (HPTabPanel)component;
>                                 if ((ctrl.ClientID != null) &&
> (ctrl.ClientID.Length != 0) &&
> ctrl.ClientID == s)
>                                 {
>                                         tc.Add(ctrl);
>                                 }
>                         }
>                 }
>         }
>
>
>         return tc;
>
>
> }
>
>
> -------------------------------------  UITypeEditor
> public override object EditValue(ITypeDescriptorContext context,
> IServiceProvider provider, object value)
> {
>         if (provider != null)
>         {
>                 IWindowsFormsEditorService editorService =
> (IWindowsFormsEditorService)
> provider.GetService(typeof(IWindowsFormsEditorService));
>                 if (editorService == null)
>                 {
>                         return value;
>                 }
>
>                 // get forms editor service
>                 IWindowsFormsEditorService wfes =
> provider.GetService(typeof(IWindowsFormsEditorService)) as
> IWindowsFormsEditorService;
>
>
>                 // create our form
>                 TabCollectionEditorForm form = new
> TabCollectionEditorForm(context,
> value as TabCollection);
>
>
>                 // show our form
>                 wfes.ShowDialog(form);
>
>
>                 // Force designer update
>                 context.OnComponentChanged();
>
>
>                 // return updated value
>                 return form.Tabs;
>         }
>
>
>         // just in case
>         return base.EditValue(context, provider, value);
>
>
> }
>
>
> ------------------------------
>
>
> Notice that I dont want to have InnerProperties and the like. I want my
>
> control data string stored in a property.
>
>
> Thanks for any input that may help.
>
>
> Luciano Bargmann
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Context.User is Null in the LoggedIn method of the Login Control Maxus ASP .Net 0 04-12-2007 06:42 AM
Cannot invoke Call with null namespace URI for method null raviupasi@gmail.com Java 0 05-12-2006 01:34 PM
context is null in my TypeConverter.ConvertFrom() method lucianoluke@bol.com.br ASP .Net Web Controls 1 05-05-2006 01:11 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
Context.Items vs Context.Handler (passing values between pages) VS_NET_DEV ASP .Net 2 05-25-2004 01:16 PM



Advertisments