issue with passing object to a function in c#

Hello,

iu am trying to pass an object to a function in c# and it sends over null  but the control exists on the page just not when its passed to the function.


CODE
        private void Page_Load(object sender, System.EventArgs e)
        {
            // gets the autenticated users infomation
            string username = null;
            string RUNStat = Request.QueryString["Run"];
            username = Request.ServerVariables["AUTH_USER"].Replace("ctis\\", "");
            // gets the errors that may be passed through the system
         // lblerror.Text = Convert.ToString(HttpContext.Current.Session["ERROR"]);
            Dynamic BanCons = new Dynamic();
            Authentication Auth = new Authentication();
            SystemInternals Setup = new SystemInternals();

            // call teh system setup class to set some local varables usined within the application
            Setup.Get_System_Sertup();

            // call some web services to get the data to the right places
            SLogs.ErrorLoggingSoapClient logs = new SLogs.ErrorLoggingSoapClient();
            Email.EmailSoap EmailWeb = new Email.EmailSoapClient();
            try
            {
                buildmenu();
                // calls The database to build the menu for administrators and developers

                if (RUNStat == "P")
                {
                    //    RunType.Text = "Production"
                }
                else if (RUNStat == "T")
                {
                    //   RunType.Text = "Test"
                }

                if (Auth.VerifyUserPermission(username, "ADM"))
                {
                    Welcome.Controls.Clear();
                    // *****
                    // ***** Draw header line
                    // *****
                    BanCons.WebLabelNew(Welcome, "Logged in successfully as " + username + "<hr />");
                    HttpContext.Current.Session["User"] = username;

                }
                else
                {
                    BanCons.WebLabelNew((Welcome), "You do not have access to this module.");
                    MainContent.Visible = false;
                }

                // *****
                // ***** Catch some errors
                // *****
            }
            catch (DataException exc)
            {
                logs.Errorlog(exc.ToString(), "ErrorLoggingSite",true);
            }

            // vasic copywright infi
            lblCopyright.Text = DynamicCopyright("2012");
        }

Open in new window


FUNCTION THAT I CALL
        ////////////////////////////////////////////
        //Author : Chris Jones
        //Department : Application Solutions
        //Version 1.0
        //Description:
        ////////////////////////////////////////////
        public void WebLabelNew(object PH, string LabelText, string CSSClass = "")
        {
            Label l = new Label();

            l.Text = LabelText;
            l.CssClass = CSSClass;
            (PH as Label).Controls.Add(l);

            l = null;
        }

Open in new window


ERROR

object not sent to an instance of an object.
LVL 1
Chris JonesLead Application Web DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Melih SARICAOwnerCommented:
I dont know what kind of control is "wellcome" but ur trying to cast that control as a label. and trying to add a label in label is that  right ?
0
Chris JonesLead Application Web DeveloperAuthor Commented:
oh sorry the welcome control is a placeholder.
0
Melih SARICAOwnerCommented:
on which line of the code u get this error ?
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Chris JonesLead Application Web DeveloperAuthor Commented:
BanCons.WebLabelNew(Welcome, "You do not have access to this module.");
0
Melih SARICAOwnerCommented:
BanCons.WebLabelNew is not a static function so u ave to create an instance of bancons
bancons = new Bancons();
bancons.weblabelnew....
0
Chris JonesLead Application Web DeveloperAuthor Commented:
this is what this line does in my code right ?

       Dynamic BanCons = new Dynamic();
0
Chris JonesLead Application Web DeveloperAuthor Commented:
i also wanted to nbot that the values are p[assed to the function just fine its the placeholder thans sends null.

i can see this text in teh function that i call when i step through= You do not have access to this module

      BanCons.WebLabelNew(Welcome , "You do not have access to this module.");

but this is null when i step through them i get an error = Welcome
0
Melih SARICAOwnerCommented:
sorry i did not see that line...

did u try  u step into that weblabelnew
0
Chris JonesLead Application Web DeveloperAuthor Commented:
yes it gives me a null object for my placeholder control so i did a test i created a placeholder on teh fly and pased it n and i dont get a null object but i still get the object not sent to an instance of an object.

EXMAPLE CHANGE
                  PlaceHolder holder = new PlaceHolder();


                    BanCons.WebLabelNew(holder, "You do not have access to this module.");
                    MainContent.Visible = false;

Open in new window

0
Chris JonesLead Application Web DeveloperAuthor Commented:
here is a screenshotc
0
Chris JonesLead Application Web DeveloperAuthor Commented:
i found my error or something it looks liek i cant read any controls in my page so i ahev a placeholder on the page and i can refrence it but it always returns null.

or emxpale i have a label on my page and i ran it and it gave me the null error as well

      lblerror.Text = " This is a test ";
0
Melih SARICAOwnerCommented:
Change (PH as Placeholder).controls.add(l); and try it please
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.