Hi,
I try to generate an OrgChart dynamically, for do that, I need to add actions to the orgChart item (by RadButton).
In my first POC, I try the programm below.
<%@ Control language="C#" Inherits="DotNetNuke.Modules.Quanteam.ContractModule.View" AutoEventWireup="false" Codebehind="View.ascx.cs" %>
<%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
<%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>
<
asp:MultiView
ID
=
"multiView"
runat
=
"server"
>
<
asp:View
ID
=
"ViewContractDetail"
runat
=
"server"
>
<
telerik:RadOrgChart
runat
=
"server"
ID
=
"radOrgChart"
>
<
Nodes
>
<
telerik:OrgChartNode
>
<
ItemTemplate
>
<
div
style
=
"background-color: Red; height: 80px; width: 180px;"
>
<
telerik:RadButton
ID
=
"TestBtnOrgChart"
Text
=
"click : 0"
runat
=
"server"
OnClick
=
"onClick_Handler"
ValidationGroup
=
"ParamValidationGroup"
ButtonType
=
"LinkButton"
BorderStyle
=
"None"
>
<
Icon
PrimaryIconUrl
=
"~/images/Add.gif"
PrimaryIconLeft
=
"5px"
/>
</
telerik:RadButton
>
</
div
>
</
ItemTemplate
>
<
GroupItems
>
<
telerik:OrgChartGroupItem
Text
=
"Click for Test"
/>
</
GroupItems
>
</
telerik:OrgChartNode
>
</
telerik:RadOrgChart
>
</
asp:View
>
</
asp:MultiView
>
private
void
Page_Load(
object
sender, System.EventArgs e)
{
try
{
System.Web.UI.WebControls.View view = FindControl(
"ViewContractDetail"
)
as
System.Web.UI.WebControls.View;
multiView.SetActiveView(view);
//----------------------------------------------------
// RadOrgChart
//----------------------------------------------------
var nodeContract =
new
OrgChartNode();
radOrgChart.Nodes.Add(nodeContract);
OrgChartGroupItem topContract =
new
OrgChartGroupItem() { Template =
new
MyTemplate(
"btnOrgChart1"
) };
nodeContract.GroupItems.Add(topContract);
var node =
new
OrgChartNode();
topContract.Node.Nodes.Add(node);
OrgChartGroupItem missionNode =
new
OrgChartGroupItem() { Template =
new
MyTemplate(
"btnOrgChart2"
, onClick_Handler) };
node.GroupItems.Add(missionNode);
//----------------------------------------------------
// RadButton
//----------------------------------------------------
RadButton radBtn =
new
RadButton();
radBtn.ID =
"btn_1"
;
radBtn.Text =
string
.Format(
"click : {0}"
, 0);
radBtn.Click += onClick_Handler;
view.Controls.Add(radBtn);
}
catch
(Exception exc)
//Module failed to load
{
Exceptions.ProcessModuleLoadException(
this
, exc);
}
}
class
MyTemplate : ITemplate
{
private
string
_id;
private
System.EventHandler _onClick;
public
MyTemplate(
string
id)
{
_id = id;
_onClick = onClick_Handler;
}
public
MyTemplate(
string
id, System.EventHandler onClick)
{
_id = id;
_onClick = onClick;
}
public
void
InstantiateIn(Control container)
{
RadButton radBtn =
new
RadButton();
radBtn.ID = _id;
radBtn.Text =
string
.Format(
"click {1} : {0}"
, 0, _id);
radBtn.Click += _onClick;
container.Controls.Add(radBtn);
}
protected
void
onClick_Handler(
object
sender, System.EventArgs e)
{
RadButton radBtn = sender
as
RadButton;
radBtn.Text =
string
.Format(
"click {1} : {0}"
, Convert.ToInt32(radBtn.Text.Split(
':'
)[1]) + 1, _id);
}
}
protected
void
onClick_Handler(
object
sender, System.EventArgs e)
{
RadButton radBtn = sender
as
RadButton;
string
[] items = radBtn.Text.Split(
':'
);
radBtn.Text =
string
.Format(
"{0} : {1}"
, items[0], Convert.ToInt32(items[1].Trim()) + 1);
}
When I try this program, the button created into the OrgChart by API call the Page_Load handler, but not the associated click handler.
Even if the handler came from the view or from the custom ITemplate class.
The two buttons of control :
- generated with the ASX and inside of the OrgChart
- generated with the API and outside of OrgChart
works normally.
Why my two Button generated with API into the OrgChar seems to don't call the Click event.
For information, I begin on ASP.Net since few week.
Thanks for your help.