Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 16th, 2004, 02:10 PM
Authorized User
 
Join Date: Feb 2004
Location: Delhi, Delhi, India.
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
__________________
-.. -..
  #2 (permalink)  
Old February 16th, 2004, 02:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,111
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.

  #3 (permalink)  
Old February 16th, 2004, 09:07 PM
Authorized User
 
Join Date: Feb 2004
Location: Delhi, Delhi, India.
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

  #4 (permalink)  
Old February 17th, 2004, 05:05 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:21 PM.


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