473,385 Members | 1,311 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,385 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 3025
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
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.