Dec 03, 2009, 12:07 PM
How can I receive all Portlet(dynamically created) in the AnchorLayout
Hi,
I am trying to get all portlet(dynamically created) in the AnchorLayout with code below.
All suggestions are welcome.
Thank you in advance
I am trying to get all portlet(dynamically created) in the AnchorLayout with code below.
<ext:Button ID="BtnShowModules" AutoPostBack="true" onclick="BtnShowModules_Click" runat="server" Text="Show Page Modules"/>
<ext:Button ID="BtnSavePositions" Visible="false" runat="server" Text="Save the position">
<AjaxEvents>
<Click OnEvent="BtnSavePositions_Click">
<EventMask ShowMask="true" />
<ExtraParams>
<ext:Parameter Name="Message" Value="Positions are saved successfully." />
</ExtraParams>
</Click>
</AjaxEvents>
</ext:Button>
<ext:LayoutColumn ColumnWidth=".10">
<ext:PortalColumn Title="Modules" ID="PortalColumnModules" runat="server" StyleSpec="padding:10px 0 10px 10px" >
<Body>
<ext:AnchorLayout ID="AnchorLayoutModules" runat="server">
<ext:Anchor Horizontal="100%">
<ext:Portlet ID="Portlet2" runat="server" Title="Portlet Modules">
</ext:Portlet>
</ext:Anchor>
</ext:AnchorLayout>
</Body>
</ext:PortalColumn>
</ext:LayoutColumn>
//function for creating dynamic portlet
public void GetModulesByPageID(int PageID)
{
using (MYEntities db = new MYEntities())
{
var pageModules2 = from mdl in db.TRM_Pages_Modules
where mdl.TRM_Pages.ID == PageID orderby mdl.TRM_Locations.ID,mdl.Sequence
select new { ID = mdl.TRM_Modules.ID, ModuleName = mdl.TRM_Modules.Name, LocationID = mdl.TRM_Locations.ID, Sequence=mdl.Sequence };
foreach (var modules in pageModules2.ToList())
{
Anchor ModulesAnchor = new Anchor();
Portlet ModulesPortlet = new Portlet();
ModulesPortlet.Title = modules.ModuleName;
ModulesPortlet.ID = modules.ID.ToString();
ModulesAnchor.Items.Add(ModulesPortlet);
AnchorLayoutModules.Anchors.Add(ModulesAnchor);
}
}
}
//after Clicking BtnSavePositions button <br style="font-weight: bold;">
protected void BtnSavePositions_Click(object sender, AjaxEventArgs e)
{
AnchorLayout PortalColumnLeftObj = ControlUtils.FindControl<AnchorLayout>(this.Page, "AnchorLayoutLeft");
//Save left part
int position = 0;
foreach (var item in PortalColumnLeftObj.Items)
{
string moduleId = item.ID;
string moduleName = item.ProductName;
}
Ext.Msg.Alert("Save Position", string.Format("{0}", e.ExtraParams["Message"])).Show();
}
//create portlet dynamically
protected void BtnShowModules_Click(object sender, EventArgs e)
{
int selectedItemInt;
bool chkSelecttedItem = Int32.TryParse(ComboWebSites.SelectedItem.Value, out selectedItemInt);
if (chkSelecttedItem)
{
GetModulesByPageID(selectedItemInt);
}
BtnSavePositions.Visible = true;
//GetAllModules();
}
I can see all portlet on the screen but I cannot get them(by clicking button) even by drop event(in the Portal) like this <ext:Portal ID="Portal1" runat="server" Title="Portal" >
<AjaxEvents>
<Drop OnEvent="Drop">
<ExtraParams>
<ext:Parameter Name="id" Value="e.panel.id" Mode="Raw" />
<ext:Parameter Name="parentID" Value="e.portal.id" Mode="Raw" />
<ext:Parameter Name="index" Value="e.columnIndex" Mode="Raw" />
<ext:Parameter Name="pos" Value="e.position" Mode="Raw" />
</ExtraParams>
</Drop>
</AjaxEvents>
[AjaxMethod]
public void Drop(object sender, AjaxEventArgs e)
{
//I can see the all parameters right.
string id = e.ExtraParams["id"].ToString();
string portalID = e.ExtraParams["parentID"].ToString();
string cindex = e.ExtraParams["index"].ToString();
string postion = e.ExtraParams["pos"].ToString();
this.PortletMiddle.Html = "id:" + id + " PID:" + portalID + " Column:" + cindex + " pos:" + postion;
//Just one Portlet is coming which is Portlet1 (this is not being created dynamically)
AnchorLayout PortalColumnLeftObj = ControlUtils.FindControl<AnchorLayout>(this.Page, "AnchorLayoutLeft");
//Save left part
int position = 0;
foreach (var item in PortalColumnLeftObj.Items)
{
string moduleId = item.ID;
string moduleName = item.ProductName;
}
}
Actually, it will be enough to get it by DROP EVENTAll suggestions are welcome.
Thank you in advance