Solved

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

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 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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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