Solved

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

Posted on 2004-04-02
3
1,172 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 250 total points
ID: 10746275
You need to recreate the controls on PostBack. That's all.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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