Solved

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

Posted on 2004-04-02
3
1,180 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

687 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