---
title: "Can I loop through textbox id’s to check values in asp.net"  
description: "Can I loop through textbox id’s to check values in asp.net"  
author: "Pravesh Singh"  
published: 2014-11-14  
updated: 2014-11-14  
canonical: https://www.mindstick.com/forum/12582/can-i-loop-through-textbox-id-s-to-check-values-in-asp-dot-net  
category: "asp.net"  
tags: ["c#", "loop"]  
reading_time: 1 minute  

---

# Can I loop through textbox id’s to check values in asp.net

I'm working on a [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) and I'm a [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) and I'm having a little trouble with this. I'm trying to [check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) a [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) is empty and if it is to change the value to N/A so that I can input n/a into a [database instead](https://www.mindstick.com/forum/159659/when-use-a-nosql-database-instead-of-a-relational-database-is-it-okay-to-use-both-on-the-same-site) of it not working.

Here is the code that I thought would work but didn't because the .Text [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) isn't near the ID anymore:

```
for(int i = 1; i<=17; i++){if(!("tb" + i).Text)"tb" + i.Text = "n/a";}
```

I wasn't sure if the true/false would work but I never got to find out because it doesn't [compile](https://www.mindstick.com/forum/2316/how-to-views-compile-in-mvc) to begin with. I have 17 textboxes on my [design](https://www.mindstick.com/articles/12279/interior-design-and-furniture-store-wordpress-theme) page all with ID 'tb + i' [e.g](https://www.mindstick.com/forum/157370/how-to-swap-neighbor-characters-in-string-e-g-string-demo-would-be-edom) tb1, tb2

## Replies

### Reply by Samuel Fernandes

If you want to loop through the textbox ids, you have to find the control on the page first using the FindControl method.

**Then you can create your loop like this:**

```
TextBox txt;for(int i = 1; i<=17; i++){    txt = (TextBox)Page.FindControl("tb" + i);    if(string.IsNullOrEmpty(txt.Text))        txt.Text = "n/a";}
```


---

Original Source: https://www.mindstick.com/forum/12582/can-i-loop-through-textbox-id-s-to-check-values-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
