FindControl problems in nested user controls

Results 1 to 2 of 2

Thread: FindControl problems in nested user controls

  1. #1
    Join Date
    Dec 1969

    Default FindControl problems in nested user controls

    I am having a very frustrating problem. I am using many user controls to create reusable search components for my sports-related database, and have a component that is meant to search for and select a team. I use events to pass information between parent and child controls, and it all works out rather well when it does actually work. The problem I&#039;m having is I create the control, register it on my .ascx page, then when I refer to in the codebehind, I get NullReferenceExceptions. Here are some relevant bits:<BR>&#060;from uc1.ascx&#062;<BR>&#060;%@ Register tagPrefix="me" tagName="teamchooser" Src="/controls/teams/TeamChooser.ascx" %&#062;<BR>&#060;me:teamchooser id="tmChooser" runat="server" visible="true"/&#062;<BR>&#060;asp:button onclick="test" text = "toggle"/&#062;<BR>&#060;/uc1.ascx&#062;<BR>Then, in my code-behind, paraphrased<BR>&#060;from uc1.ascx.cs&#062;<BR>protected controls.teams.TeamChooser tmChooser;<BR>Page_Load(){<BR>tmChooser = (controls.teams.TeamChooser) this.FindControl("tmChooser");<BR>}<BR>test(){<BR> tmChooser.Visible = !tmChooser.Visible;<BR>}<BR>&#060;/uc1.ascx.cs&#062;<BR><BR>I get the NullReference on the line in test(). Any help?

  2. #2

    Default RE: FindControl problems in nested user controls

    try removing the line from Page_Load

Posting Permissions

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