VS2010 IntelliSense inside text/x-jquery-tmpl script templates

前端 未结 5 1582
北海茫月
北海茫月 2021-01-01 14:53

I\'ve been using jQuery templates which I absolutely love to use. The only drawback from an IDE standpoint is the lack of HTML IntelliSense inside the script tag. Is there

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 15:16

    I'd solved this issue by creating simple custom serverside control (for ASP.NET 4 WebForms app.):

    [ToolboxData("<{0}:JqueryTemplate runat=server>")]
    [PersistChildren(true)]
    [ParseChildren(false)]
    public class JqueryTemplate : Control {
        private bool _useDefaultClientIdMode = true;
    
        [DefaultValue(ClientIDMode.Static)]
        [Category("Behavior")]
        [Themeable(false)]
        public override ClientIDMode ClientIDMode {
            get {
                return (_useDefaultClientIdMode) ? ClientIDMode.Static : base.ClientIDMode;
            }
            set { 
                base.ClientIDMode = value;
                _useDefaultClientIdMode = false;
            }
        }
    
        protected override void Render(HtmlTextWriter writer) {
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/x-jquery-tmpl");
            writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
            writer.RenderBeginTag(HtmlTextWriterTag.Script);
            base.Render(writer);
            writer.RenderEndTag();          
        }
    
    }
    

    and put each jquery template inside it (instead of

提交回复
热议问题