Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 16th, 2004, 02:10 PM
Authorized User
 
Join Date: Feb 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mahulda
Default Using the IDs of dynamically created textboxes

Hi everybody,
My Page consists of a no. of textboxes created dynamicaly using the placeholder control.


  dim i as integer=1

  dim tb1 as textbox=new textbox()
  tb.id="tb"&i
  tb.text="One"
  pl.add(tb1) 'Here pl is the placeholder control

Here I have given the ID of the textbox as tb1 but when I try to use it, like for eg.

        response.write(tb1.text)

I get the error : tb1 not declared.
Please advise me on how to use the ID.
Using the placeholder is mandatory and cannot be changed.
I am using VBScript for my coding
__________________
-.. -..
 
Old February 16th, 2004, 02:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

dim myTxtBox as textbox = myplaceHolder.FindControl("tb1")
response.write(myTxtBox)
dim myTxtBox2 as textbox = myplaceHolder.FindControl("tb2")
response.write(myTxtBox2)

Try that. You must do that for all unless you loop through the placeholder.

 
Old February 16th, 2004, 09:07 PM
Authorized User
 
Join Date: Feb 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mahulda
Default

Will this work ?

dim i as integer
dim myTxtBox as textbox

for i= 1 to 5 'suppose i have 5 textboxes "tb1", "tb2"..."tb5"

myTxtBox = myplaceHolder.FindControl("tb"&i)
response.write(myTxtBox)

next

 
Old February 17th, 2004, 05:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Why don't you try it out?? ;)

Yes, that would work. FindControl expects the name of the control as a string, so combining the fixed "tb" with the number should work.

However, there are a few issues with the current code. First of all, you probably need to cast the control returned by FindControl to a real text box:
Code:
Dim i As Integer
Dim myTxtBox As TextBox 

For i = 1 To 5 'suppose i have 5 textboxes "tb1", "tb2"..."tb5"
  myTxtBox = CType(myplaceHolder.FindControl("tb" & i.ToString()), TextBox)
Next
Second, you can't Response.Write the TextBox to get its text; you'll need to explicitly use its text property:
Code:
Response.Write(myTxtBox.Text)
HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically generated textboxes and their values Frode ASP.NET 2.0 Basics 1 April 17th, 2006 03:46 PM
Dynamically Generating Textboxes Maxood PHP How-To 6 March 9th, 2006 09:14 AM
Dynamically created code Puck312 Pro VB 6 3 September 7th, 2005 01:21 PM
Dynamically displaying textboxes and label lily611 General .NET 1 December 15th, 2004 06:59 PM
Dynamically created controls katsarosj ASP.NET 1.0 and 1.1 Basics 4 February 4th, 2004 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.