ASP.Net HTML form postback question
-
I have an ASP.Net form that has some HTML checkboxes which are dynamically added to the form. I use the ID to identify them but they are generated from data so are different every time. How can I see these checkboxes when I post back? I've tried Request.Form.Controls.Count and see that there are several HTML controls, but I'd like to be able to see the HTML ID and value of these controls. Ideally it would be by using a foreach loop. I can identify them by their ID as the ID starts with the string 'chk'. Am I missing something here? Thanks in advance - Dave
-
I have an ASP.Net form that has some HTML checkboxes which are dynamically added to the form. I use the ID to identify them but they are generated from data so are different every time. How can I see these checkboxes when I post back? I've tried Request.Form.Controls.Count and see that there are several HTML controls, but I'd like to be able to see the HTML ID and value of these controls. Ideally it would be by using a foreach loop. I can identify them by their ID as the ID starts with the string 'chk'. Am I missing something here? Thanks in advance - Dave
Off the top of my head Dave, I'm sure you can do the following...
Request.Form.Item("chk???")
Where ??? is your ID. That will give you access to the value of those controls on postback. HTH Chris. -
Off the top of my head Dave, I'm sure you can do the following...
Request.Form.Item("chk???")
Where ??? is your ID. That will give you access to the value of those controls on postback. HTH Chris.The problem is that I don't know what the number will be. I need to iterate through all controls that have been posted back and if their id starts with 'chk' then that is the data that I want to process.
-
The problem is that I don't know what the number will be. I need to iterate through all controls that have been posted back and if their id starts with 'chk' then that is the data that I want to process.
Ok, then perhaps something like...
For Each tmpItem As Item In Request.Forms.Item If tmpItem.toString.IndexOf("chk") > 0 Then 'do something EndIf Next
Might be what you are looking for? I hope I'm on the right track here. /chris -
Ok, then perhaps something like...
For Each tmpItem As Item In Request.Forms.Item If tmpItem.toString.IndexOf("chk") > 0 Then 'do something EndIf Next
Might be what you are looking for? I hope I'm on the right track here. /chrisChris Unfortunately there is no member under Request called Forms. I do have a member called Form but it doesn't have an Items collection. (Not in C# anyway). I do seem to have cracked it though. Here is what I found...
int intItemId; // Loop for each key in the request form foreach (string strKey in Request.Form.Keys) { // Is this a checkbox key? if (strKey.IndexOf("chk") > -1) // Yes { // Get the id of the checked data item intItemId = Convert.ToInt32( strKey.Substring(strKey.IndexOf("chk") + 3) ); // The user has selected item intItemId. Process that here... } }// end foreach key
-
Chris Unfortunately there is no member under Request called Forms. I do have a member called Form but it doesn't have an Items collection. (Not in C# anyway). I do seem to have cracked it though. Here is what I found...
int intItemId; // Loop for each key in the request form foreach (string strKey in Request.Form.Keys) { // Is this a checkbox key? if (strKey.IndexOf("chk") > -1) // Yes { // Get the id of the checked data item intItemId = Convert.ToInt32( strKey.Substring(strKey.IndexOf("chk") + 3) ); // The user has selected item intItemId. Process that here... } }// end foreach key
Ahh, C#, I'm not familiar with the differences between C# and VB.NET Glad you solved the problem :)