Position of dynamically added controls

C

Chris

I have some code which adds controls to a placeholder. The button and label
however always appears above the dynamically added content when the actual
tags are below. Why is this. I want them to appear below as it really messes
with my plans for assessiblity. What am I doing wrong. Regards.

Dim Form1 As New HtmlForm
Form1 = Page.FindControl("form1")
Dim masterplaceholder As PlaceHolder = New PlaceHolder
masterplaceholder = Page.FindControl("plformgroup")
Form1.Controls.Add(masterplaceholder)
Dim txt As TextBox = New TextBox
masterplaceholder.Controls.Add(txt)


<form id="form1" runat="server">
<div>

<asp:placeHolder ID="plformgroup" runat="server"></asp:placeHolder>
<asp:Label ID="lblstatus" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
 
B

bruce barker

it because you move the place holder to the when you add it to the forms
collection. i can not understand your code. you create a new placholde,
then throw it away. then you lookup the existing placeholder and re-add
it (why?).

-- bruce (sqlwork.com)
 
C

Chris

Ah the code exists in a classoutside the page. Should I just be finding the
placeholder then adding to it?
 
C

Chris

Yes I have realised that. Now i am not adding to the form I am just finding
it. This works but now I am trying to group the control in a panel so I can
apply a css class to act as a border but now I get a band across the top of
the page rather than a border around all the controls. Any ideas why.
Regards, Chris.

Dim tmpControl As Control = page.FindControl(placeholderid)

Dim masterplaceholder As PlaceHolder = CType(tmpControl, PlaceHolder)

<asp:panel ID="Panel1" runat="server" >



<asp:Label ID="lblstatus" runat="server"></asp:Label>

<asp:placeHolder ID="plformgroup" runat="server">

</asp:placeHolder>

<asp:Button ID="Button1" runat="server" Text="Button" />


</asp:panel>
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top