PDA

View Full Version : [CLOSED] Portlet Dynamic Create problem



gs_user
Aug 21, 2012, 4:05 AM
Hello!

Following is my Code

I'm Create Portlet in Code-Behide
and i use DirectEvents(widget_add_click) to create a new portlet ,it's not working!

Why? how to do this?




<%@ Page Language="C#" %>

<%@ Import Namespace="Ext.Net.Utilities" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
RefreshPortal();
}

}


protected void RefreshPortal()
{

Portal1.Items.Clear();

//塞PortalColumn,最多四欄
PortalColumn pc1 = this.GetPortalColumn("0.25");
pc1.Items.Add(GetPortlet("test1", "C", ""));
this.Portal1.Items.Add(pc1);

PortalColumn pc2 = this.GetPortalColumn("0.25");
pc2.Items.Add(GetPortlet("test2", "C", ""));
this.Portal1.Items.Add(pc2);

PortalColumn pc3 = this.GetPortalColumn("0.25");
pc3.Items.Add(GetPortlet("test3", "C", ""));
this.Portal1.Items.Add(pc3);

PortalColumn pc4 = this.GetPortalColumn("0.25");
pc4.Items.Add(GetPortlet("test4", "C", ""));
this.Portal1.Items.Add(pc4);

Portal1.Render();
}

private PortalColumn GetPortalColumn(string columnWidth)
{
PortalColumn pc = new PortalColumn();
pc.Layout = "anchor";
if (!(columnWidth == ""))
pc.ColumnWidth = Convert.ToDouble(columnWidth);

return pc;
}

private Portlet GetPortlet(string title, string type, string content)
{
Portlet p = new Portlet()
{
ID = title,
Title = title,
Height = 200,
};

if (type == "G") //Grid
{
//
}
else if (type == "C") //Chart
{

}
else if (type == "L") //Link
{
p.Height = 500;
p.Loader = new ComponentLoader
{
Url = content,
Mode = LoadMode.Frame,
LoadMask =
{
ShowMask = true,
}
};
}

return p;
}

protected void Add_Block(object sender, DirectEventArgs e)
{
//DO something
w_Widget.Show();

}

protected void widget_add_click(object sender, DirectEventArgs e)
{
// add portlet in the last column
foreach (PortalColumn pc in ControlUtils.FindControls<PortalColumn>(Portal1))
{
if (pc.ID == "pc4")
pc.Items.Add(this.GetPortlet(cb_Widget.SelectedIte m.Value, "C", ""));
else if (pc.ID == "pc3")
pc.Items.Add(this.GetPortlet(cb_Widget.SelectedIte m.Value, "C", ""));
else if (pc.ID == "pc2")
pc.Items.Add(this.GetPortlet(cb_Widget.SelectedIte m.Value, "C", ""));
else if (pc.ID == "pc1")
pc.Items.Add(this.GetPortlet(cb_Widget.SelectedIte m.Value, "C", ""));
break;
}
w_Widget.Close();
}
</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title>Portal in TabPanel - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" type="text/css" />

<style type="text/css">
.x-column-padding{
padding : 10px 0px 10px 10px;
}

.x-column-padding1{
padding : 10px;
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
<Items>
<ext:TabPanel ID="TabPanel1"
runat="server"
Region="Center"
ActiveTabIndex="0"
Title="TabPanel"
MarginsSummary="5 5 5 0">
<Items>
<ext:Panel ID="Panel4" runat="server" Title="Tab 1" Layout="Fit" >
<TabMenu>
<ext:Menu ID="Menu1" runat="server">
<Items>
<ext:MenuItem ID="MenuItem1" runat="server" Text="_Widget_Setting" Icon="BorderAll" >
<DirectEvents>
<Click OnEvent="Add_Block" >
<EventMask ShowMask="true" />
</Click>
</DirectEvents>
</ext:MenuItem>
</Items>
</ext:Menu>
</TabMenu>
<Items>
<ext:Portal ID="Portal1" runat="server" Border="false">
<Items>
<ext:PortalColumn ID="PortalColumn1"
runat="server"
Cls="x-column-padding">
<Items>
<ext:Portlet ID="Portlet1" runat="server" Title="Another Panel 1" Icon="Accept" />
</Items>
</ext:PortalColumn>
<ext:PortalColumn ID="PortalColumn2"
runat="server"
Cls="x-column-padding">
<Items>
<ext:Portlet ID="Portlet2" runat="server" Title="Panel 2" />
<ext:Portlet ID="Portlet3" runat="server" Title="Another Panel 2" />
</Items>
</ext:PortalColumn>
<ext:PortalColumn ID="PortalColumn3"
runat="server"
Cls="x-column-padding1">
<Items>
<ext:Portlet ID="Portlet4" runat="server" Title="Panel 3" />
<ext:Portlet ID="Portlet5" runat="server" Title="Another Panel 3" />
</Items>
</ext:PortalColumn>
</Items>
</ext:Portal>
</Items>
</ext:Panel>
<ext:Panel ID="Panel5" runat="server" Title="Tab 2" Layout="Fit">
<Items>
<ext:Portal ID="Portal2" runat="server" Border="false">
<Items>
<ext:PortalColumn ID="PortalColumn4"
runat="server"
Cls="x-column-padding">
<Items>
<ext:Portlet ID="Portlet7" Title="Another Panel 3" runat="server" />
</Items>
</ext:PortalColumn>
<ext:PortalColumn ID="PortalColumn5"
runat="server"
Cls="x-column-padding">
<Items>
<ext:Portlet ID="Portlet8" Title="Panel 2" runat="server" />
<ext:Portlet ID="Portlet9" Title="Another Panel 2" runat="server" />
</Items>
</ext:PortalColumn>
<ext:PortalColumn ID="PortalColumn6"
runat="server"
Cls="x-column-padding1">
<Items>
<ext:Portlet ID="Portlet10" Title="Another Panel 1" runat="server" />
</Items>
</ext:PortalColumn>
</Items>
</ext:Portal>
</Items>
</ext:Panel>
</Items>
</ext:TabPanel>
</Items>
</ext:Viewport>

<ext:Window
ID="w_Widget"
runat="server"
Resizable="false"
Height="150"
Icon="BorderAll"
Title="_Widget_Setting"
Draggable="false"
Width="350"
Modal="True"
Padding="5"
AutoDestroy="False" Layout = "FormLayout" Hidden="True" >
<Items>
<ext:FormPanel ID="FormPanel2" runat="server" Height="120" Width="340" Padding="5" Layout="AbsoluteLayout">
<Items>
<ext:ComboBox ID="cbWedgit_Type" runat="server" FieldLabel="_Wedgit_Type" X="10" Y="10">
<Items>
<ext:ListItem Text="_One_Column" Value="1" />
<ext:ListItem Text="_Two_Column" Value="2" />
<ext:ListItem Text="_Three_Column" Value="3" />
<ext:ListItem Text="_1_Large_2_Small" Value="4" />
</Items>
</ext:ComboBox>
<ext:ComboBox ID="cb_Widget" runat="server" FieldLabel="_Widget_Add" Width="200" X="10" Y="40">
<Items>
<ext:ListItem Text="test5" Value="test5" />
<ext:ListItem Text="test6" Value="test6" />
<ext:ListItem Text="test7" Value="test7" />
<ext:ListItem Text="test8" Value="test8" />
</Items>
</ext:ComboBox>
<ext:Button ID="bt_widget_add_click" runat="server" Text="_Add" Icon="ApplicationAdd" X="230" Y="40" >
<DirectEvents>
<Click OnEvent="widget_add_click" />
</DirectEvents>
</ext:Button>
</Items>
<Buttons>
<ext:Button ID="Button1" runat="server" Text="_Close" Icon="Door" >
<Listeners>
<Click Handler="#{w_Widget}.hide();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Items>
</ext:Window>
</form>
</body>
</html>

Daniil
Aug 21, 2012, 11:25 AM
Hi,

It is not enough during DirectEvent to just put the control into the Items collection.

You should render the control, as here:
http://examples2.ext.net/#/XRender/Basic/Add_Items/

gs_user
Aug 22, 2012, 2:03 AM
thank you for your reply

Actually,

I use ControlUtils.FindControls<PortalColumn>
but find is MarkUp things ,Instead of function(RefreshPortal) create things

why?

Daniil
Aug 22, 2012, 5:30 AM
Are you asking why some controls created in some DirectEvent are not available during another DirectEvent? Because these controls are not automatically recreated. Neither ASP.NET or Ext.NET recreates any controls automatically.

gs_user
Aug 22, 2012, 10:36 AM
thank you for your reply~

My English is Pool, and asp.net is Pool....HAHA...


Let me put it another way.

Thank you!

Daniil
Aug 22, 2012, 11:02 AM
My English is Pool, and asp.net is Pool....HAHA...

Apologize, not sure what you mean under "Pool". Any synonym?