Custom Control raising 'System.Web.UI.HtmlControls.HtmlS

Posted by Community Admin on 04-Aug-2018 00:55

Custom Control raising 'System.Web.UI.HtmlControls.HtmlSelect' does not allow child controls Error

All Replies

Posted by Community Admin on 26-May-2011 00:00

Hi,

I created a custom control that contains 2 html selects which each selects contains items. Unfortunately when i drag and drop it on my lay out page it raises error "

'System.Web.UI.HtmlControls.HtmlSelect' does not allow child controls.


".

my custome ascx code is :

<%@ Control Language="C#" AutoEventWireup="true" %>
<div id="search_title">
    Search Publications by:</div>
<div id="search_container">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td>
                Service Line<br />
                <select id="selServiceLine" name="selServiceLine" runat="server" class="sel_generic">
                    <option selected="selected" value="-1"></option>
                    <option value="0">Corporate Recovery</option>
                    <option value="1">Turnaround and Restructuring</option>
                    <option value="2">Real Estate Advisory</option>
                    <option value="3">Forensics</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td>
                Industry<br />
                <select id="selIndustry" name="selIndustry" runat="server" class="sel_generic">
                    <option selected="selected" value="-1"></option>
                    <option value="0">Accommodation, Cafes and Restaurants</option>
                    <option value="1">Agriculture, Forestry and Fishing</option>
                    <option value="2">Automotive</option>
                    <option value="3">Communication</option>
                    <option value="4">Construction</option>
                    <option value="5">Cultural and Recreational Services</option>
                    <option value="6">Education</option>
                    <option value="7">Electricity, Gas and Water Supply</option>
                    <option value="8">Environmental</option>
                    <option value="9">Finance and Insurance</option>
                    <option value="10">Health and Aged Care</option>
                    <option value="11">Information Technology</option>
                    <option value="12">Manufacturing</option>
                    <option value="13">Mining</option>
                    <option value="14">Personal and Other Services</option>
                    <option value="15">Pharmaceutical</option>
                    <option value="16">Property and Business Services</option>
                    <option value="17">Retail Trade</option>
                    <option value="18">Transport and Storage</option>
                    <option value="19">Wholesaling</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td>
                <a id="lnkEnter" onclick="submit()">
                    <img src="/Sitefinity/WebsiteTemplates/Default/App_Themes/Default/Images/btn_enter.gif"
                        alt="Enter" align="absmiddle" /></a>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
        </tr>
    </table>
    <hr />
</div>

and my .cs code is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Text;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Web.UI.HtmlControls;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;
using KordaMentha.Controls.Designers;


namespace KordaMentha.Controls.Interfaces

    [ControlDesigner(typeof(SearchSC3Designer))]
    public class SearchSC3 : SimpleView
   
        public SearchSC3()
       

       

        protected override void OnPreRender(EventArgs e)
       
            base.OnPreRender(e);
            ScriptManager.RegisterClientScriptInclude(this, GetType(), "SearchScript", ResolveUrl("/Controls/js/SearchSC3.js"));

       

        protected override void OnLoad(EventArgs e)
       
            EnsureChildControls();
       

        protected override string LayoutTemplateName
       
            get
           
                return "KordaMentha.Controls.Interfaces.SearchSC3.ascx";
           
       

        protected override void InitializeControls(GenericContainer controlContainer)
       

       

        protected virtual HtmlControl selServiceLine
       
            get return base.Container.GetControl<HtmlControl>("selServiceLine", true);
       

        protected virtual HtmlControl selIndustry
       
            get return base.Container.GetControl<HtmlControl>("selIndustry", true);
       

        protected virtual HtmlAnchor lnkEnter
       
            get return base.Container.GetControl<HtmlAnchor>("lnkEnter", true);
       

        public string Title get; set;
   


what i did wrong anyway ?

thanks

Posted by Community Admin on 26-May-2011 00:00

Hi John,

I set the control at my end and it did not throw errors. I attached a short video that illustrates this.

Are there issues if you move the logic to user control instead of custom control that inherits from SimpleView?

Also you should use VirtualPathProvider to register the template

return "KordaMentha.Controls.Interfaces.SearchSC3.ascx";

and LayoutTemplatePath property. For LayoutTemplateName you should return null.

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed