Answered by:
loop through controls in the web form

Question
-
Hi
I have a web page with about 40 checkboxes that i need to loop through t ose if they are checket or not but i can't find out how to do this.
Pleas can somone help me with this
BR
Falken100
- Moved by Youjun Tang Tuesday, March 17, 2015 9:59 AM more related to the suggested forum
Monday, March 16, 2015 9:06 AM
Answers
-
Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReset.Click Dim frm As Control = Me.FindControl("YourFormName") 'is the HTML form Id For Each ctrl As Control In frm.Controls If TypeOf ctrl Is CheckBox Then if DirectCast(ctrl, CheckBox).Checked = true 'do what you want to do here end if End If Next end sub
- Edited by Rbie Monday, March 16, 2015 9:24 AM
- Proposed as answer by Cor Ligthert Monday, March 16, 2015 9:59 AM
- Marked as answer by Just Karl Wednesday, March 25, 2015 4:59 PM
Monday, March 16, 2015 9:23 AM -
Hi Falken100,
As your issue is related to ASP.net, I suggest you posting it to asp.net forum for supports. Thanks for your understanding.
Best regards,
Youjun TangWe are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by Just Karl Wednesday, March 25, 2015 4:59 PM
Tuesday, March 17, 2015 9:59 AM
All replies
-
Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReset.Click Dim frm As Control = Me.FindControl("YourFormName") 'is the HTML form Id For Each ctrl As Control In frm.Controls If TypeOf ctrl Is CheckBox Then if DirectCast(ctrl, CheckBox).Checked = true 'do what you want to do here end if End If Next end sub
- Edited by Rbie Monday, March 16, 2015 9:24 AM
- Proposed as answer by Cor Ligthert Monday, March 16, 2015 9:59 AM
- Marked as answer by Just Karl Wednesday, March 25, 2015 4:59 PM
Monday, March 16, 2015 9:23 AM -
Hi and thanks for the reply
When i try I got this messages.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:Line 25: Dim frm As Control = Me.FindControl("form1") 'is the HTML Form(ID) Line 26: Line 27: For Each ctrl As Control In frm.Controls Line 28: If TypeOf ctrl Is CheckBox Then Line 29: If DirectCast(ctrl, CheckBox).Checked = True Then
does it matter that I have a master page?
The form is in the master page also.
formid="form1"runat="server">
<divclass="ContentPlaceHolder1">
<asp:ContentPlaceHolderid="ContentPlaceHolder1"runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
BR
Falken100
- Edited by Falken100 Monday, March 16, 2015 12:58 PM
Monday, March 16, 2015 10:04 AM -
Hi Falken100,
As your issue is related to ASP.net, I suggest you posting it to asp.net forum for supports. Thanks for your understanding.
Best regards,
Youjun TangWe are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by Just Karl Wednesday, March 25, 2015 4:59 PM
Tuesday, March 17, 2015 9:59 AM