I know this question has been asked before and I've read several responses that I am not satisfied with. Nevertheless, my question is how do you create a custom web control with intellisense support in html view? I've read the standard response of creating
an .XSD file with the intellisense definitions and referencing the schema in the <body> tag of the html page but that can't be the only way.
I've downloaded several third party controls that have full intellisense support in html view and I've never had to reference some .XSD file in my <body> tag(s). Most recently I've searched through all of the source code for the Ajax Control Toolkit and
I haven't found any .XSD files nor have I found any code explicity enabling html intellisense (I also don't know what I'm looking for) so I'm really pretty confused about the whole topic.
I'm hoping that someone can disclose the secrets that nobody else seems to know [:)].
Sounds like when you use the register directive in your aspx (which is the standard for commercial controls and such), the XSD is generated on the -fly-, as opposed to having to manually author it, from attributes coming from your code behind...sounds about
right to me.
Thank you for your reply, but I can't seem to pull up the URL you supplied; I can't even pull up the domain so I'll try later in the event there's a dns error or something like that.
Anyway, I have read something like that before, that using the register directive will expose attributes to html intellisense but I've never consistently gotten it to work. Also, I like to register my controls in the Web.config file so I don't have duplicate
register directives across my .aspx pages. Again, this works for third party/commercial controls but not for my own custom controls.
The only control I "successfully" exposed to intellisense in the html view was derived from a HyperLink control. I say "successfully" because I didn't actually do anything, it just worked. However, when I created a custom Parameter to use with an ObjectDataSource,
no intellisense support regardless of registration through a page directive or the Web.config file.
This is really driving me crazy. I need a master control author to explain the mystery of html intellisense support!
In the web.config or the register directive, its the same really. Sorry for the confusion. And indeed, the URL doesn't work anymore. It worked when I supplied the link, hrmp. Ill be looking for a similar link. Anyway, what that page explained was how there
are attributes you add on top of your methods, and the intellisense gets generated from those. Maybe if you look in the source of the ajax controls you'll see them, now that at least you know what you're looking for. If I find something first, ill post it.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Security.Permissions;
namespace Phoenix.TestControl
{
/// <summary>
/// Summary description for ServerControl
/// </summary>
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("XProperty"), ToolboxData("<{0}:ServerControl runat=\"server\"> </{0}:ServerControl>")]
public class ServerControl : WebControl
{
private string _xProperty;
[
Bindable(true),
Category("DemoProperties"),
DefaultValue(""),
Description("Property to test intellisense"),
Localizable(true)
]
public virtual string XProperty
{
get { return _xProperty; }
set { _xProperty = value; }
}
protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write(this._xProperty);
}
}
}
Now when I register the control in my page (didn't test the web config, but I'm 99% sure it will work, since its the same thing), intellisense works fine, and XProperty shows up when adding that control while in HTML view.
It is the code inserted automatically during creation of custom webcontrol in VS2005:
RightClick in Server Explorer on project of of Library Type ---> Add...--->Component ----> Web Custom Control --> Add ---> OK
You cannot miss it if you ever created even once custom webcontrols as well as miss the intellisense appearing without any further effort.
Or you could not miss it copypasting any code examples
I wanted to write it but then became perplexed by complexities being discussied (.XSD, etc., references, etc.)</div>
Gennady Vanin (Novosibirsk) -- Геннадий Ванин (Новосибирск) -- Guennadi Vanine
I played around with the example that you gave and indeed I had intellisense in html view.
However, as soon as I tried to recreate my control (the original source is at work), intellisense was lost.
The only difference between my control and the posted example (I was already aware of adding the various attributes to my class and properties and thus had already done so) is that my control extends System.Web.UI.WebControls.Parameter and not System.Web.UI.WebControls.WebControl.
As soon as I switched to the latter, I had intellisense support.
So am I to believe that the secret of html view intellisense lies in the extended class? I don't understand why when extending Control, WebControl or even ObjectDataSource (I tried some other arbitrary class just to see what would happen) I get full intellisense
support in html view but not when I extend Parameter?
The whole thing makes no sense... it's horse caca!
Probably because they expected Parameter to be part of a Server control, not a server control of its own. All the other classes you mention all inherit from Control at one point or another in the hierarchy, Parameter inherits directly from Object instead, so
its lacking the intellisense features of (I suppose)
System.Web.UI.Control that WebControl and ObjectDataSource inherit.
Again, this goes back to my original question, what are those "intellisense features" that seem to be included in Control and WebControl? What was added to Control and WebControl that exposes intellisense to the html view?
I don't know why this is so important to me but it is?!
Empirically I determined that implementation of IAttributeAccessor is responsible for Intellisense. There is no Intellisense in webcontrols derived from Control but those derived from WebControl already have it. WebControl implements Control and realizes IAttributeAccessor
In order to compile I had to add to Control-derived custom class just copied, without tunderstanding what they are doing, from msdn public class ServerControl : Control, IAttributeAccessor { public String GetAttribute(String name) { // return "xxxxxxxxx";
return (String)ViewState[name]; } public void SetAttribute(String name, String value1) { ViewState[name] = value1; } Might be I am wrong
Gennady Vanin (Novosibirsk) -- Геннадий Ванин (Новосибирск) -- Guennadi Vanine
kenniejaydav...
Member
25 Points
24 Posts
intellisense in html view
Feb 16, 2007 09:07 PM|LINK
I know this question has been asked before and I've read several responses that I am not satisfied with. Nevertheless, my question is how do you create a custom web control with intellisense support in html view? I've read the standard response of creating an .XSD file with the intellisense definitions and referencing the schema in the <body> tag of the html page but that can't be the only way.
I've downloaded several third party controls that have full intellisense support in html view and I've never had to reference some .XSD file in my <body> tag(s). Most recently I've searched through all of the source code for the Ajax Control Toolkit and I haven't found any .XSD files nor have I found any code explicity enabling html intellisense (I also don't know what I'm looking for) so I'm really pretty confused about the whole topic.
I'm hoping that someone can disclose the secrets that nobody else seems to know [:)].
shados
Star
12285 Points
2229 Posts
Re: intellisense in html view
Feb 17, 2007 12:07 AM|LINK
I didnt actually try it, but this seems to be exactly what you want...seems like manually authoring the XSD is semi-obsolete...
http://www.nikhilk.net/MetadataBasedIntellisense.aspx
Sounds like when you use the register directive in your aspx (which is the standard for commercial controls and such), the XSD is generated on the -fly-, as opposed to having to manually author it, from attributes coming from your code behind...sounds about right to me.
kenniejaydav...
Member
25 Points
24 Posts
Re: intellisense in html view
Feb 17, 2007 06:04 PM|LINK
Thank you for your reply, but I can't seem to pull up the URL you supplied; I can't even pull up the domain so I'll try later in the event there's a dns error or something like that.
Anyway, I have read something like that before, that using the register directive will expose attributes to html intellisense but I've never consistently gotten it to work. Also, I like to register my controls in the Web.config file so I don't have duplicate register directives across my .aspx pages. Again, this works for third party/commercial controls but not for my own custom controls.
The only control I "successfully" exposed to intellisense in the html view was derived from a HyperLink control. I say "successfully" because I didn't actually do anything, it just worked. However, when I created a custom Parameter to use with an ObjectDataSource, no intellisense support regardless of registration through a page directive or the Web.config file.
This is really driving me crazy. I need a master control author to explain the mystery of html intellisense support!
shados
Star
12285 Points
2229 Posts
Re: intellisense in html view
Feb 17, 2007 06:11 PM|LINK
shados
Star
12285 Points
2229 Posts
Re: intellisense in html view
Feb 17, 2007 06:43 PM|LINK
Okie, I tested this and it worked:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.ComponentModel; using System.Security.Permissions; namespace Phoenix.TestControl { /// <summary> /// Summary description for ServerControl /// </summary> [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), DefaultProperty("XProperty"), ToolboxData("<{0}:ServerControl runat=\"server\"> </{0}:ServerControl>")] public class ServerControl : WebControl { private string _xProperty; [ Bindable(true), Category("DemoProperties"), DefaultValue(""), Description("Property to test intellisense"), Localizable(true) ] public virtual string XProperty { get { return _xProperty; } set { _xProperty = value; } } protected override void RenderContents(HtmlTextWriter writer) { writer.Write(this._xProperty); } } }Now when I register the control in my page (didn't test the web config, but I'm 99% sure it will work, since its the same thing), intellisense works fine, and XProperty shows up when adding that control while in HTML view.
guenavan
Contributor
4306 Points
1695 Posts
Re: intellisense in html view
Feb 18, 2007 12:26 AM|LINK
It is the code inserted automatically during creation of custom webcontrol in VS2005:
RightClick in Server Explorer on project of of Library Type ---> Add...--->Component ----> Web Custom Control --> Add ---> OK
You cannot miss it if you ever created even once custom webcontrols as well as miss the intellisense appearing without any further effort.
Or you could not miss it copypasting any code examples
I wanted to write it but then became perplexed by complexities being discussied (.XSD, etc., references, etc.)</div>
kenniejaydav...
Member
25 Points
24 Posts
Re: intellisense in html view
Feb 18, 2007 04:31 AM|LINK
I played around with the example that you gave and indeed I had intellisense in html view.
However, as soon as I tried to recreate my control (the original source is at work), intellisense was lost.
The only difference between my control and the posted example (I was already aware of adding the various attributes to my class and properties and thus had already done so) is that my control extends System.Web.UI.WebControls.Parameter and not System.Web.UI.WebControls.WebControl. As soon as I switched to the latter, I had intellisense support.
So am I to believe that the secret of html view intellisense lies in the extended class? I don't understand why when extending Control, WebControl or even ObjectDataSource (I tried some other arbitrary class just to see what would happen) I get full intellisense support in html view but not when I extend Parameter?
The whole thing makes no sense... it's horse caca!
shados
Star
12285 Points
2229 Posts
Re: intellisense in html view
Feb 18, 2007 05:36 AM|LINK
kenniejaydav...
Member
25 Points
24 Posts
Re: intellisense in html view
Feb 18, 2007 06:32 AM|LINK
Again, this goes back to my original question, what are those "intellisense features" that seem to be included in Control and WebControl? What was added to Control and WebControl that exposes intellisense to the html view?
I don't know why this is so important to me but it is?!
guenavan
Contributor
4306 Points
1695 Posts
Re: intellisense in html view
Feb 18, 2007 09:03 AM|LINK