473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Placeholder control

Hi there
I can't believe this is so hard to figure out. I've drawn a placeholder control "phCategory" on my form in asp.net. In my load event I do this

Dim txtCategories As New textbo
phCategory.Controls.Add(txtCategories

The form displays my textbox just fine but once the user clicks submit how do I reference the value of the textbox? Is the textbox I created not a server control where I can access its text property? Do I need to use findcontrol? Thanks in advance!
Nov 18 '05 #1
2 3022
Hi, Charlie Dison,

You should create the texbox and add it to the controls collection of the
placeholder on every Page_Load, not only when IsPostBack is false.

After that, if you have EnableViewState set to true to both the page and the
textbox, the value will be loaded in the Text property. Note that this value
is loaded after the Page_Load method because the method that loads the
viewstate values to the runtime-generated controls is after the Page_Load
method in the Page class lifecycle.

Then, if you have a handler for the Click event of the button you should be
able to see the user input loaded in the property Text of the textbox. The
only problem is that you don't have a reference to the textbox, so you will
have to find it in the controls collection of the placeholder, and then you
will have to cast it to TextBox in order to get/set the property Text.

Page_Load:

Dim t1 As New TextBox
phCategory.Controls.Add(t1)

Button1_Click:

Dim l1 As New Label
l1.Text = CType(phCategory.Controls(0), TextBox).Text
phCategory.Controls.Add(l1)

Hope this helps
Martin
"Charlie Dison" <an*******@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com...
Hi there,
I can't believe this is so hard to figure out. I've drawn a placeholder control "phCategory" on my form in asp.net. In my load event I
do this:
Dim txtCategories As New textbox
phCategory.Controls.Add(txtCategories)

The form displays my textbox just fine but once the user clicks

submit how do I reference the value of the textbox? Is the textbox I
created not a server control where I can access its text property? Do I
need to use findcontrol? Thanks in advance!
Nov 18 '05 #2
There are two ways to access the value of your TextBox.

1. Use the Request.Form("TextBoxId") on a postback
2. Recreate the TextBox again, and access the .Text property

Dim txtCategories As New textbox
phCategory.Controls.Add(txtCategories)
txtCategories.Text

Tommy,

"Charlie Dison" <an*******@discussions.microsoft.com> wrote in message news:<F0**********************************@microso ft.com>...
Hi there,
I can't believe this is so hard to figure out. I've drawn a placeholder control "phCategory" on my form in asp.net. In my load event I do this:

Dim txtCategories As New textbox
phCategory.Controls.Add(txtCategories)

The form displays my textbox just fine but once the user clicks submit how do I reference the value of the textbox? Is the textbox I created not a server control where I can access its text property? Do I need to use findcontrol? Thanks in advance!

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: patrick_a | last post by:
Hello, I am trying to insert multiple instances of a custom user control into a placeholder on an aspx page, based on the records retrieved from the database. I use the datareader to loop through...
2
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the...
1
by: Dan | last post by:
I have an asp.net page default.aspx with a user control and a placeholder control. <html> <body> <form id="myform" method="post" runat="server" /> <PageHeader:Header id="header1"...
0
by: shark | last post by:
I have a placeholder in a control that is in turn, used as a control in a placeholder in a form. I am getting a viewstate error so I believe I have to clear my placeholder before I load the...
1
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My...
2
by: Ben de Vette | last post by:
Hi, I like to load a UserControl onto a placeholder with some more control then just doing protected System.Web.UI.WebControls.PlaceHolder placeHolder; UserControl ascx =...
2
by: Don Wash | last post by:
Hi There! I'm creating my website with ASP.NET + XHTML, which means I will strictly adhere the XHTML standards for my web page output. I use Panel or PlaceHolder WebControls to place...
5
by: studio60podcast | last post by:
I have an ASP:Placeholder and I'm trying to populate with Label controls from the code behind after a button click, essentially creating a list of selections. But each time I click the button,...
6
by: David Colliver | last post by:
Hi, using vb.net 1.1 I am trying to add a control to a placeholder but am having problems with it. I do it practically the same way as i do in C# (I have more C# skill than VB.NET)and I...
7
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.