Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Placeholder controls are lost in the postback... How to retrieve data from the controls?

Posted on 2004-04-02
3
Medium Priority
?
1,195 Views
Last Modified: 2011-10-03
Greetings.

I am new to this placeholder control and need some help. I have a form that generates several rows for input based on the number of items purchased. In the end what I would like to do is to read the data from these controls and post it into the database.

I am not able to maintain the controls I initialy inserted in the placeholder after postback... I am posting a simple page code which demonstrates what I want to do. Any help is greatly appreciated.

'This is the aspx page which has my placeholder
<HTML>
      <HEAD>
            <title>WebForm2</title>
      </HEAD>
      <body>
            <form id="Form1" method="post" runat="server">
                  <P>Number of Items Purchased:
                        <asp:textbox id="txtItems" Runat="server" Width="33px"></asp:textbox>&nbsp;
                  </P>
                  <P><asp:placeholder id="plcOrder" Runat="server"></asp:placeholder></P>
                  <P>
                        <asp:Label id="lblMyOrder" runat="server"></asp:Label></P>
                  <asp:button id="btnContinue" runat="server" Text="Continue..."></asp:button>
            </form>
      </body>
</HTML>

This is the code behind...


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Sub makeTable(ByVal iRows As Integer)

        Me.plcOrder.Controls.Add(New LiteralControl("<TABLE border=1 cellpadding=1 cellspacing=2>"))
        Dim i As Integer
        For i = 0 To iRows - 1
            Dim t3 As TextBox = New TextBox
            t3.ID = "txtPrice" & i
            t3.Style("width") = "50px"
            Dim t4 As TextBox = New TextBox
            t4.ID = "txtQuantity" & i
            t4.Style("width") = "50px"
            Me.plcOrder.Controls.Add(New LiteralControl("<TR>"))
            Me.plcOrder.Controls.Add(New LiteralControl("</TD>"))
            Me.plcOrder.Controls.Add(New LiteralControl("<TD>Price: "))
            Me.plcOrder.Controls.Add(t3)
            Me.plcOrder.Controls.Add(New LiteralControl("</TD>"))
            Me.plcOrder.Controls.Add(New LiteralControl("<TD>Quantity: "))
            Me.plcOrder.Controls.Add(t4)
            Me.plcOrder.Controls.Add(New LiteralControl("</TD>"))
            Me.plcOrder.Controls.Add(New LiteralControl("</TR>"))
        Next
        Me.plcOrder.Controls.Add(New LiteralControl("</table>"))
    End Sub

    Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
        If Me.btnContinue.Text = "Continue..." Then
            makeTable(Me.txtItems.Text)
            Me.btnContinue.Text = "Submit Order"
        Else
            'Here is where I would like to read the values from the controls in the placeholder
            'when the form submitted and write it to the label... I am losing all my controls in
            'the placeholder. Any help is appreciated.
        End If
    End Sub

Again any suggestion or help is greatly appreciated.
0
Comment
Question by:amendi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
KarunSK earned 1000 total points
ID: 10746275
You need to recreate the controls on PostBack. That's all.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 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