Solved

How do I make dynamically added controls visible inside a panel control?

Posted on 2004-08-11
12
509 Views
Last Modified: 2008-03-17
Hello again!

I am trying to add controls dynamically, link buttons and images.  The link buttons require a container of some sort since they must appear between the form tags.  Well the controls appear to be added just fine, but they are not visible.  The panels visible property is set to True.

How do I make the dynamically added controls visible?  The code is below.


<FORM>
<asp:Panel id="Panel1" style="Z-INDEX: 118; LEFT: 8px; POSITION: absolute; TOP: 552px" runat="server"
                        Height="144px" Width="520px" BackColor="Transparent"></asp:Panel>

</FORM>

                    cImageCon.Height = System.Web.UI.WebControls.Unit.Pixel(86)
                    cImageCon.Width = System.Web.UI.WebControls.Unit.Pixel(119)
                    cImageCon.Style("LEFT") = System.Web.UI.WebControls.Unit.Pixel(8).ToString
                    cImageCon.Style("POSITION") = "absolute"
                    cImageCon.Style("TOP") = System.Web.UI.WebControls.Unit.Pixel(lTop).ToString
                    cImageCon.Visible = True
                    cImageCon.ImageUrl = ibAdPic.ImageUrl
                    cLink.Height = System.Web.UI.WebControls.Unit.Pixel(25)
                    cLink.Width = System.Web.UI.WebControls.Unit.Pixel(56)

                    cLink.Style("Font-Bold") = "True"
                    cLink.Style("Font-Size") = "X-Small"
                    cLink.Style("Font-Names") = "Arial"
                    cLink.Style("runat") = "server"
                    cLink.Style("LEFT") = System.Web.UI.WebControls.Unit.Pixel(8).ToString
                    Dim LabelTop As Long = lTop
                    LabelTop = LabelTop + 100
                    cLink.Style("TOP") = System.Web.UI.WebControls.Unit.Pixel(LabelTop).ToString
                    cLink.Visible = True
0
Comment
Question by:bczingo
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 7

Expert Comment

by:mdamico
Comment Utility
I don't see anywhere where you are adding the controls to the panel/

Panel1.Controls.Add(cImageCon)
Panel1.Controls.Add(cLink)
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
how bout using find control to access the properties:

Dim myForm As Control = Page.FindControl("FormFrame1")
            myForm.myTextBox.Visible = True

Regards,

Aeros
0
 
LVL 3

Author Comment

by:bczingo
Comment Utility
Sorry.  Copy Paste error!

Panel1.Controls.Add(cLink)
Panel1.Controls.Add(cImageCon)
0
 
LVL 9

Expert Comment

by:Rodney Helsens
Comment Utility
When you say the controls appear to be added just fine, I assume you have "viewed source" on the html and seen the controls there?

Try adding a simple control to the panel, does this show up? If so, there is a problem with the controls, where are you setting the text property of the link?

            Dim t As New TextBox()
            t.Text = "myTextBox"
            t.ID = "myTextBox"
            Panel1.Controls.Add(t)
0
 
LVL 3

Author Comment

by:bczingo
Comment Utility
aerosaga,

I tried the find control method and it didn't reveal the control.
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
then I suspect rodnex is correct in assuming that the controls are not being created correctly.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Author Comment

by:bczingo
Comment Utility
Rodnex,

Yes They are there when I view source

<div id="Panel1" style="background-color:Transparent;height:144px;width:520px;Z-INDEX: 118; LEFT: 8px; POSITION: absolute; TOP: 552px">
      <img id="imgAdPhoto5" src="C:\Documents and Settings\Administrator\My Documents\My Pictures\Parts\0117.jpg" border="0" style="height:86px;width:119px;LEFT:8px;POSITION:absolute;TOP:596px;" />
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
ok, so what happened when you attempted to find the controls?
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Heres a couple of alternate ways to try the same thing.

Dim x1 As myCustomControl = DirectCast(Me.FindControl("ReportMenu1"), myCustomControl)
                myPageLabel.text = x.MyCustomControl.Label.Text

Public ReadOnly Property GetMyLabelText() As String
 Get
   If Not Label1 Is Nothing Then Return Label1.TexT
 End Get
End Property


OR

Private _myParameter as String
Public Property myParameter() as String
  Get
    Return _myParameter
  End Get
  Set
    _myParameter = value
  End Set
End Property

Then in you aspx page:

Dim x1 As myCustomControl = DirectCast(Me.FindControl("ReportMenu1"), myCustomControl)
x1.myParameter = "XXXX"

0
 
LVL 9

Expert Comment

by:Rodney Helsens
Comment Utility
put a border = 1 on that image, you will probably see that the image is being rendered, but you are referencing an absolute URL to the image..
0
 
LVL 9

Accepted Solution

by:
Rodney Helsens earned 500 total points
Comment Utility
ya know, after looking at that generated html code, there is a good chance that your problem is that the div may be hidden behind other divs, since you are setting its position to absolute, it shows up far left, towards the bottom of the screen with a zindex of 118.. take a long look at this..

0
 
LVL 1

Expert Comment

by:steve_mick972
Comment Utility
interestingly when I ran ur code and first I could not see any controls and when accidentally scrolled through the page I saw that image and link button bottom of the page on the left hand side...
and I think rodnex might be right...  either u miss them seeing coz ur setting them as absolute r ur div tag might be causing the problem...

Steve
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now