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

Top 5 Contributors of the Month
Imran Ghani

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()
                // 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
            catch (Exception CreateChildControls_Exception)
                _exceptions += "CreateChildControls_Exception: " + CreateChildControls_Exception.Message;
                throw new ArgumentException(_exceptions);

            }//end catch
            }//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
            catch (Exception RenderContents_Exception)
                _exceptions += "RenderContents_Exception: " + RenderContents_Exception.Message;
                throw new ArgumentException(_exceptions);

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



Further Readings:


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