PDA

View Full Version : [CLOSED] how to get number of panels in the window?



tobros
Jun 04, 2013, 7:19 AM
<ext:Window runat="server" Width="320" ID="w_docwin" Hidden="True" Modal="True" Title="附件管理" Layout="AccordionLayout">
</ext:Window>
<ext:NumberField Icon="TextListNumbers" ID="nf_doc" runat="server" InputWidth="60" EmptyText="0">
<DirectEvents>
<IconClick OnEvent="e_doclick"></IconClick>
</DirectEvents>
</ext:NumberField>



protected void e_doclick(object sender, DirectEventArgs e)
{

if (nf_doc.Value != null)
{
var n = (int)nf_doc.Number;

int c = w_docwin.Items.Count;//how to get panel number in the w_docwin window?

if (n > c) //if n>c
{
for (int i = 0; i < n-c; i++) //add number of n-c panels until its number is n;
{
var p = new Ext.Net.Panel();
var tf = new TextField { FieldLabel = "附件名称" };
var tf1 = new TextField { FieldLabel = "附件描述" };
var tf2 = new TextField { FieldLabel = "其他描述" };
var upload = new FileUploadField { FieldLabel = "文件", ButtonText = "浏览" };

p.Items.Add(tf);
p.Items.Add(tf1);
p.Items.Add(tf2);
p.Items.Add(upload);
w_docwin.Items.Add(p);
p.Render();
}
}
w_docwin.Show();
}

Daniil
Jun 04, 2013, 9:02 AM
Hi @tobros,

If you render something during one DirectEvent, it is absolutely unknown during another DirectEvent unless you recreate it manually.

You can store required info somewhere (for example, in Session) during initial rendering of dynamic controls. Another approach (and I like it much more) send required info from client side as an extra parameter of a DirectEvent.

win.items.getCount();

tobros
Jun 04, 2013, 9:17 AM
Hi @tobros,

If you render something during one DirectEvent, it is absolutely unknown during another DirectEvent unless you recreate it manually.

You can store required info somewhere (for example, in Session) during initial rendering of dynamic controls. Another approach (and I like it much more) send required info from client side as an extra parameter of a DirectEvent.

win.items.getCount();


not getCount method

Daniil
Jun 04, 2013, 10:14 AM
How exactly are you trying?

tobros
Jun 05, 2013, 12:56 AM
How exactly are you trying?



protected void e_doclick(object sender, DirectEventArgs e)
{

if (nf_doc.Value != null)
{
var n = (int)nf_doc.Number;

int c = w_docwin.Items.Count;//how to get panel number in the w_docwin window?
w_docwin.Items.getCount();//not getCount method
if (n > c)
{
for (int i = 0; i < n-c; i++)
{
var p = new Ext.Net.Panel();
var tf = new TextField { FieldLabel = "附件名称" };
var tf1 = new TextField { FieldLabel = "附件描述" };
var tf2 = new TextField { FieldLabel = "其他描述" };
var upload = new FileUploadField { FieldLabel = "文件", ButtonText = "浏览" };

p.Items.Add(tf);
p.Items.Add(tf1);
p.Items.Add(tf2);
p.Items.Add(upload);
w_docwin.Items.Add(p);
p.Render();
}
}
w_docwin.Show();
}

Baidaly
Jun 05, 2013, 2:32 AM
Hello!

If window items is static you can identify them on the server-side, but if window has dynamic items you should send them from client side:



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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Examples</title>

<script runat="server">
public void Click(object sender, DirectEventArgs e)
{
X.Msg.Alert("Count", string.Format("Server side items count = {0}; Client side items count = {1}", Window1.Items.Count(), e.ExtraParams["count"])).Show();
}
</script>

</head>
<body>
<ext:ResourceManager runat="server" />

<ext:Window runat="server" Layout="HBox" Width="600" Height="400" ID="Window1">
<LayoutConfig>
<ext:HBoxLayoutConfig Align="Stretch"/>
</LayoutConfig>
<Items>
<ext:Panel runat="server" ID="Panel1" Height="100" Flex="1"></ext:Panel>
<ext:Panel runat="server" ID="Panel2" Height="100" Flex="1"></ext:Panel>
<ext:Panel runat="server" ID="Panel3" Height="100" Flex="1"></ext:Panel>
<ext:Panel runat="server" ID="Panel4" Height="100" Flex="1"></ext:Panel>
</Items>
<Buttons>
<ext:Button runat="server" Text="Click me ">
<DirectEvents>
<Click OnEvent="Click">
<ExtraParams>
<ext:Parameter Name="count" Value="#{Window1}.items.getCount()" Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:Window>
</body>
</html>





int c = w_docwin.Items.Count;

This code should work. Variable c should contain items count. You don't need to call GetCount method