Questions regarding control nesting and form check

Results 1 to 2 of 2

Thread: Questions regarding control nesting and form check

  1. #1
    Join Date
    Dec 1969

    Default Questions regarding control nesting and form check

    Here&#039;s the scenario. I have a user control in a user control in a web form. The lowest user control creates HTMLCheckboxes in a dynamically created table (using the table, row and cell objects). The request.form keys that are returned contain concatenated strings which I assume to be a part of how ASP.NET handles variable scope.<BR><BR>In my generated form, if I were check the first and second checkboxes the returned keys look something like this:<BR><BR>"ucUserControl1:ucUserControlTraining 1:fccbTraining1"<BR>"ucUserControl1:ucUserControlT raining1:fccbTraining2"<BR><BR>I could write string parsing code to figure out which checkboxes were checked but is there a better way of referencing returned HTML form variables deep within user controls? Is there a readonly property somewhere that can generate the strings for object context? Is there an interface to these variables that is cleaner and can be referenced from within the user control without having to parse out the posted forms values like the ones listed above manually?<BR><BR>Regards,<BR>Tony

  2. #2
    Join Date
    Dec 1969

    Default RE: Questions regarding control nesting and form c

    If there are different naming containers, you need to use the FindControl method. It takes a string that is the ID of the control you are looking for and returns that control. I use it mostly with datagrids/datalists/repeaters:<BR><BR>protected void myDataGrid_ItemCommand(object sender, DataGridCommandEventArgs e)<BR>{<BR> CheckBox myChk = (CheckBox)e.Item.FindControl("myChk");<BR>}<BR><BR >The second thing you might need to do is make sure that the user controls and checkboxlist are public. Then you could refer to them in the standard OO way:<BR><BR>public class UserControl1 : UserControl<BR>{<BR>public CheckBoxList myList;<BR>}<BR><BR>public class UserControl2 : UserControl<BR>{<BR> public UserControl1 myControl;<BR>}<BR><BR>public class myPage : Page<BR>{<BR> protected UserControl2 myTopControl;<BR> void Page_Load()<BR> {<BR> CheckBoxList chkl = myTopControl.myControl.myList;<BR> }<BR>}<BR><BR>I tend not to like to have public web controls floating around but it should work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts