Please!!! Need help with WebUI.Panel

J

Jim H

Let me start by saying that this whole project is a C# project and I don't
know ASP. I am posting to this group because of a suggestion by someone in
a response in the C# group.

I have a web application which has a WebUI.PlaceHolder on it. I have a
single custom Output rendering control that has a bunch of WebUI.Table
controls (the number is determined at run time) that I add using
Controls.Add during CreateChildControls of the renderer. Everything works
fine with that. Now I want to Add groups of tables into panels and add the
panels to the renderer control.
What I do is this:

I loop through my data. In the loop I create a Panel dynamically by
creating an instance of a new Panel().
I add all my controls to the Panel by calling
lPanel.Controls.Add(myControl).
Then I add the Panel control to my renderer by calling Controls.Add(lPanel)
just like I used to with the tables.

The problem is that all of the panels are opening up inside of eachother. I
need then one under the other.

code chunk:

int i = 0;
foreach(DataRow lRow in m_tOIResults.Rows)
{
lPanel = new Panel();
lPanel.ID = string.Format("Rpt{0}", i); //each panel get a different
name
i++;

//put a border on so I can see where each panel starts and ends
lPanel.BorderStyle = BorderStyle.Inset;

//alternate panel background colors to make it easier to see what's
going on
if(((float)i / 2.0) != (i / 2))
lPanel.BackColor = System.Drawing.Color.Aqua;
else
lPanel.BackColor = System.Drawing.Color.DarkGreen;

//create some loaded tables
lPanel.Controls.Add(MyTable1);
//more of the same here.
this.Controls.Add(lPanel);
}

When I set borders on the panels I can see that each panel is opening up
inside the panel before it right after the tables.

I even add a LiteralControl in the loop - this.Controls.Add(new
LiteralControl("Jim was here"));
That text apears in eachof the last panels.
Any ideas as to why and what I can do to stop this? What am I doing wrong?

jim

PS VS .NET 2003 Enterprise Architect
 
J

Jacob Yang [MSFT]

Hi Jim,

According to your description, I also did a test on my side (I apologize
that I tested it in VB.NET. However, it is nothing to do with language). In
my test, those panels arranged from top to bottom correctly. Here are my
test steps.

1. Create a new web application and then add a web custom control into this
application.
2. Override the CreateChildControls method inside the custom control and
copy the following code into this method:

' Adds literal control to current ControlCollection
Me.Controls.Add(New LiteralControl("<h3>Value: "))

Dim count As Integer
Dim lPanel As Panel
Dim Box As TextBox

count = 0

For count = 1 To 5
Me.Controls.Add(New LiteralControl("Jim was here"))

lPanel = New Panel
lPanel.ID = String.Format("Rpt{0}", count)

'put a border on so I can see where each panel starts and ends
lPanel.BorderStyle = BorderStyle.Inset

Box = New TextBox
Box.Text = "0"

lPanel.Controls.Add(Box)

Me.Controls.Add(lPanel)
Next

Me.Controls.Add(New LiteralControl("</h3>"))

3. In this custom control, there is nothing but the implementation of the
CreateChildControls.
4. Compile this web application.
5. Create another web application as the consumer of the custom control
above. By default the webform1.aspx should be created.
6. Switch to the design mode of webform1.aspx and right click any space on
the toolbox and select Add/Remove Items
7. Browse to the assembly of the custom control above
8. Drag the custom control onto the webform1.aspx
9. Compile and run the latter web application to check the result.

You will see all the panels should arrange as expected.

Please test it and let me know the results.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jim H

You did exactly what I did with one difference. You actually dragged the
custom control onto the web form where I had a placeholder control and did a
MyPlaceHolder.Controls.Add(MyCustomRenderer). I changed my code to do the
same way you did but it did not change my results. I still have panels
opening inside of panels.

When I take out all of the table controls and just use the text box control
like you did then it works fine. All panels open next to eachother not
inside one another.

Any ideas?

Could my tables be generating HTML that causes the panels to open inside one
another?

jim
 
J

Jim H

Each of my custom table objects was missing a RenderEndTag() causing bad
HTML.
Thanks for the test code, you sent me down the right path.
Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top