Solved

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

Posted on 2004-08-11
12
512 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why is some text in blue in Visual Studio? 6 33
How to prevent website from publishing with errors 9 48
Code works but it's slow 28 70
List<PaisEntity> - show some 1 24
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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

777 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