Hallo zusammen
Seit Stunden versuche ich ein ganz triviales Custom Control zum Laufen zu
bringen. Das Custom Control hat zwei Image Controls und ein Attribut "Expanded".
Je nachdem ob "Expanded" true oder false ist soll beim einen Image Contorl
ein anderes Bild angezeigt werden.
Ich habe festgestellt, dass ich die Attribute ImageUrlExpanded/ImageUrlCollapsed
verliere wenn ich das Attribute ImageUrl im Code habe. Entferne ich dieses
so klappts. Liegt es an der Methode EnsureChildControls()? Diese muss ich
aber verwenden weil man sonst im Visual Studio Designer einen Fehler erh�lt...
Ich w�re mehr als dankbar f�r Hilfe. Es kann doch nicht so schwierig sein...?
Code:
########################################################
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace My.WebControls
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:MyButton runat=server></{0}:MyButton>")]
public class MyButton : WebControl
{
//Used by toggleImage
private string imageUrlExpanded;
private string imageUrlCollapsed;
private Image toggleImage;
//The image
private Image 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;
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string ImageUrlCollapsed
{
get
{
return this.imageUrlCollapsed;
}
set
{
this.imageUrlCollapsed = value;
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string ImageUrl
{
get
{
this.EnsureChildControls();
return this.image.ImageUrl;
}
set
{
this.EnsureChildControls();
this.image.ImageUrl = value;
}
}
protected override void CreateChildControls()
{
this.image = new Image();
Label label = new Label();
label.Text = "Expanded: " + this.expanded
+"<br>ImageUrlExpanded: " +
this.ImageUrlExpanded + "<br>ImageUrlCollapsed: " + this.ImageUrlCollapsed
+"<br>ImageUrl: " + this.ImageUrl;
this.Controls.Add(label);
}
}
}
########################################################
_______________________________________________
Asp.net Mailingliste, Postings senden an:
[email protected]
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net