Reputation: 703
I have a table which is dynamically created based on the amount of results returned. In each row there is a cell (created from c# code) with a textbox like
"<input id='textbox" + i + "'type='text'/
>"
so textbox0, 1, 2, etc.
My question is, how to obtain each textbox's value in the c# code, after a user inputs something?
i.e you can't just go textbox1.Text to get the value since the code behind page has no idea what textbox1 is.
Upvotes: 0
Views: 892
Reputation: 3224
You can use javascript code.
<script language="javascript">
var txt = document.getElementsByTagName('input');
for(var i = 0; i < txt.length; i++)
{
// do what you want ...
}
</script>
Upvotes: 0
Reputation: 48088
First of all, you should specify a unique name for your inputs :
"<input id='textbox" + i + "' name='textbox" + i + "' type='text'/>"
then at server side you can get each textbox's value by this name :
string textbox1Value = Request.Form["textbox1"];
Upvotes: 2