在Panel上动态添加LinkBut​​ton

时间:2011-08-12 07:49:54

标签: extjs panel dynamic-controls ext.net

我在页面上有ext:FileUploadField。文件上传后,我需要显示该文件的链接。 我动态创建一个LinkBut​​ton,将它添加到Panel1上,我看不到LinkBut​​ton!我不知道为什么!

<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 个答案:

答案 0 :(得分:1)

我猜你需要将它添加到面板的按钮列表而不是面板本身。如果您有合适的布局并添加第二个项目,那么您可能还会遇到布局问题。

答案 1 :(得分:0)

尝试使用此代码:

X.Msg.Show( ...... ); 
var linkButton = new LinkButton(); 
linkButton.ID = "fdsfdsfds"; 
linkButton.Text = attachment.Name; 
linkButton.NavigateUrl = "#"; 
linkButton.Render(Panel1, RenderMode.AddTo);

这将直接向Panel1添加链接按钮