[FIXED] [#269] [2.x] how to add window's item from session to another window's item?

Page 1 of 3 123 LastLast
  1. #1

    [FIXED] [#269] [2.x] how to add window's item from session to another window's item?

    my goal is : when click a NumberField , then pop a window which contain the some panel which num is save as the numberfield's Number .
    when the numberfield's Number is less then the current panel's number, then remove the redundant num, if the numberfield's Number is more, then
    add the panel until the number is same.

    <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">
                                                        <ExtraParams>
                                                            <ext:Parameter Name="count" Value="#{w_docwin}.items.getCount()" Mode="Raw"/>
                                                        </ExtraParams>
                                                    </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 =int.Parse(e.ExtraParams["count"].ToString());//先有的数目
                   
                    if (n > c)//if is more than current panel's number in the window
                    {
                        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();
                        }
                    } else if (n < c)//if is less than the current panel's number in the winow.
                    {
                        Window attaWindow = (Window)Session["pz_atta"];//get window from store.
                        for (int i = n; i < c; i++)
                        {
                            attaWindow.Items.RemoveAt(n);//remove the redundant  panel.
                        }
                        w_docwin.Items.Clear();   //?
                        w_docwin.Items.AddRange(attaWindow.Items);//?  here how to add the attaWindow's items to the window w_docwin?
                    }
                    Session["pz_atta"] = w_docwin;   //use session to store window.
                    w_docwin.Show();
                }
    how to do ?
    thanks.
    Last edited by fabricio.murta; Apr 27, 2016 at 12:36 AM.
  2. #2
    Hi @tobros,

    Sorry, I don't quite follow the scenario, but can say something for sure - it is a bad idea to store controls in Session. Here is a related discussion for more details.
    http://bytes.com/topic/asp-net/answe...sion-variables

    I do not quite understand why you need to store those controls in Session. Could you provide us with a full example which would demonstrate the scenario?
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @tobros,

    Sorry, I don't quite follow the scenario, but can say something for sure - it is a bad idea to store controls in Session. Here is a related discussion for more details.
    http://bytes.com/topic/asp-net/answe...sion-variables

    I do not quite understand why you need to store those controls in Session. Could you provide us with a full example which would demonstrate the scenario?
    sample code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script runat="server">
    
            protected void e_doclick(object sender, DirectEventArgs e)
            {
    
                if (nf_doc.Value != null)
                {
                    var n = (int)nf_doc.Number; //设置的数目
                    int c = int.Parse(e.ExtraParams["count"].ToString()); //先有的数目
    
                    if (n > c) //if is more than current panel's number in the window
                    {
                        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();
                        }
                    }
                    else if (n < c) //if is less than the current panel's number in the winow.
                    {
                        Window attaWindow = (Window)Session["pz_atta"]; //get window from store.
                        for (int i = n; i < c; i++)
                        {
                            attaWindow.Items.RemoveAt(n); //remove the redundant  panel.
                        }
                        w_docwin.Items.Clear(); //?
                        w_docwin.Items.AddRange(attaWindow.Items); //?  here how to add the attaWindow's items to the window w_docwin?
                    }
                    Session["pz_atta"] = w_docwin; //use session to store window.
                    w_docwin.Show();
                }
            }
    
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server"></ext:ResourceManager>
            <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">
                        <ExtraParams>
                            <ext:Parameter Name="count" Value="#{w_docwin}.items.getCount()" Mode="Raw" />
                        </ExtraParams>
                    </IconClick>
                </DirectEvents>
    
            </ext:NumberField>
    
        </form>
    </body>
    </html>
  4. #4
    Hello!

    for (int i = n; i < c; i++)
    {
    	attaWindow.Items.RemoveAt(n); //remove the redundant  panel.
    }
    ASP.NET is stateless and you cannot remove dynamic items also it's not safe and good to store Windows in Session. Better to save ID of the window.

    I can suggest the following approach:

    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <!DOCTYPE html>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script runat="server">
     
            protected void e_doclick(object sender, DirectEventArgs e)
            {
     
                if (nf_doc.Value != null)
                {
                    var n = (int)nf_doc.Number; //设置的数目
                    int c = int.Parse(e.ExtraParams["count"].ToString()); //先有的数目
     
                    if (n > c) //if is more than current panel's number in the window
                    {
                        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();
                        }
                    }
                    else if (n < c) //if is less than the current panel's number in the winow.
                    {
                        string attaWindow = (string)Session["pz_atta"]; //get window from store.
                        for (int i = n; i < c; i++)
                        {
                            X.AddScript(string.Format("App.{0}.items.removeAt({1});", attaWindow, n));
                        }
                        X.GetCmp<Window>(attaWindow).Call("doLayout");
                        //w_docwin.Items.Clear(); //?
                        ///w_docwin.Items.AddRange(attaWindow.Items); //?  here how to add the attaWindow's items to the window w_docwin?
                    }
                    Session["pz_atta"] = w_docwin.ID; //use session to store window.
                    w_docwin.Show();
                }
            }
     
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server"></ext:ResourceManager>
            <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">
                        <ExtraParams>
                            <ext:Parameter Name="count" Value="#{w_docwin}.items.getCount()" Mode="Raw" />
                        </ExtraParams>
                    </IconClick>
                </DirectEvents>
     
            </ext:NumberField>
     
        </form>
    </body>
    </html>
    w_docwin.Items.Clear(); //?
    w_docwin.Items.AddRange(attaWindow.Items); //?  here how to add the attaWindow's items to the window w_docwin?
    Also, can you explain how do you want to create this items?
  5. #5
    for (int i = n; i < c; i++)
    {
        attaWindow.Items.RemoveAt(n); //remove the redundant  panel.
    }
    attaWindow is in the seesion last clicked the event. this click , remove the dundant panel. then w_docwin clear all the items. then add the attaWindow's item.
    w_docwin.Items.Clear();
    w_docwin.Items.AddRange(attaWindow.Items);
    dose not work, maybe using javascript.
  6. #6
    about your recommand code.
    is there some bug.
    http://screencast.com/t/3C2LkSOJnTZh
  7. #7
    Regarding the screencast. It looks an ID conflict, i.e. a few controls with the same ID are rendered.

    Please clarify do you need the fields' values persist?
  8. #8
    Quote Originally Posted by Daniil View Post
    Regarding the screencast. It looks an ID conflict, i.e. a few controls with the same ID are rendered.

    Please clarify do you need the fields' values persist?
    yes , the fields persist.

    for example ,select 3,pop window have 3 panels,select 5,pop window have 5 panels, the select 4 , pop window have 4 panels, the four panel is persist,and save as last pop window.

    select 3, pop panels a,b,c
    select 4, pop panels a,b,c,d
    select 2, pop panels a,b
    and so on.
  9. #9
    Yes, I understand it, but I am asking about the fields' values. I.e. the text which a user types in the fields.

    E.g.:

    1. Select 3 => a, b, c
    2. A user types in some field within the b
    3. Select 3 => a, b (the typed text persists)
  10. #10
    Quote Originally Posted by Daniil View Post
    Yes, I understand it, but I am asking about the fields' values. I.e. the text which a user types in the fields.

    E.g.:

    1. Select 3 => a, b, c
    2. A user types in some field within the b
    3. Select 3 => a, b (the typed text persists)
    the typed text persists.

    E.g.:

    1. Select 3 => a, b, c
    2. A user types in some field within the b, the close the pop window.
    3. Select 3 => a, b (the typed text persists),c
Page 1 of 3 123 LastLast

Similar Threads

  1. [CLOSED] asp:datalist inside ext window item.count always zero
    By Tonic in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Jul 15, 2013, 12:49 PM
  2. Replies: 4
    Last Post: Jan 21, 2013, 7:23 AM
  3. Replies: 17
    Last Post: Dec 17, 2012, 11:58 AM
  4. [CLOSED] Always selected Item is nothing for combobox as menu item
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 04, 2011, 4:51 PM
  5. Replies: 1
    Last Post: Jun 01, 2009, 5:15 PM

Posting Permissions