Solved

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

Posted on 2004-08-11
12
513 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

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…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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