|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataSourceID '<NewDataSource ...>' not working in composite controeverything working in the relevant properties (DataTextField, etc.), including that DataSourceID properly lists all valid datasources on the page. However, when I choose '<NewDataSource...>', the wizard doesn't fire, and the properly value simply changes to '<NewDataSource...>'. Is there some action I need to conduct on my part to fire the New Data Source wizard? The following is the code I am using for this property (which maps it to the underlying CheckBox which does all the binding work): /// <summary> /// Gets or sets the ID of the control from which the data-bound control retrieves its list of data items. /// </summary> /// <value>The ID of a control that represents the data source from which the data-bound control retrieves its data.</value> [IDReferenceProperty(typeof(DataSourceControl))] [TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter))] [DefaultValue((string)null)] [Description("The ID of the control from which the data-bound control retrieves its list of data items.")] [Category("Data")] public string DataSourceID { get { EnsureChildControls(); return m_chk.DataSourceID; } set { EnsureChildControls(); m_chk.DataSourceID = value; } } Hi Christophe,
Welcome to the ASP.NET newsgroup. It seems you're going on for your custom webcontrols :). For the DataSourceID property, decorate them with [IDReferenceProperty(typeof(DataSourceControl))] [TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter ))] is not sufficient, the two attribute can only help the IDE correct manage the value of that property or select existing datasource controls on the webform. However, for the "Create New DataSource" wizard you mentioned, it depend on the control's design-time ActionList feature: #DesignerActionList Class http://msdn2.microsoft.com/en-us/library/system.componentmodel.design.design eractionlist.aspx And for those buildin DataBound Controls, they are derived from the DataBoundControl class which has implemented some of the designer Actions(in the Designer) so that the child control classes and utilize. Since our custom control doesn't derive from the base class, the "Create New DataSource" wizard won't work.... You can consider derive your custom control from the DataBouncControl class and implement those required method( do not need to actually put any detailed code there......). For example: namespace WebControlLib { [DefaultProperty("Text")] [ToolboxData("<{0}:DSTestControl runat=server></{0}:DSTestControl>")] //[Designer("System.Web.UI.Design.WebControls.DataBoundControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class DSTestControl : DataBoundControl, INamingContainer { private string _dsid; [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? String.Empty : s); } set { ViewState["Text"] = value; } } [IDReferenceProperty(typeof(DataSourceControl))] [TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter ))] public string DataSourceID { get { //EnsureChildControls(); //return m_chk.DataSourceID; return _dsid; } set { //EnsureChildControls(); //m_chk.DataSourceID = value; _dsid = value; } } protected override void RenderContents(HtmlTextWriter output) { output.Write("<br/>DataSourceId: " + _dsid); } protected override void PerformSelect() { //do nothing; //throw new Exception("The method or operation is not implemented."); } protected override void ValidateDataSource(object dataSource) { //do nothing // throw new Exception("The method or operation is not implemented."); } } } Hope this helps. Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- | Thread-Topic: DataSourceID '<NewDataSource ...>' not working in composite <ChristophePeillet@nospam.nospam>contro | thread-index: AcYiZAY52qu3zXteSzCNkI1J2ja6Ag== | X-WBNR-Posting-Host: 193.172.19.20 | From: =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?= Show quoteHide quote | Subject: DataSourceID '<NewDataSource ...>' not working in composite microsoft.public.dotnet.framework.aspnet.webcontrols:32822contro | Date: Thu, 26 Jan 2006 02:34:02 -0800 | Lines: 38 | Message-ID: <A9B07C24-7951-4DB3-9785-547210FFE***@microsoft.com> | MIME-Version: 1.0 | Content-Type: text/plain; | charset="Utf-8" | Content-Transfer-Encoding: 7bit | X-Newsreader: Microsoft CDO for Windows 2000 | Content-Class: urn:content-classes:message | Importance: normal | Priority: normal | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quoteHide quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols [TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter| | I am trying to add databinding support to some composite controls, and have | everything working in the relevant properties (DataTextField, etc.), | including that DataSourceID properly lists all valid datasources on the page. | However, when I choose '<NewDataSource...>', the wizard doesn't fire, and | the properly value simply changes to '<NewDataSource...>'. Is there some | action I need to conduct on my part to fire the New Data Source wizard? | | The following is the code I am using for this property (which maps it to the | underlying CheckBox which does all the binding work): | | /// <summary> | /// Gets or sets the ID of the control from which the data-bound | control retrieves its list of data items. | /// </summary> | /// <value>The ID of a control that represents the data source from | which the data-bound control retrieves its data.</value> | [IDReferenceProperty(typeof(DataSourceControl))] | | ))] Show quoteHide quote | [DefaultValue((string)null)] | [Description("The ID of the control from which the data-bound | control retrieves its list of data items.")] | [Category("Data")] | public string DataSourceID | { | get | { | EnsureChildControls(); | return m_chk.DataSourceID; | } | set | { | EnsureChildControls(); | m_chk.DataSourceID = value; | } | } | | | Unfortunately, I am not able to inherit from DataBoundControl because of an
existing inheritance hierarchy I am obliged to follow. I also implement custom designers for the controls. However, your advice at least points me in the right direction. What I can do is look at the DataBounControlDesigner in Reflector, and see how I can implement the same logic myself. As always, Thanks for your help and advice. Show quoteHide quote "Steven Cheng[MSFT]" wrote: > Hi Christophe, > > Welcome to the ASP.NET newsgroup. > > It seems you're going on for your custom webcontrols :). For the > DataSourceID property, decorate them with > > [IDReferenceProperty(typeof(DataSourceControl))] > [TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter > ))] > > is not sufficient, the two attribute can only help the IDE correct manage > the value of that property or select existing datasource controls on the > webform. However, for the "Create New DataSource" wizard you mentioned, it > depend on the control's design-time ActionList feature: > > #DesignerActionList Class > http://msdn2.microsoft.com/en-us/library/system.componentmodel.design.design > eractionlist.aspx > > And for those buildin DataBound Controls, they are derived from the > DataBoundControl class which has implemented some of the designer > Actions(in the Designer) so that the child control classes and utilize. > Since our custom control doesn't derive from the base class, the "Create > New DataSource" wizard won't work.... You can consider derive your custom > control from the DataBouncControl class and implement those required > method( do not need to actually put any detailed code there......). For > example: > > namespace WebControlLib > { > [DefaultProperty("Text")] > [ToolboxData("<{0}:DSTestControl runat=server></{0}:DSTestControl>")] > //[Designer("System.Web.UI.Design.WebControls.DataBoundControlDesigner, > System.Design, Version=2.0.0.0, Culture=neutral, > PublicKeyToken=b03f5f7f11d50a3a"), > AspNetHostingPermission(SecurityAction.InheritanceDemand, > Level=AspNetHostingPermissionLevel.Minimal), > AspNetHostingPermission(SecurityAction.LinkDemand, > Level=AspNetHostingPermissionLevel.Minimal)] > public class DSTestControl : DataBoundControl, INamingContainer > { > private string _dsid; > > > [Bindable(true)] > [Category("Appearance")] > [DefaultValue("")] > [Localizable(true)] > public string Text > { > get > { > String s = (String)ViewState["Text"]; > return ((s == null) ? String.Empty : s); > } > > set > { > ViewState["Text"] = value; > } > } > > > [IDReferenceProperty(typeof(DataSourceControl))] > > [TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter > ))] > public string DataSourceID > { > get > { > //EnsureChildControls(); > //return m_chk.DataSourceID; > return _dsid; > } > set > { > //EnsureChildControls(); > //m_chk.DataSourceID = value; > _dsid = value; > } > } > > > > protected override void RenderContents(HtmlTextWriter output) > { > output.Write("<br/>DataSourceId: " + _dsid); > } > > protected override void PerformSelect() > { > //do nothing; > //throw new Exception("The method or operation is not > implemented."); > > } > > protected override void ValidateDataSource(object dataSource) > { > //do nothing > // throw new Exception("The method or operation is not > implemented."); > } > } > } > > > Hope this helps. > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > > > > > > > > -------------------- > | Thread-Topic: DataSourceID '<NewDataSource ...>' not working in composite > contro > | thread-index: AcYiZAY52qu3zXteSzCNkI1J2ja6Ag== > | X-WBNR-Posting-Host: 193.172.19.20 > | From: =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?= > <ChristophePeillet@nospam.nospam> > | Subject: DataSourceID '<NewDataSource ...>' not working in composite > contro > | Date: Thu, 26 Jan 2006 02:34:02 -0800 > | Lines: 38 > | Message-ID: <A9B07C24-7951-4DB3-9785-547210FFE***@microsoft.com> > | MIME-Version: 1.0 > | Content-Type: text/plain; > | charset="Utf-8" > | Content-Transfer-Encoding: 7bit > | X-Newsreader: Microsoft CDO for Windows 2000 > | Content-Class: urn:content-classes:message > | Importance: normal > | Priority: normal > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl > | Xref: TK2MSFTNGXA02.phx.gbl > microsoft.public.dotnet.framework.aspnet.webcontrols:32822 > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols > | > | I am trying to add databinding support to some composite controls, and > have > | everything working in the relevant properties (DataTextField, etc.), > | including that DataSourceID properly lists all valid datasources on the > page. > | However, when I choose '<NewDataSource...>', the wizard doesn't fire, > and > | the properly value simply changes to '<NewDataSource...>'. Is there some > | action I need to conduct on my part to fire the New Data Source wizard? > | > | The following is the code I am using for this property (which maps it to > the > | underlying CheckBox which does all the binding work): > | > | /// <summary> > | /// Gets or sets the ID of the control from which the data-bound > | control retrieves its list of data items. > | /// </summary> > | /// <value>The ID of a control that represents the data source > from > | which the data-bound control retrieves its data.</value> > | [IDReferenceProperty(typeof(DataSourceControl))] > | > | > [TypeConverter(typeof(System.Web.UI.Design.WebControls.DataSourceIDConverter > ))] > | [DefaultValue((string)null)] > | [Description("The ID of the control from which the data-bound > | control retrieves its list of data items.")] > | [Category("Data")] > | public string DataSourceID > | { > | get > | { > | EnsureChildControls(); > | return m_chk.DataSourceID; > | } > | set > | { > | EnsureChildControls(); > | m_chk.DataSourceID = value; > | } > | } > | > | > | > > Thank for your response Christophe,
Yes, if you do want to make those databound control specific design-time actions work, we have to lookup the code of the DataBoundcontrol and its designer. Based on my experience, it'll be a bit hard since most of them are encapsulated through complex structure and relations. Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) |
|||||||||||||||||||||||