Advertisement

03.20.2008 at 07:20AM PDT, ID: 23256958
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Append Dynamic Controls to Placeholder

Tags: ASP.Net 2.0, I.E.
Hi,

I'm having problems appending controls to a placeholder control... here's the jist of it:
It's basically like a CMS... this is a module i'm trying to develop where admin users can compose their page's content using a UI... so i've got the basic template/sections that can't be removed, but i also have buttons at the bottom to add sections to their page. Here's the problem... it works, the only problem is that it doesn't seem to append, but only replaces the last inserted control to the placeholder with the new one.

in this section, i'm trying to add a "Header" section for the user, see code below... here's what happens:

section gets added as "header0"... then if i click again, instead of preserving Header0, it removes Header0, and adds Header1... i would like to append, not overwrite.

thanks for any help available! max points to anyone who can help.

MaxOvrdrv2
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
AdminAdd.aspx
 
<asp:PlaceHolder ID="plcPage" runat="server" Visible=false>
            <!-- template section here! -->
            <div class="rowheader">
                <asp:Label ID="lblContentTitle" runat="Server" Text="Page Composition"></asp:Label>
            </div>
            <br /><br />
            <div class="rowodd">
                <div class="leftodd"><asp:Label ID="lbltitle" runat="server" Text="Post Main Header:"></asp:Label></div>
                <div class="rightodd"><asp:TextBox ID="txttitle" runat="Server" Width="95%"></asp:TextBox></div>
            </div>
            <br /><br />
            <div class="roweven">
                <div class="lefteven"><asp:Label ID="lblpagetext0" runat="server" Text="Post Intro Text<br>(If any)"></asp:Label></div>
                <div class="righteven"><asp:TextBox ID="txtpagetext0" runat="server" TextMode="multiline" Width="95%" Rows=5></asp:TextBox></div>
            </div>                       
        </asp:PlaceHolder>
        <br /><br />
        <asp:PlaceHolder ID="plcPageBtns" runat="server" Visible=false>
            <div class="rowheader">
                <asp:Label ID="lblbtnstitle" runat="server" Text="Add a section:"></asp:Label><br />
                <!-- insert buttons here! -->
                <asp:Button ID="btnHeader" runat="server" Text="Header" />&nbsp;<asp:button ID="btnSubHeader" runat="server" Text="Sub Header" />&nbsp;<asp:Button ID="btnText" runat="server" Text="Page Text" />
            </div>
        </asp:PlaceHolder>
 
AdminAdd.vb (Header click function)
Private Sub btnHeader_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnHeader.Click
        'adds a header section to the page composition placeholder
        Dim divrow As New HtmlGenericControl
        Dim divleft As New HtmlGenericControl
        Dim divright As New HtmlGenericControl
        Dim lblHeader As New Label
        Dim txtHeader As New TextBox
        Dim lblSpacer As New Label
 
 
        Dim evenodd = CInt(Me.txtHeaderNum.Text) Mod 2
 
        If evenodd = 0 Then
            divrow.Attributes.Add("class", "roweven")
            divleft.Attributes.Add("class", "lefteven")
            divright.Attributes.Add("class", "righteven")
        Else
            divrow.Attributes.Add("class", "rowodd")
            divleft.Attributes.Add("class", "leftodd")
            divright.Attributes.Add("class", "rightodd")
        End If
 
        divrow.ID = "divrowHeader" & Me.txtHeaderNum.Text
        divleft.ID = "divleftHeader" & Me.txtHeaderNum.Text
        divright.ID = "divrightHeader" & Me.txtHeaderNum.Text
 
        lblHeader.ID = "lblHeader" & Me.txtHeaderNum.Text
        lblHeader.Text = "Header " & Me.txtHeaderNum.Text
        txtHeader.ID = "txtHeader" & Me.txtHeaderNum.Text
        txtHeader.Width = System.Web.UI.WebControls.Unit.Percentage(95)
        lblSpacer.ID = "lblSpacer" & Me.txtHeaderNum.Text
        lblSpacer.Text = "<br /><br />"
 
        divleft.Controls.Add(lblHeader)
        divright.Controls.Add(txtHeader)
        divrow.Controls.Add(divleft)
        divrow.Controls.Add(divright)
        Me.plcPage.Controls.Add(lblSpacer)
        Me.plcPage.Controls.Add(divrow)
        Me.txtHeaderNum.Text = CInt(Me.txtHeaderNum.Text) + 1
 
        divrow = Nothing
        divleft = Nothing
        divright = Nothing
        lblHeader = Nothing
        txtHeader = Nothing
        lblSpacer = Nothing
 
 
 
    End Sub
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: MaxOvrdrv2
Solution Provided By: MaxOvrdrv2
Participating Experts: 1
Solution Grade: A
Views: 19
Translate:
Loading Advertisement...
03.20.2008 at 07:51AM PDT, ID: 21172087

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.20.2008 at 08:11AM PDT, ID: 21172299

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.20.2008 at 08:17AM PDT, ID: 21172363

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.20.2008 at 08:33AM PDT, ID: 21172563

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.20.2008 at 11:16AM PDT, ID: 21174096

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.20.2008 at 01:38PM PDT, ID: 21175641

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.20.2008 at 07:51AM PDT, ID: 21172087
try using a panel instead of a placeholder.
SnowFlake
 
03.20.2008 at 08:11AM PDT, ID: 21172299
nope... still only replaces, doesn't append to the control... maybe it's something in the back-end that's doing it?
here's what it looks like
first click:
<STATIC SECTION>
| Header 0 | <TEXTBOX> |

second click
<STATIC SECTION>
| Header 1 | <TEXTBOX> |

Header 0 disappeared... i want it to stay there...
 
03.20.2008 at 08:17AM PDT, ID: 21172363
are you using postbacks ?
It is possible that that controls does not have any controls in it when you are trying to add to it and your problem is one of persistance and not one of overwrite instead of append ?
If I remember correctly - dynamically added controls are problematic in this sense.
 
03.20.2008 at 08:33AM PDT, ID: 21172563
might be... those controls are definitely not in the page on first load... but after postback (click on button), then it is added... is there not something i should in the page directive or something to prevent the placeholder/panel from clearing itself every time there is a postback?
 
03.20.2008 at 11:16AM PDT, ID: 21174096
what's weird is that i have something very similar in .Net 1.1. and it works perfectly fine... code is exactly the same... the only difference is that on PageLoad the placeholder doesn't have any controls within it to begin with... now why would it keep state in 1.1. and not in 2.0???

this is ridiculous, i'm not gonna re-render every control in that placeholder on EVERY post-back... i know it can be done, i have it in 1.1....

in 1.1.:

textbox numofdependants button add
addclick= call addcontrol(placeholderID)

addcontrol(placeholderID)
declare controls to add
set their attributes
add eventhandlers if needed
add controls to placeholder...

and that's it... i can do as many postbacks as i want and the data remains in the controls and they don't have to be "re-added" to the placeholder... why can't i do that in 2.0???
 
03.20.2008 at 01:38PM PDT, ID: 21175641
actually... this is the answer for anyone who wants to know:

and independent function must be called from the PageLoad() function instead, because before the page load is called, the placeholder gets cleared of all it,s controls. However, if you name/rename all your dynamic controls with the same name, they will retain viewstate... therefore, something like this will do it:

pageload
     loadcontrols
end pageload

loadcontrols
    for i to textnum.text
        add your controls
    next
end loadcontrols


mine ended up being a little bit more complicated than that because i also had different controls place in different places based on the user input... but you get the gist of it... here's kinda what i ended up with

.aspx
buttons add header, add subheader, add page text, add link

hidden text HeadersNum
hidden text SubHeadersNum
hidden text PageTextsNum
hidden text LinksNum
hidden text PageOrder

PlaceHolder

.vb

pageload
    loadcontrols
end pageload

loadcontrols
     load all controls as per page order
end loadcontrols

anybutton.click event
    add a new control to the placeholder with unique iterative ID (currentnum+1)
    assign new top num to proper text box
    add control type to order textbox
end anybutton.click event
Accepted Solution
 
 
20080716-EE-VQP-33 / EE_QW_2_20070628