//Draws the controls, only gets called for the first drawing of the page, not for each postback
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            try
            {
                _xml = new XmlDocument();
                _xml.LoadXml(_data.Value.ToString());

            }
            catch
            {
                _xml = createBaseXmlDocument();
            }

            _listboxLinks = new ListBox();
            _listboxLinks.ID = "links" + base.ID;
            _listboxLinks.Width = 400;
            _listboxLinks.Height = 140;
            foreach (XmlNode node in _xml.DocumentElement.ChildNodes)
            {
                string text = node.Attributes["title"].Value.ToString();
                string value = (node.Attributes["type"].Value.ToString().Equals("internal") ? "i" : "e")
                    + (node.Attributes["newwindow"].Value.ToString().Equals("1") ? "n" : "o")
                    + node.Attributes["link"].Value.ToString();
                _listboxLinks.Items.Add(new ListItem(text, value));
            }

            _buttonUp = new Button();
            _buttonUp.ID = "btnUp" + base.ID;
            _buttonUp.Text = umbraco.ui.GetText("relatedlinks", "modeUp");
            _buttonUp.Width = 80;
            _buttonUp.Click += new EventHandler(this.buttonUp_Click);

           
            _buttonDown = new Button();
            _buttonDown.ID = "btnDown" + base.ID;
            _buttonDown.Attributes.Add("style", "margin-top: 5px;");
            _buttonDown.Text = umbraco.ui.GetText("relatedlinks", "modeDown");
            _buttonDown.Width = 80;
            _buttonDown.Click += new EventHandler(this.buttonDown_Click);

            _buttonDelete = new Button();
            _buttonDelete.ID = "btnDel" + base.ID;
            _buttonDelete.Text = umbraco.ui.GetText("relatedlinks", "removeLink");
            _buttonDelete.Width = 80;
            _buttonDelete.Click += new EventHandler(this.buttonDel_Click);

            _textboxLinkTitle = new TextBox();
            _textboxLinkTitle.Width = 400;
            _textboxLinkTitle.ID = "linktitle" + base.ID;

            _checkNewWindow = new CheckBox();
            _checkNewWindow.ID = "checkNewWindow" + base.ID;
            _checkNewWindow.Checked = false;
            _checkNewWindow.Text = umbraco.ui.GetText("relatedlinks", "newWindow");

            _textBoxExtUrl = new TextBox();
            _textBoxExtUrl.Width = 400;
            _textBoxExtUrl.ID = "exturl" + base.ID;

            _buttonAddExtUrl = new Button();
            _buttonAddExtUrl.ID = "btnAddExtUrl" + base.ID;
            _buttonAddExtUrl.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddExtUrl.Width = 80;
            _buttonAddExtUrl.Click += new EventHandler(this.buttonAddExt_Click);

            _buttonAddIntUrlCP = new Button();
            _buttonAddIntUrlCP.ID = "btnAddIntUrl" + base.ID;
            _buttonAddIntUrlCP.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddIntUrlCP.Width = 80;
            _buttonAddIntUrlCP.Click += new EventHandler(this.buttonAddIntCP_Click);

            _pagePickerExtractor = new PagePickerDataExtractor();
            _pagePicker = new pagePicker(_pagePickerExtractor);
            _pagePicker.ID = "pagePicker" + base.ID;
            
            ContentTemplateContainer.Controls.Add(new LiteralControl("<div class=\"relatedlinksdatatype\" style=\"text-align: left;  padding: 5px;\"><table><tr><td rowspan=\"2\">"));
            ContentTemplateContainer.Controls.Add(_listboxLinks);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td><td style=\"vertical-align: top\">"));
            ContentTemplateContainer.Controls.Add(_buttonUp);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(_buttonDown);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td></tr><tr><td style=\"vertical-align: bottom\">"));
            ContentTemplateContainer.Controls.Add(_buttonDelete);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td></tr></table>"));

            // Add related links container
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<a href=\"javascript:;\" onClick=\"document.getElementById('{0}_addExternalLinkPanel').style.display='none';document.getElementById('{0}_addExternalLinkButton').style.display='none';document.getElementById('{0}_addLinkContainer').style.display='block';document.getElementById('{0}_addInternalLinkPanel').style.display='block';document.getElementById('{0}_addInternalLinkButton').style.display='block';\"><strong>{1}</strong></a>", ClientID, umbraco.ui.GetText("relatedlinks", "addInternal"))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format(" | <a href=\"javascript:;\" onClick=\"document.getElementById('{0}_addInternalLinkPanel').style.display='none';document.getElementById('{0}_addInternalLinkButton').style.display='none';document.getElementById('{0}_addLinkContainer').style.display='block';document.getElementById('{0}_addExternalLinkPanel').style.display='block';document.getElementById('{0}_addExternalLinkButton').style.display='block';\"><strong>{1}</strong></a>", ClientID, umbraco.ui.GetText("relatedlinks", "addExternal"))));

            // All urls
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"{0}_addLinkContainer\" style=\"display: none; padding: 4px; border: 1px solid #ccc; margin-top: 5px;margin-right:10px;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<a href=\"javascript:;\" onClick=\"document.getElementById('{0}_addLinkContainer').style.display='none';\" style=\"border: none;\"><img src=\"{1}/images/close.png\" style=\"float: right\" /></a>", ClientID,  this.Page.ResolveUrl(SystemDirectories.Umbraco))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "caption"))));
            ContentTemplateContainer.Controls.Add(_textboxLinkTitle);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"{0}_addExternalLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "linkurl"))));
            ContentTemplateContainer.Controls.Add(_textBoxExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"{0}_addInternalLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "internalPage"))));
            ContentTemplateContainer.Controls.Add(_pagePicker);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl("<div style=\"margin: 5px 0\">"));
            ContentTemplateContainer.Controls.Add(_checkNewWindow);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"{0}_addInternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddIntUrlCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"{0}_addExternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            resetInputMedia();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        /// <exception cref="T:System.InvalidOperationException">
        /// The <see cref="P:System.Web.UI.UpdatePanel.ContentTemplate"/> property is being defined when the <see cref="P:System.Web.UI.UpdatePanel.ContentTemplateContainer"/> property has already been created.
        /// </exception>
        /// <remarks>
        /// Draws the controls, only gets called for the first drawing of the page, not for each postback
        /// </remarks>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            string editLink = string.Format(@"
                        function {0}_relatedLinkEdit() {{
                            var idx = document.getElementById('{0}links').selectedIndex;
                            if (idx != -1) {{
                                var link = document.getElementById('{0}links')[idx].value;
                                var text = document.getElementById('{0}links')[idx].text;
                                if (link.length > 2) {{
                                    var linkType = link.substring(0,1);
                                    var linkNewWind = link.substring(1,2);
                                    var linkLink = link.substring(2);

                                    {0}_closeLinkContainer();

                                    document.getElementById('{0}linktitle').value = text;
                                    if (linkNewWind == 'n') {{
                                        document.getElementById('{0}checkNewWindow').checked = true;
                                    }}
                                    else {{
                                        document.getElementById('{0}checkNewWindow').checked = false;
                                    }}
                                    switch (linkType)
                                    {{
                                        case 'i':
                                            var e = {{ outVal: linkLink }};
                                            mc_{0}pagePicker.SaveSelection(e);
                                            document.getElementById('{0}_addInternalLinkPanel').style.display='block';
                                            document.getElementById('{0}_editInternalLinkButton').style.display='block';
                                            break;

                                        case 'm':
                                            var e = {{ outVal: linkLink }};
                                            mc_{0}mediaChooser.SaveSelection(e);
                                            document.getElementById('{0}_addMediaLinkPanel').style.display='block';
                                            document.getElementById('{0}_editMediaLinkButton').style.display='block';
                                            break;

                                        case 'e':
                                            document.getElementById('{0}exturl').value = linkLink;
                                            document.getElementById('{0}_addExternalLinkPanel').style.display='block';
                                            document.getElementById('{0}_editExternalLinkButton').style.display='block';
                                            break;
                                    }}
                                    document.getElementById('{0}_addLinkContainer').style.display='block';
                                }}
                            }}
                        }}

                        function {0}_addInternalLink() {{
                            {0}_closeLinkContainer();
                            document.getElementById('{0}linktitle').value = '';
                            document.getElementById('{0}checkNewWindow').checked = false;
                            //{0}pagePicker_clear();
                            mc_{0}pagePicker.ClearSelection();

                            document.getElementById('{0}_addInternalLinkPanel').style.display='block';
                            document.getElementById('{0}_addInternalLinkButton').style.display='block';
                            document.getElementById('{0}_addLinkContainer').style.display='block';
                        }}
                        function {0}_addMediaLink() {{
                            {0}_closeLinkContainer();
                            document.getElementById('{0}linktitle').value = '';
                            document.getElementById('{0}checkNewWindow').checked = false;
                            //{0}mediaChooser_clear();
                            mc_{0}mediaChooser.ClearSelection();

                            document.getElementById('{0}_addMediaLinkPanel').style.display='block';
                            document.getElementById('{0}_addMediaLinkButton').style.display='block';
                            document.getElementById('{0}_addLinkContainer').style.display='block';
                        }}
                        function {0}_addExternalLink() {{
                            {0}_closeLinkContainer();
                            document.getElementById('{0}linktitle').value = '';
                            document.getElementById('{0}checkNewWindow').checked = false;
                            document.getElementById('{0}exturl').value = 'http://';

                            document.getElementById('{0}_addExternalLinkPanel').style.display='block';
                            document.getElementById('{0}_addExternalLinkButton').style.display='block';
                            document.getElementById('{0}_addLinkContainer').style.display='block';
                        }}
                        function {0}_closeLinkContainer() {{
                            document.getElementById('{0}_addInternalLinkPanel').style.display='none';
                            document.getElementById('{0}_addInternalLinkButton').style.display='none';
                            document.getElementById('{0}_editInternalLinkButton').style.display='none';

                            document.getElementById('{0}_addMediaLinkPanel').style.display='none';
                            document.getElementById('{0}_addMediaLinkButton').style.display='none';
                            document.getElementById('{0}_editMediaLinkButton').style.display='none';

                            document.getElementById('{0}_addExternalLinkPanel').style.display='none';
                            document.getElementById('{0}_addExternalLinkButton').style.display='none';
                            document.getElementById('{0}_editExternalLinkButton').style.display='none';

                            document.getElementById('{0}_addLinkContainer').style.display='none';
                        }}
                        ", this.ClientID);
            Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID + "_editLink", editLink, true);

            try
            {
                _xml = new XmlDocument();
                _xml.LoadXml(_data.Value.ToString());

            }
            catch
            {
                _xml = createBaseXmlDocument();
            }

            _listboxLinks = new ListBox();
            _listboxLinks.ID = base.ID + "links";
            _listboxLinks.Attributes.Add("onClick", ClientID + "_closeLinkContainer();");
            _listboxLinks.Width = 400;
            _listboxLinks.Height = 140;
            foreach (XmlNode node in _xml.DocumentElement.ChildNodes)
            {
                string text = node.Attributes["title"].Value.ToString();
                string type;
                if (node.Attributes["type"].Value.ToString().Equals("internal"))
                    type = "i";
                else if (node.Attributes["type"].Value.ToString().Equals("media"))
                    type = "m";
                else
                    type = "e";

                string value = type
                    + (node.Attributes["newwindow"].Value.ToString().Equals("1") ? "n" : "o")
                    + node.Attributes["link"].Value.ToString();
                _listboxLinks.Items.Add(new ListItem(text, value));
            }

            _buttonUp = new Button();
            _buttonUp.ID = base.ID + "btnUp";
            _buttonUp.Text = umbraco.ui.GetText("relatedlinks", "modeUp");
            _buttonUp.Width = 80;
            _buttonUp.Click += new EventHandler(this.buttonUp_Click);

            _buttonDown = new Button();
            _buttonDown.ID = base.ID + "btnDown";
            _buttonDown.Attributes.Add("style", "margin-top: 5px;");
            _buttonDown.Text = umbraco.ui.GetText("relatedlinks", "modeDown");
            _buttonDown.Width = 80;
            _buttonDown.Click += new EventHandler(this.buttonDown_Click);

            _buttonEdit = new Button();
            _buttonEdit.ID = base.ID + "btnEdit";
            _buttonEdit.Text = GetTextWithDefault("relatedlinks", "editLink", "Edit link");
            _buttonEdit.Width = 80;
            _buttonEdit.OnClientClick = this.ClientID + "_relatedLinkEdit(); return false;";

            _buttonDelete = new Button();
            _buttonDelete.ID = base.ID + "btnDel";
            _buttonDelete.Text = umbraco.ui.GetText("relatedlinks", "removeLink");
            _buttonDelete.Width = 80;
            _buttonDelete.Click += new EventHandler(this.buttonDel_Click);

            _textboxLinkTitle = new TextBox();
            _textboxLinkTitle.Width = 400;
            _textboxLinkTitle.ID = base.ID + "linktitle";

            _checkNewWindow = new CheckBox();
            _checkNewWindow.ID = base.ID + "checkNewWindow";
            _checkNewWindow.Checked = false;
            _checkNewWindow.Text = umbraco.ui.GetText("relatedlinks", "newWindow");

            _textBoxExtUrl = new TextBox();
            _textBoxExtUrl.Width = 400;
            _textBoxExtUrl.ID = base.ID + "exturl";

            _buttonAddExtUrl = new Button();
            _buttonAddExtUrl.ID = base.ID + "btnAddExtUrl";
            _buttonAddExtUrl.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddExtUrl.Width = 80;
            _buttonAddExtUrl.Click += new EventHandler(this.buttonAddExt_Click);

            _buttonAddIntUrlCP = new Button();
            _buttonAddIntUrlCP.ID = base.ID + "btnAddIntUrl";
            _buttonAddIntUrlCP.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddIntUrlCP.Width = 80;
            _buttonAddIntUrlCP.Click += new EventHandler(this.buttonAddIntCP_Click);

            _buttonAddMediaCP = new Button();
            _buttonAddMediaCP.ID = base.ID + "btnAddMedia";
            _buttonAddMediaCP.Text = umbraco.ui.GetText("relatedlinks", "addlink");
            _buttonAddMediaCP.Width = 80;
            _buttonAddMediaCP.Click += new EventHandler(this.buttonAddMediaCP_Click);

            _buttonEditExtUrl = new Button();
            _buttonEditExtUrl.ID = base.ID + "btnEditExtUrl";
            _buttonEditExtUrl.Text = GetTextWithDefault("relatedlinks", "savelink", "Save");
            _buttonEditExtUrl.Width = 80;
            _buttonEditExtUrl.Click += new EventHandler(this.buttonEditExt_Click);

            _buttonEditIntUrlCP = new Button();
            _buttonEditIntUrlCP.ID = base.ID + "btnEditIntUrl";
            _buttonEditIntUrlCP.Text = GetTextWithDefault("relatedlinks", "savelink", "Save");
            _buttonEditIntUrlCP.Width = 80;
            _buttonEditIntUrlCP.Click += new EventHandler(this.buttonEditIntCP_Click);

            _buttonEditMediaCP = new Button();
            _buttonEditMediaCP.ID = base.ID + "btnEditMedia";
            _buttonEditMediaCP.Text = GetTextWithDefault("relatedlinks", "savelink", "Save");
            _buttonEditMediaCP.Width = 80;
            _buttonEditMediaCP.Click += new EventHandler(this.buttonEditMediaCP_Click);

            _pagePickerExtractor = new PagePickerwMediaDataExtractor();
            _pagePicker = new pagePicker(_pagePickerExtractor);
            _pagePicker.ID = base.ID + "pagePicker";

            _mediaChooserExtractor = new PagePickerwMediaDataExtractor();
            _mediaChooser = new mediaChooser(_mediaChooserExtractor);
            _mediaChooser.ID = base.ID + "mediaChooser";

            ContentTemplateContainer.Controls.Add(new LiteralControl("<div class=\"relatedlinksdatatype\" style=\"text-align: left;  padding: 5px;\"><table><tr><td rowspan=\"2\">"));
            ContentTemplateContainer.Controls.Add(_listboxLinks);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td><td style=\"vertical-align: top\">"));
            ContentTemplateContainer.Controls.Add(_buttonUp);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(_buttonDown);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td></tr><tr><td style=\"vertical-align: bottom\">"));
            ContentTemplateContainer.Controls.Add(_buttonEdit);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(_buttonDelete);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));
            ContentTemplateContainer.Controls.Add(new LiteralControl("</td></tr></table>"));

            // Add related links container: for each link type, we add a link that displays the
            // corresponding div and hides the others
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<a href=\"javascript:;\" onClick=\"{0}_addInternalLink();\"><strong>{1}</strong></a>", ClientID, umbraco.ui.GetText("relatedlinks", "addInternal"))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format(" | <a href=\"javascript:;\" onClick=\"{0}_addMediaLink();\"><strong>{1}</strong></a>", ClientID, GetTextWithDefault("relatedlinks", "addMedia", "Add media link"))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format(" | <a href=\"javascript:;\" onClick=\"{0}_addExternalLink();\"><strong>{1}</strong></a>", ClientID, umbraco.ui.GetText("relatedlinks", "addExternal"))));

            // All urls containers
            // Main contaniner: {ClienID}_addLinkContainer
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addLinkContainer\" style=\"display: none; padding: 4px; border: 1px solid #ccc; margin-top: 5px;margin-right:10px;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<a href=\"javascript:;\" onClick=\"{0}_closeLinkContainer();\" style=\"border: none;\"><img src=\"{1}/images/close.png\" style=\"float: right\" /></a>", ClientID, IOHelper.ResolveUrl(SystemDirectories.Umbraco))));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "caption"))));
            ContentTemplateContainer.Controls.Add(_textboxLinkTitle);
            ContentTemplateContainer.Controls.Add(new LiteralControl("<br />"));

            // External Url container: {CliendID}_addExternalLinkPanel
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addExternalLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "linkurl"))));
            ContentTemplateContainer.Controls.Add(_textBoxExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Internal Link container: {CliendID}_addInternalLinkPanel
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addInternalLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", umbraco.ui.GetText("relatedlinks", "internalPage"))));
            ContentTemplateContainer.Controls.Add(_pagePicker);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Media Link container: {CliendID}_addMediaLinkPanel
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addMediaLinkPanel\" style=\"display: none; margin: 3px 0\">", ClientID)));
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("{0}:<br />", GetTextWithDefault("relatedlinks", "media", "Media"))));
            ContentTemplateContainer.Controls.Add(_mediaChooser);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Checkbox for new window container
            ContentTemplateContainer.Controls.Add(new LiteralControl("<div style=\"margin: 5px 0\">"));
            ContentTemplateContainer.Controls.Add(_checkNewWindow);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Internal Link button: {ClientID}_addInternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addInternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddIntUrlCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
            // Internal Link button: {ClientID}_editInternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_editInternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonEditIntUrlCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // Media Link button: {ClientID}_addMediaLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addMediaLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddMediaCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
            // Media Link button: {ClientID}_editMediaLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_editMediaLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonEditMediaCP);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            // External Url button: {ClientID}_addExternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_addExternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonAddExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
            // External Url button: {ClientID}_editExternalLinkButton
            ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<div id=\"{0}_editExternalLinkButton\" style=\"display: none;\">", ClientID)));
            ContentTemplateContainer.Controls.Add(_buttonEditExtUrl);
            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            resetInputMedia();
        }