AW: AW: [Asp.net] Einfaches Custom Control Problem?

2005-01-06 Diskussionsfäden Andreas Rudischhauser
Das geht aber doch mit einem bool expanded nicht... oder willst du das so
machen, dass, soblad ImageUrl gesetzt ist, hat das vorang?

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von [EMAIL PROTECTED]
Gesendet: Donnerstag, 6. Januar 2005 12:45
An: asp.net@glengamoi.com
Betreff: RE: AW: [Asp.net] Einfaches Custom Control Problem?

Ich hab mich vermutlich unklar ausgedrückt. Aber jetzt hast du in deinem
Beispiel einfach das eine Bild entfernt. Letztendlich soll es im Custom
Control
ein Bild, welches abhängig vom Attribut Expanded ist und ein Bild, welches
irgend ein anderes Bild anzeigt, haben:

--
Bild Expanded od Collapsed ¦  Irgendeinbild  ¦
--


-- Original-Nachricht --
From: Andreas Rudischhauser [EMAIL PROTECTED]
To: asp.net@glengamoi.com
Subject: AW: [Asp.net] Einfaches Custom Control Problem?
Reply-To: asp.net@glengamoi.com
Date: Thu, 6 Jan 2005 12:26:21 +0100


Es geht sogar noch cooler wenn du von Image ableitest:

   using System;
   using System.Web.UI;
   using System.Web.UI.WebControls;
   using System.ComponentModel;

   namespace test
   {
   /// summary
   /// Summary description for WebCustomControl1.
   /// /summary
   [DefaultProperty(Text), 
   ToolboxData({0}:MyButton runat=server/{0}:MyButton)]
   public class MyButton : Image
   {
   
   //Hier sperre ich das Setzten der ImageUrl
   public override string ImageUrl
   {
   get
   {
   return base.ImageUrl;
   }
   }

   
   
   [Bindable(true), 
   Category(Appearance), 
   DefaultValue(true)] 
   public bool Expanded
   {
   get
   {
   return this.expanded;
   }

   set
   {
   this.expanded = value;
   }
   }
   private bool expanded = true;
   
   [Bindable(true), 
   Category(Appearance), 
   DefaultValue()] 
   public string ImageUrlExpanded 
   {
   get
   {
   return this.imageUrlExpanded;
   }
   set
   {
   this.imageUrlExpanded = value;
   }
   }
   private string imageUrlExpanded = ;

   [Bindable(true), 
   Category(Appearance), 
   DefaultValue()] 
   public string ImageUrlCollapsed 
   {
   get
   {
   return this.imageUrlCollapsed;
   }

   set
   {
   this.imageUrlCollapsed = value;
   }
   }
   private string imageUrlCollapsed = ;

   protected override void OnLoad(EventArgs e)
   {
   base.OnLoad (e);
   base.ImageUrl = (this.expanded) ?
this.imageUrlExpanded : this.imageUrlCollapsed;
   }
   }
   }


___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net


AW: AW: [Asp.net] Einfaches Custom Control Problem?

2005-01-06 Diskussionsfäden Andreas Rudischhauser
Sorry, jetzt hab ichs verstanden, das rechte Bild ist immer am start :)

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von [EMAIL PROTECTED]
Gesendet: Donnerstag, 6. Januar 2005 12:45
An: asp.net@glengamoi.com
Betreff: RE: AW: [Asp.net] Einfaches Custom Control Problem?

Ich hab mich vermutlich unklar ausgedrückt. Aber jetzt hast du in deinem
Beispiel einfach das eine Bild entfernt. Letztendlich soll es im Custom
Control
ein Bild, welches abhängig vom Attribut Expanded ist und ein Bild, welches
irgend ein anderes Bild anzeigt, haben:

--
Bild Expanded od Collapsed ¦  Irgendeinbild  ¦
--


-- Original-Nachricht --
From: Andreas Rudischhauser [EMAIL PROTECTED]
To: asp.net@glengamoi.com
Subject: AW: [Asp.net] Einfaches Custom Control Problem?
Reply-To: asp.net@glengamoi.com
Date: Thu, 6 Jan 2005 12:26:21 +0100


Es geht sogar noch cooler wenn du von Image ableitest:

   using System;
   using System.Web.UI;
   using System.Web.UI.WebControls;
   using System.ComponentModel;

   namespace test
   {
   /// summary
   /// Summary description for WebCustomControl1.
   /// /summary
   [DefaultProperty(Text), 
   ToolboxData({0}:MyButton runat=server/{0}:MyButton)]
   public class MyButton : Image
   {
   
   //Hier sperre ich das Setzten der ImageUrl
   public override string ImageUrl
   {
   get
   {
   return base.ImageUrl;
   }
   }

   
   
   [Bindable(true), 
   Category(Appearance), 
   DefaultValue(true)] 
   public bool Expanded
   {
   get
   {
   return this.expanded;
   }

   set
   {
   this.expanded = value;
   }
   }
   private bool expanded = true;
   
   [Bindable(true), 
   Category(Appearance), 
   DefaultValue()] 
   public string ImageUrlExpanded 
   {
   get
   {
   return this.imageUrlExpanded;
   }
   set
   {
   this.imageUrlExpanded = value;
   }
   }
   private string imageUrlExpanded = ;

   [Bindable(true), 
   Category(Appearance), 
   DefaultValue()] 
   public string ImageUrlCollapsed 
   {
   get
   {
   return this.imageUrlCollapsed;
   }

   set
   {
   this.imageUrlCollapsed = value;
   }
   }
   private string imageUrlCollapsed = ;

   protected override void OnLoad(EventArgs e)
   {
   base.OnLoad (e);
   base.ImageUrl = (this.expanded) ?
this.imageUrlExpanded : this.imageUrlCollapsed;
   }
   }
   }


___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net


AW: AW: [Asp.net] Einfaches Custom Control Problem?

2005-01-06 Diskussionsfäden Andreas Rudischhauser
Also 

1. Dein fehler kommt daher, dass du das Image image nicht mit new Image()
initialisiert hattest. Dann kannst du natürlich auch nicht mit .ImageUrl
darauf zugreifen.

2. So ist aber besser programmiert. Controls sollten nur in
CreateChildControls zusammengesetzt werden. Wenn man es genau nimmt solltest
du die Daten sogar erst in PreRender() einfügen.


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace test
{
/// summary
/// Summary description for WebCustomControl1.
/// /summary
[DefaultProperty(Text), 
ToolboxData({0}:MyButton runat=server/{0}:MyButton)]
public class MyButton : WebControl
{
//Used by toggleImage
private Image toggleImage = new Image();
private Image normalImage = new Image();

//Defines which image to display
private bool expanded = true;

[Bindable(true), 
Category(Appearance), 
DefaultValue(true)] 
public bool Expanded
{
get
{
return this.expanded;
}

set
{
this.expanded = value;
}
}


[Bindable(true), 
Category(Appearance), 
DefaultValue()] 
public string ImageUrlExpanded 
{
get
{
return this.imageUrlExpanded;
}
set
{
this.imageUrlExpanded = value;
}
}
private string imageUrlExpanded = ;

[Bindable(true), 
Category(Appearance), 
DefaultValue()] 
public string ImageUrlCollapsed 
{
get
{
return this.imageUrlCollapsed;
}

set
{
this.imageUrlCollapsed = value;
}
}
private string imageUrlCollapsed = ;

[Bindable(true), 
Category(Appearance), 
DefaultValue()] 
public string ImageUrl
{
get
{
return this.imageUrl;
}

set
{
this.imageUrl = value;
}
}
private string imageUrl = ;



protected override void CreateChildControls()
{
this.toggleImage.ImageUrl = (this.expanded) ?
this.imageUrlExpanded : this.imageUrlCollapsed;
this.Controls.Add(toggleImage);

this.normalImage.ImageUrl = this.imageUrl;
this.Controls.Add(normalImage);
}
}
}


___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net


RE: AW: AW: [Asp.net] Einfaches Custom Control Problem?

2005-01-06 Diskussionsfäden pmoser
So klappts tatsächlich auf den ersten Blick. Leider wird aber in Visual Studio
 in der Vorschau nur ein weisser Fleck angezeigt. Also habe ich versucht
ein Designer zu implementieren, etwa so:

public class MyDesigner : ControlDesigner
{
public NodeDesigner()   {}

public override string GetDesignTimeHtml()
{
return base.GetDesignTimeHtml();
}
}

Funktioniert jedoch nicht - Keine Vorschau...


-- Original-Nachricht --
From: Andreas Rudischhauser [EMAIL PROTECTED]
To: asp.net@glengamoi.com
Subject: AW: AW: [Asp.net] Einfaches Custom Control Problem?
Reply-To: asp.net@glengamoi.com
Date: Thu, 6 Jan 2005 13:24:22 +0100


Also 

1. Dein fehler kommt daher, dass du das Image image nicht mit new Image()
initialisiert hattest. Dann kannst du natürlich auch nicht mit .ImageUrl
darauf zugreifen.

2. So ist aber besser programmiert. Controls sollten nur in
CreateChildControls zusammengesetzt werden. Wenn man es genau nimmt solltest
du die Daten sogar erst in PreRender() einfügen.


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace test
{
   /// summary
   /// Summary description for WebCustomControl1.
   /// /summary
   [DefaultProperty(Text), 
   ToolboxData({0}:MyButton runat=server/{0}:MyButton)]
   public class MyButton : WebControl
   {
   //Used by toggleImage
   private Image toggleImage = new Image();
   private Image normalImage = new Image();
   
   //Defines which image to display
   private bool expanded = true;
   
   [Bindable(true), 
   Category(Appearance), 
   DefaultValue(true)] 
   public bool Expanded
   {
   get
   {
   return this.expanded;
   }

   set
   {
   this.expanded = value;
   }
   }
   

   [Bindable(true), 
   Category(Appearance), 
   DefaultValue()] 
   public string ImageUrlExpanded 
   {
   get
   {
   return this.imageUrlExpanded;
   }
   set
   {
   this.imageUrlExpanded = value;
   }
   }
   private string imageUrlExpanded = ;

   [Bindable(true), 
   Category(Appearance), 
   DefaultValue()] 
   public string ImageUrlCollapsed 
   {
   get
   {
   return this.imageUrlCollapsed;
   }

   set
   {
   this.imageUrlCollapsed = value;
   }
   }
   private string imageUrlCollapsed = ;

   [Bindable(true), 
   Category(Appearance), 
   DefaultValue()] 
   public string ImageUrl
   {
   get
   {
   return this.imageUrl;
   }

   set
   {
   this.imageUrl = value;
   }
   }
   private string imageUrl = ;



   protected override void CreateChildControls()
   {
   this.toggleImage.ImageUrl = (this.expanded) ?
this.imageUrlExpanded : this.imageUrlCollapsed;
this.Controls.Add(toggleImage);

   this.normalImage.ImageUrl = this.imageUrl;
   this.Controls.Add(normalImage);
   }
   }
}


___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

___
Asp.net Mailingliste, Postings senden an:
Asp.net@glengamoi.com
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net