locked
Custom control and VS 2008 bugs RRS feed

  • Question

  • User-1206499603 posted

    Hi everyone,

    I'm trying to write a custom control and  I have some questions about it. Please help me!!! 

    1 - It has a DataSourceID property (like GridView) and also it has a "System.Web.UI.Design.ControlDesigner" based designer class. if I changed this property outside of the UpdatePanel it adds designer html output to Sourceview of the control. It is realy strange. Is it a bug of VS 2008 or mine.

    2 - I am trying to implement a ControlToBind property like ControlToValidate property but it has to be a DataGrid, GridView, Repeater or DataList. Is there a way to filter these items for Design view.

    3 - When I changed its properties it doesn't effect the sourceview (except the first problem I mentioned). I run this fix but it didn't fix my problem (I have no MS Office installed in my computer maybe it's related). http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=17185

     

    Thanks in advance.

    Sunday, January 24, 2010 5:40 PM

All replies

  • User-1136466523 posted

    Hi,

    if I changed this property outside of the UpdatePanel it adds designer html output to Sourceview of the control. 

    Could you please clarify? What property you changed? And what kind of html markups added into the source view of the control?

     

    Tuesday, January 26, 2010 12:15 AM
  • User-1206499603 posted

    Hi and thanks for your response,

    I'm sending a simple code example below about my problem. You can see if you build this and add its dll file to a WebSite as a Control. And don't forget all the problems happen when you change some think in design view and switch it to Source View.

    As you can see there is DataSourceId property. if "testControl" is placed in a UpdatePanel and I changed SourceID property by selecting from the ComboBox it seems like everything is OK but when I switch it to SourceView there is no changes in the SourceView and also aspx file. (And I think it is same problem with O mentioned as 3. item.)

    But if "testControl" is outside a UpdatePanel and I changed the DataSourceID using combobox again the IDE adds DataSourceID correctly and also it adds desing time output to Source view.

     

    Here is the example.

    First time. The control was newly added.

    <cc1:testControl ID="TestControl1" runat="server" />


    After I changed the DataSourceID in design view.

    <cc1:testControl ID="TestControl1" runat="server" 
                DataSourceID="SqlDataSource1" >
                    <a href='#'>This is design time</a></cc1:testControl>


     

     Control Example

     

    using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Collections;
    using System.Text;
    using System.Collections.Generic;
    using System.Configuration;
    using System.IO;
    namespace test
    {
    
        [Designer(typeof(TestDesigner)), DefaultEvent("PageChange"), DefaultProperty("PageSize"), ToolboxData("<{0}:testControl runat=\"server\" />")]
        public class testControl : WebControl
        {
    
    
    
    
            #region Properties
    
            private string _dataSourceId = "";
            [
            IDReferenceProperty(typeof(DataSourceControl)),
            TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter)),
            Category("Data"),
            Themeable(false),
            DefaultValue(""),
            Description("The control ID of an IDataSource that will be used as the data source.")
            ]
            public string DataSourceID
            {
                get
                {
                    return _dataSourceId;
                }
                set
                {
                    _dataSourceId = value;
                }
            }
    
            private string _dataMember = "";
            [
            Bindable(false),
            Category("Data"),
            DefaultValue(""),
            Description("Get or set DataMember for DataSourceId")
            ]
            public string DataMember
            {
                get
                {
                    return _dataMember;
                }
                set
                {
                    _dataMember = value;
                }
            }
    
            #endregion
    
    
            protected override void Render(HtmlTextWriter writer)
            {
                base.Render(writer);
            }
    
    
        }
    
    
        public class TestDesigner : System.Web.UI.Design.ControlDesigner
        {
            public override string GetDesignTimeHtml()
            {
                try
                {
                    return GetPersistenceContent();
                }
                catch
                {
                    try
                    {
                        return "<a href='#'>This is design time(error)</a>";
                    }
                    catch (Exception e)
                    {
    
                        return this.GetErrorDesignTimeHtml(e);
                    }
                }
            }
    
            protected override string GetEmptyDesignTimeHtml()
            {
                //Return empty text in a placeholder
                return this.CreatePlaceHolderDesignTimeHtml("Add items to the list.");
            }
    
            protected override string GetErrorDesignTimeHtml(Exception e)
            {
                //Return error text in a placeholder
                return this.CreatePlaceHolderDesignTimeHtml("The control could not be loaded:<br>" + e.ToString());
            }
            [System.Obsolete]
            public override string GetPersistInnerHtml()
            {
                return "<a href='#'>This is design time</a>";
            }
    
        }
    
       
    
    
    }
    
    


     

     

     

    Tuesday, January 26, 2010 9:58 AM