c# - Problem Creating Instances of ASP.NET User Controls Programmatically -


I am able to create control pro from the gramma without any problem using the code given below:

< Pre> FileListReader FReader = (FileListReader) LoadControl ("~ / Controls / FileListReader.ascx"); PhFileLists.Controls.Add (fReader); However, I would like to change the control so that I can give it a constructor like this:
  Public FileListReader (Int32 itemGroupId, Int32 documentType, string header string , String Footer String, Bull is Administrator) {base.Construct (); This.itemGroupId = itemGroupId; This.documentType = documentType; This.HeaderString = HeaderString; This.FooterString = FooterString; This.isAdminUser = isAdminUser; }  

And then I should be able to call control in this way:

  FileListReader fReader = (FileListReader) LoadControl (typeof (FileListReader), New Object [] {Item Group ID, 6, "Cell Sheets", "End Lt; BR /> 
AdManuser}};

However, when I do this, I always get an error that the control within the file control manager in my file has not been started and I get an empty reference error. So for example I have a and gt; & Lt; / Asp: label & gt; is the control, when I try to set the text on the page_load method, what is the reason for it being generated? I felt that base.Construct () must have solved this issue but it is not clearly.

The proper way of a manufacturer's heir is as follows:

  Class FileListReader: WebControl {Public FileListReader (Int32 itemGroupId, Int32 documentType, String Header String, String Footer, bool isAdminUser): Base () // and & lt; - Notice this heir {this.itemGroupId = itemGroupId; This.documentType = documentType; This.HeaderString = HeaderString; This.FooterString = FooterString; This.isAdminUser = isAdminUser; } // ... other code here ...  

Does your constructor change to fix the problem?


Comments