PDA

View Full Version : [CLOSED] How to change and save Portal control's content ??



wangyi
Aug 15, 2013, 10:59 AM
I want to dynamic add Portal control's content .
But I encountered two problems.

1)When PortletReSet mehtod executed, the Portal control's content does not change?

2)In PortletSave method, the portal.Items is empty?

Help!!!

aspx:


<ext:Portal ID="PortalMain" runat="server" Border="false" >
</ext:Portal>

<ext:Button runat="server" ID="BtnResetPorlet" Text="reset Width="70">
<DirectEvents>
<Click OnEvent="PortletReSet"></Click>
</DirectEvents>
</ext:Button>

<ext:Button runat="server" ID="BtnSavePortlet" Text="save" Width="70">
<DirectEvents>
<Click OnEvent="PortletSave"></Click>
</DirectEvents>
</ext:Button>


cs code:


protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
BindPortelet("10");
}
}

private void BindPortelet(string columnIndex)
{
PortalMain.Items.Clear();
PortalColumn tempcolumn = new PortalColumn();
tempcolumn.ID = "column" + columnIndex ;

Portlet templet = new Portlet();
templet.ID = "p1";
templet.Title = "p1"

tempcolumn.Items.Add(templet);

PortalMain.Items.Add(tempcolumn);


PortalMain.DataBind();
PortalMain.DoLayout();
}


protected void PortletReSet (object sender, DirectEventArgs e)
{
BindPortelet("200");
}



// portal.Items is empty, count=0?
protected void PortletSave (object sender, DirectEventArgs e)
{
string ids = "";

foreach (Portal portal in ControlUtils.FindControls<Portal>(this.Page))
{
foreach (PortalColumn tempcolumn in portal.Items )
{
foreach (Portlet tempportlet in tempcolumn.Items)
{
ids += tempportlet.ID + ",";
}
}
}

}

Daniil
Aug 15, 2013, 2:11 PM
Hi @wangyi,



1)When PortletReSet mehtod executed, the Portal control's content does not change?


To render a control dynamically during a DirectEvent, you should render it manually. I.e. it is not enough to add a control to a container's Items and call a container's DoLayout or DataBind methods. By the way, you can remove the last two.

In your scenario, i.e. adding PortalColumn dynamically, I can suggest to re-render an entire Portal if it is an appropriate option.

Example

private void BindPortelet(string columnIndex)
{
PortalMain.Items.Clear();
PortalColumn tempcolumn = new PortalColumn();
tempcolumn.ID = "column" + columnIndex;

Portlet templet = new Portlet();
templet.ID = "p1";
templet.Title = "p1";

tempcolumn.Items.Add(templet);
PortalMain.Items.Add(tempcolumn);

if (X.IsAjaxRequest)
{
PortalMain.Render();
}
}

To do not lose the Portal's position on the page, please wrap it in an Ext.NET Container.


2)In PortletSave method, the portal.Items is empty?


If you create something during one DirectEvent, it is not automatically recreated (neither by Ext.NET or ASP.NET) during another DirectEvent. So, if you need to access all the dynamically added Items you should recreate them during each request. Though, it might get complicated. So, can you clarify why do you need it? To render something into a Portlet. If so, please take a look at this example.
http://examples2.ext.net/#/XRender/Advanced/Parent_Add_Children/

wangyi
Aug 19, 2013, 2:19 AM
Thanks for help!