May 03, 2012, 10:13 AM
How to create Event Click at runtime on MenuItem created at runtime
Hi have the following error:
Errore server nell'applicazione '/SM2012'.
The control with ID 'MnuItm1' not found
asp.net Designer:
<ext:Viewport ID="ViewP" runat="server" Layout="BorderLayout">
<Items>
<ext:BorderLayout runat ="server">
<West>
<ext:Panel ID="pnlLeft" runat="server" Title="Profili" Width="200" MinWidth="100" MaxWidth="200" Split ="true" Margins="5 0 5 5" Collapsible="true" Layout="FitLayout" Region="West">
<Items>
<ext:MenuPanel ID="MnuPnlProfili" runat="server" Border="false">
<Menu ID="MnuProfili" runat="server">
<Items>
</Items>
</Menu>
</ext:MenuPanel>
</Items>
</ext:Panel>
</West>
<Center>
<ext:Panel ID="pnlCenter" runat="server" Title="Profilo Selezionato:" Margins="5 5 5 0" Padding="5" region="Center">
</ext:Panel>
</Center>
</ext:BorderLayout>
</Items>
</ext:Viewport>
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int idUtente = Convert.ToInt16((Session["USERID"].ToString().Split('|'))[0]);
//IMPOSTO CIO CHE L'UTENTE LOGGATO PUO FARE IN QUESTA PAGINA(A LIVELLO DI FUNZIONI) IN BASE AI SUOI PRIVILEGI
DataTable tbPrivilegi = ClsPrivilegi.GetTableFunctionPrivilegi(Enumeratori .TipoFunzionePrivilegi.AllPrivilegi, idUtente);
tbPrivilegi.Dispose();
MyConnection myconn = new MyConnection(ClsGlobal.GetConnectionString(ClsGlob al.NameConnectionString));
DataTable tbProfili = myconn.ExecuteStoredGet("SP_PROFILI_GET");
foreach (DataRow rgp in tbProfili.Rows)
{
Ext.Net.MenuItem itm = new Ext.Net.MenuItem(rgp["NOME"].ToString());
itm.ID = "MnuItm" + rgp["ID"].ToString();
itm.Icon = Ext.Net.Icon.BulletBlack;
itm.DirectEvents.Click.ExtraParams["PID"] = rgp["ID"].ToString();
itm.DirectEvents.Click.Event += new Ext.Net.ComponentDirectEvent.DirectEventHandler(It mMnuProfilo_Click);
MnuPnlProfili.Menu.Items.Add(itm);
}
MnuPnlProfili.Menu.DataBind();
myconn = null;
}
}
public void ItmMnuProfilo_Click(object sender, DirectEventArgs e)
{
string p = ((Ext.Net.MenuItem)sender).ID;
}
Help me!
Thanks in advance
Errore server nell'applicazione '/SM2012'.
The control with ID 'MnuItm1' not found
asp.net Designer:
<ext:Viewport ID="ViewP" runat="server" Layout="BorderLayout">
<Items>
<ext:BorderLayout runat ="server">
<West>
<ext:Panel ID="pnlLeft" runat="server" Title="Profili" Width="200" MinWidth="100" MaxWidth="200" Split ="true" Margins="5 0 5 5" Collapsible="true" Layout="FitLayout" Region="West">
<Items>
<ext:MenuPanel ID="MnuPnlProfili" runat="server" Border="false">
<Menu ID="MnuProfili" runat="server">
<Items>
</Items>
</Menu>
</ext:MenuPanel>
</Items>
</ext:Panel>
</West>
<Center>
<ext:Panel ID="pnlCenter" runat="server" Title="Profilo Selezionato:" Margins="5 5 5 0" Padding="5" region="Center">
</ext:Panel>
</Center>
</ext:BorderLayout>
</Items>
</ext:Viewport>
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int idUtente = Convert.ToInt16((Session["USERID"].ToString().Split('|'))[0]);
//IMPOSTO CIO CHE L'UTENTE LOGGATO PUO FARE IN QUESTA PAGINA(A LIVELLO DI FUNZIONI) IN BASE AI SUOI PRIVILEGI
DataTable tbPrivilegi = ClsPrivilegi.GetTableFunctionPrivilegi(Enumeratori .TipoFunzionePrivilegi.AllPrivilegi, idUtente);
tbPrivilegi.Dispose();
MyConnection myconn = new MyConnection(ClsGlobal.GetConnectionString(ClsGlob al.NameConnectionString));
DataTable tbProfili = myconn.ExecuteStoredGet("SP_PROFILI_GET");
foreach (DataRow rgp in tbProfili.Rows)
{
Ext.Net.MenuItem itm = new Ext.Net.MenuItem(rgp["NOME"].ToString());
itm.ID = "MnuItm" + rgp["ID"].ToString();
itm.Icon = Ext.Net.Icon.BulletBlack;
itm.DirectEvents.Click.ExtraParams["PID"] = rgp["ID"].ToString();
itm.DirectEvents.Click.Event += new Ext.Net.ComponentDirectEvent.DirectEventHandler(It mMnuProfilo_Click);
MnuPnlProfili.Menu.Items.Add(itm);
}
MnuPnlProfili.Menu.DataBind();
myconn = null;
}
}
public void ItmMnuProfilo_Click(object sender, DirectEventArgs e)
{
string p = ((Ext.Net.MenuItem)sender).ID;
}
Help me!
Thanks in advance