Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
Trying to find programmatically created control within WebTab
posted

I working an ASP.Net 4 project in Visual Studio 2010 that allows users to select and run SQL Server 2008 Reporting Services reports.

When the user selects a report, any controls needed to select parameters are programmatically generated within an ASP.NET Panel on a different Tab (i.e., Reports are selected on Tab[0], Parameters are specified on Tab[1], Results (ReportViewer) are seen on Tab[2]).

Parameters are being added to an ASP.Net Panel using the following assignment (sample):

pnlParametersRight.Controls.Add(ctlParam);

 

 

After the panel's closing tag (</Panel>), I've added a "Generate Results" button.

Interestingly, when I go to Tab[1], the controls are (correctly added, including valid values in dropdownboxes and listboxes) below the button, instead of above it.

At any rate, once the user selects the parameters values, he or she clicks the "Generate Results" button.

I need to pass the parmeter values from the controls in Tab[1] to Reporting Services.

I'm running into a problem finding the parameter controls.

In order to find the correct names, I built a small method that shows me the names as I step through the code:

 

 

 

 

 

 

 

WebTab

 

 

menu = (WebTab)FindControl("mnuiQuery");

 

 

 

string foo = "";

 

 

 

int c = 0;

// menu.Tabs[1].FindControl("tmpl1").Controls.Count;

 

 

 

string subctl = "";

 

 

 

foreach (Control ctl in menu.Tabs[1].Controls)

{ foo = ctl.ID.ToString();                       // foo shows ctl.ID as "tmp1"

 

 

 

   foreach (Control ctl2 in ctl.FindControl("tmpl1").Controls)   *** here the method blows up with a "Object reference not set to an instance of an object." error

   {

      c = ctl.FindControl(

 

"tmpl1").Controls.Count;

 

 

 

      if (ctl2.ID != null)

         subctl = ctl2.ID.ToString();

   }

}

I don't understand how one line can find the control with ID "tmpl1", but when I try to access it, it blows up. Am I missing something really simple here?

TIA,

badger98023