Solved

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

Posted on 2004-08-11
12
510 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
ID: 11773721
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
ID: 11773741
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
ID: 11773907
Sorry.  Copy Paste error!

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

Expert Comment

by:Rodney Helsens
ID: 11774159
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
ID: 11774246
aerosaga,

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

Expert Comment

by:AerosSaga
ID: 11774334
then I suspect rodnex is correct in assuming that the controls are not being created correctly.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:bczingo
ID: 11774335
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
ID: 11774358
ok, so what happened when you attempted to find the controls?
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11774370
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
ID: 11774463
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
ID: 11774555
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
ID: 11774900
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

12 Experts available now in Live!

Get 1:1 Help Now