Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 123
Open form in the top right hand corner of screen 5 20
Spacing between controls 4 17
Birthdays 3 21
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now