Member
1 Points
10 Posts
Nov 28, 2013 05:15 PM|fur.attila|LINK
CustomControl is not doing anything rigth now, it is only for test purpose.
Here is my testpage (complete markup):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="Default2" %>
<%@ Register assembly="CustomControls" namespace="CustomControls" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:CustomControl ID="CustomControl1" runat="server">
<CalendarImageButton ImageUrl="~/Images/add.png" />
</cc1:CustomControl>
<br />
</div>
</form>
</body>
</html>
Here is the code for the so called "CustomControl":
using System.Web.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Web.UI.HtmlControls;
namespace CustomControls
{
[ToolboxData("<{0}:CustomControl runat=server></{0}:CustomControl>")]
[ToolboxBitmap(typeof(Calendar))]
[ParseChildren(ChildrenAsProperties = true)]
public class CustomControl : CompositeControl
[Category("Appearance")]
[Description("Sets the image for the calendar control")]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public ImageButton CalendarImageButton
get
EnsureChildControls();
return (ImageButton)ViewState["CalendarImageButton"];
}
set
ViewState["CalendarImageButton"] = value;
UpdatePanel updatePanel;
protected override void RecreateChildControls()
protected override void CreateChildControls()
Controls.Clear();
ViewState["CalendarImageButton"] = new ImageButton();
updatePanel = new UpdatePanel();
updatePanel.ID = "updatePanel";
updatePanel.ContentTemplateContainer.Controls.Add((ImageButton)ViewState["CalendarImageButton"]);
this.Controls.Add(updatePanel);
This control is not doing anything, I just want to get rendered the CalendarImageButton's Image on PageLoad event from in the markup data.
Thanks for trying to help!
Member
1 Points
10 Posts
Re: ASP.NET servercontrol subcontrol as property default value set in properties doesn't render
Nov 28, 2013 05:15 PM|fur.attila|LINK
CustomControl is not doing anything rigth now, it is only for test purpose.
Here is my testpage (complete markup):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="Default2" %>
<%@ Register assembly="CustomControls" namespace="CustomControls" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:CustomControl ID="CustomControl1" runat="server">
<CalendarImageButton ImageUrl="~/Images/add.png" />
</cc1:CustomControl>
<br />
</div>
</form>
</body>
</html>
Here is the code for the so called "CustomControl":
using System.Web.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Web.UI.HtmlControls;
namespace CustomControls
{
[ToolboxData("<{0}:CustomControl runat=server></{0}:CustomControl>")]
[ToolboxBitmap(typeof(Calendar))]
[ParseChildren(ChildrenAsProperties = true)]
public class CustomControl : CompositeControl
{
[Category("Appearance")]
[Description("Sets the image for the calendar control")]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public ImageButton CalendarImageButton
{
get
{
EnsureChildControls();
return (ImageButton)ViewState["CalendarImageButton"];
}
set
{
EnsureChildControls();
ViewState["CalendarImageButton"] = value;
}
}
UpdatePanel updatePanel;
protected override void RecreateChildControls()
{
EnsureChildControls();
}
protected override void CreateChildControls()
{
Controls.Clear();
ViewState["CalendarImageButton"] = new ImageButton();
updatePanel = new UpdatePanel();
updatePanel.ID = "updatePanel";
updatePanel.ContentTemplateContainer.Controls.Add((ImageButton)ViewState["CalendarImageButton"]);
this.Controls.Add(updatePanel);
}
}
}
This control is not doing anything, I just want to get rendered the CalendarImageButton's Image on PageLoad event from in the markup data.
Thanks for trying to help!