Results 1 to 8 of 8

Thread: Dynamically add LinkButton on Panel

  1. #1
    Member AlexMaslakov's Avatar
    Join Date
    Aug 2011
    Location
    Russia
    Posts
    106

    Dynamically add LinkButton on Panel

    I have ext:FileUploadField on the page. After file upload I need to show a link to this file. I dynamically create a LinkButton, add it on the Panel1, and I can't see the the LinkButton! I dunno why!

    Code:
    <ext:Panel ID="Panel1" runat="server">
        <Content>
            <ext:FileUploadField ID="FileUploadField1" runat="server" EmptyText="Choose a file" FieldLabel="File" Icon="ImageAdd" />
        </Content>
        <Buttons>
            <ext:Button ID="SaveButton2" runat="server" Text="Upload">
                <DirectEvents>
                    <Click OnEvent="UploadClick"></Click>
                </DirectEvents>
            </ext:Button>
        </Buttons>
    </ext:Panel>
    
    
    protected void UploadClick(object sender, DirectEventArgs e)
            {
                if (this.FileUploadField1.HasFile)
                {
                    var attachment = new Attachment { ............ };
                    if (UploadAttachment(attachment))
                    {
                        X.Msg.Show( ...... );
    
                        var linkButton = new LinkButton();
                        linkButton.ID = "fdsfdsfds";
                        linkButton.Text = attachment.Name;
                        linkButton.NavigateUrl = "#";
                        linkButton.Render();
                        Panel1.Add(linkButton);
                        // Panel1.Render(true);
                         Panel1.DoLayout(true,true);
                    }
                    else
                    {
                       //................
                    }
    
                }
                else
                {
                    //................
                }
            }

  2. #2
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,206
    Please replace
    Code:
    linkButton.Render();
    Panel1.Add(linkButton);
    
    // Panel1.Render(true);
    Panel1.DoLayout(true,true);
    with
    Code:
    linkButton.AddTo(Panel1);
    Last edited by Daniil; Aug 12, 2011 at 2:58 PM.
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  3. #3
    Member AlexMaslakov's Avatar
    Join Date
    Aug 2011
    Location
    Russia
    Posts
    106
    It's still doesn't work.

  4. #4
    Member AlexMaslakov's Avatar
    Join Date
    Aug 2011
    Location
    Russia
    Posts
    106
    Daniil, the approach below works!


    Code:
    linkButton.AddTo(Panel1,true);

  5. #5
    Member AlexMaslakov's Avatar
    Join Date
    Aug 2011
    Location
    Russia
    Posts
    106
    It's strange, but the first approach works, but the second doesn't!

    Code:
    <ext:Panel ID="Panel1" runat="server"> 
        <Content> 
            <ext:FileUploadField ID="FileUploadField1" runat="server" EmptyText="Choose a file" FieldLabel="File" Icon="ImageAdd" /> 
        </Content> 
        <Buttons> 
            <ext:Button ID="SaveButton2" runat="server" Text="Upload"> 
                <DirectEvents> 
                    <Click OnEvent="UploadClick"></Click> 
                </DirectEvents> 
            </ext:Button> 
        </Buttons> 
    </ext:Panel> 
      
      
    protected void UploadClick(object sender, DirectEventArgs e) 
            { 
                if (this.FileUploadField1.HasFile) 
                { 
                    var attachment = new Attachment { ............ }; 
                    if (UploadAttachment(attachment)) 
                    { 
                        X.Msg.Show( ...... ); 
      
                      //doesn't work!!!!!! (javascript error "Unexpected token ILLEGAL"). Why?
                       ShowUploadedFiles();
    
                        
    
    
    
                       //works good!!!!!!!!!!!!!
    
                        //var linkButton = new LinkButton();
                        //linkButton.ID = "fdsfdsfds";
                        //linkButton.Text = FileUploadField1.PostedFile.FileName;
                        //linkButton.NavigateUrl = "#";
                        //linkButton.AddTo(Panel1,true);
    
    
                        //var linkButton2 = new LinkButton();
                        //linkButton2.ID = "fdsfdsfds2";
                        //linkButton2.Text = FileUploadField1.PostedFile.FileName+" --- 2";
                        //linkButton2.NavigateUrl = "#";
                        //linkButton2.AddTo(Panel1, true);
                    } 
                    else 
                    { 
                       //................ 
                    } 
      
                } 
                else 
                { 
                    //................ 
                } 
            }
    
     protected void ShowUploadedFiles()
            {
                var attachments = GetAttachments(AttachmentId);
                foreach (var a in attachments)
                {
                    var linkButton = new LinkButton();
                    linkButton.ID = a.FileName + "____";
                    linkButton.Text = a.FileName;
                    linkButton.NavigateUrl = "#";
                    linkButton.AddTo(Panel1, true);
                }
            }

  6. #6
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,206
    How does these ids look?
    Code:
    linkButton.ID = a.FileName + "____";
    I guess it does not suite requirements on ids, see:
    http://www.w3schools.com/tags/att_standard_id.asp

    Naming rules:


    • Must begin with a letter A-Z or a-z
    • Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
    • Values are case-sensitive
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  7. #7
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,206
    Quote Originally Posted by AlexMaslakov View Post
    Daniil, the approach below works!

    Code:
    linkButton.AddTo(Panel1,true);
    Can you confirm does this code works?
    Code:
    linkButton.AddTo(Panel1);
    instead of
    Code:
    linkButton.AddTo(Panel1,true);
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  8. #8
    Member AlexMaslakov's Avatar
    Join Date
    Aug 2011
    Location
    Russia
    Posts
    106
    Quote Originally Posted by Daniil View Post
    How does these ids look?
    Code:
    linkButton.ID = a.FileName + "____";
    I guess it does not suite requirements on ids, see:
    http://www.w3schools.com/tags/att_standard_id.asp
    Yes, the problem was in the name of the ID.

Similar Threads

  1. Replies: 0
    Last Post: Mar 27, 2012, 10:01 AM
  2. Add Menu Panel Dynamically in Panel
    By archana in forum 1.x Help
    Replies: 4
    Last Post: Oct 27, 2011, 10:38 AM
  3. Add Menu Panel Dynamically in Panel
    By archana in forum 1.x Help
    Replies: 2
    Last Post: Oct 14, 2011, 9:53 AM
  4. How to dynamically add label to panel?
    By omeriko9 in forum 1.x Help
    Replies: 3
    Last Post: Sep 07, 2009, 1:01 PM
  5. Dynamically build Form Panel
    By glenh in forum 1.x Help
    Replies: 5
    Last Post: Aug 10, 2009, 4:07 AM

Tags for this Thread

Posting Permissions