1

I have my code as below

 string[] keys = { "myCustomUserControl.ascx", "myCustomUserControl.ascx.cs", "myCustomUserControl.ascx.designer.cs" };

            string customUserControlName = CommonDataCalls.GetCustomUserControlName(keys);

            UserControl objUserControl = (UserControl)this.LoadControl("~/UserControls/" + userControlName);
            userControlPlaceHolder.Controls.Add(objUserControl);

The definition of GetCustomUserControlName is as below

public string GetCustomUserControlName(string[] keys)
    {
        try
        {
            string userConrolsPhysicalPtah = System.Web.HttpContext.Current.Server.MapPath("~/UserControls/");
            DataTable objDataTable = new DataTable();
            foreach (string key in keys)
            {
                objRequestVO.addObject("ACA_KEY", key);
                CResponseVO objResponseVO = (CResponseVO)objGateway.ExecuteBusinessService(CConstant.ADMIN, CConstant.ASSEMBLY_INFO, CConstant.SELECT, objRequestVO);
                DataSet objDataSet = (DataSet)objResponseVO.getObject("RES_DS");
                cUserTrce objGeneral = new cUserTrce();
                if (!objGeneral.IsNullOrEmptyDataset(objDataSet))
                {
                    if (objDataTable.Rows.Count == 0)
                    {
                        objDataTable = objDataSet.Tables[0].Clone();
                    }
                    objDataTable.Rows.Add(objDataSet.Tables[0].Rows[0].ItemArray);
                }
            }

            if (objDataTable != null && objDataTable.Rows.Count == 3)
            {                
                string containerName = "usercontrols";
                foreach (DataRow dr in objDataTable.Rows)
                {
                    string userControlFileBlobUrl = dr["ACA_ASSEMBLY_PATH"].ToString();
                    string userControlFileName = dr["ACA_CLASS_NAME"].ToString();

                    Storage.Blob blobHandler = new Storage.Blob();
                    Stream blobstream = blobHandler.GetBlob(userControlFileBlobUrl, containerName);
                    if (!(File.Exists(userConrolsPhysicalPtah + userControlFileName)))
                    {
                        MemoryStream ms = (MemoryStream)blobstream;
                        FileStream outStream = File.OpenWrite(userConrolsPhysicalPtah + userControlFileName);
                        ms.WriteTo(outStream);
                        outStream.Flush();
                        outStream.Close();
                    }
                }



                string customUserControlName = (from DataRow row in objDataTable.Rows
                                                where row["ACA_KEY"].ToString() == keys[0]
                                                select row["ACA_CLASS_NAME"].ToString()).First();

                return customUserControlName;
            }

            else
            {
                return null;
            }
        }
        catch
        {
            return null;
        }

    }

The mithod basically copies the user controls to the virtual path at run time .

In aspx.cs page I try to load it dynamically .

But I can see the file is getting copied to the virtual path but this. Load control gives me exception saying Could not load type 'myCustomUserControl'.

I am using azure web role
What is wrong here ?

1 Answer 1

1

I solved the bug . I am just putting here for anyone to refer .

It's a one word change -

http://blog.kjeldby.dk/2008/11/dynamic-compilation-in-a-web-application/

Change

CodeBehind="myCustomUserControl.ascx.cs"

to

CodeFile="myCustomUserControl.ascx.cs"

Thanks to @Roopesh & @Kristoffer Brinch Kjeldby

and it will start working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.