Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 September 23rd, 2004, 04:32 PM
Authorized User
 
Join Date: Sep 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default TextBox

Hi,

say i have 20 textboxes on my web form...all named

t1
t2
t3
....
t20

and when the user enters the text in all of them...
i want to do

Response.write(t1.text)
;;;;;
Response.write(t20.text)

instead of that i want to loop thru

for(int i=1;i<=20;i++)
{
Response.write("write textbox values");
}

how do i do that?


 
Old September 23rd, 2004, 04:44 PM
Authorized User
 
Join Date: Jul 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

foreach(Control c in Controls)
{
  if(c is TextBox)
  {
     Response.Write(((TextBox)c).Text);
  }
}

 
Old September 26th, 2004, 04:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Unfortunately, "foreach(Control c in Controls)" will only work if you don't have any other textboxes on your page.

A better approach if you want to do this with a loop would be to put the textboxes in some kind of container, like a placeholder or a panel control so you can isolate the textboxes you really want to deal with. Then you can loop thru that control's "Controls" collection.

Where do you want to write this out to? You should try to avoid using "Response.Write" directly in your code. A better way is to assign the string to a label or literal control that is placed on the page.
 
Old September 27th, 2004, 02:51 PM
Authorized User
 
Join Date: Sep 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

this is what i found can be used in vb.net

 Request("w" & num)

C#...

string str;
               for(int i=1;i<5;i++)
               {
                    str="t"+i.ToString();
                    txt=(TextBox)Page.FindControl(str);
                    Response.Write(txt.Text);

                    str="w"+i.ToString();
                    txt=(TextBox)Page.FindControl(str);
                    Response.Write(txt.Text);
               }

yeah i just used response.write to explain the question...

but what would request(VB.NET) equivalent in C#






Similar Threads
Thread Thread Starter Forum Replies Last Post
TextBox Help iceman90289 C# 2005 6 April 6th, 2008 03:54 AM
pointing cursor from one textbox to other textbox lakshmi_annayappa ASP.NET 1.0 and 1.1 Basics 2 August 2nd, 2007 03:41 PM
help " in textbox mkb C# 2005 1 October 15th, 2006 03:08 PM
Textbox deontae45 VB.NET 2002/2003 Basics 1 September 25th, 2006 11:26 AM
Masked TextBox & formatting TextBox melvik C# 1 September 22nd, 2003 11:01 AM





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