.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

ADD Custom Web part to Child Control

Posted By:Sagar Pardeshi       Posted Date: April 02, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This code to add and lode customize web part to child control
 

 
protected string UserControlPath = @"~/usercontrols/";
         protected string UserControlFileName = @"UserInformation.ascx";
        Control _control = new Control();
        private String _exceptions;

        protected override void CreateChildControls()
        {
            try
            {
                // load the control ... this could require GAC installation
                // of your DLL to avoid File.IO permissions denial exceptions
                _control = this.Page.LoadControl(UserControlPath + UserControlFileName);
                // add it to the controls collection to wire up events
                Controls.Add(_control);
            }
            catch (Exception CreateChildControls_Exception)
            {
                _exceptions += "CreateChildControls_Exception: " + CreateChildControls_Exception.Message;
                throw new ArgumentException(_exceptions);

            }//end catch
            finally
            {
                base.CreateChildControls();
            }//end try/catch/finally block
        }//end protected override void CreateChildControls()
        protected override void RenderContents(HtmlTextWriter writer)
        {
            // not much to do here except to programmatically and cleanly
            // handle exceptions
            try
            {
                base.RenderContents(writer);
            }
            catch (Exception RenderContents_Exception)
            {
                _exceptions += "RenderContents_Exception: " + RenderContents_Exception.Message;
                throw new ArgumentException(_exceptions);
            }
            finally
            {

            }//end try/catch/finally
        }//end protected override void RenderContents(HtmlTextWriter writer)

    }

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend