利用WebResource.axd通过一个URL来访问装配件的内置资源

一:使用js 

Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI;

[assembly: WebResource(
"Controls.TextEditor.Resources.jVal.js", "text/javascript")]
[assembly: WebResource(
"Controls.TextEditor.Resources.TextEditor.js", "text/javascript")]

namespace Elane.Controls
{
[ToolboxData(
@"<{0}:TextEditor runat='server'></{0}:TextEditor>")]
public class TextEditor : TextBox
{
private TextDataType FDataType;
/// <summary>
/// 数据类型
/// </summary>
[Browsable(true)]
[Description(
"DataType")]
[Category(
"Elane")]
[DefaultValue(
0)]
public virtual TextDataType DataType
{
get { return FDataType; }
set { FDataType = value; }
}

private int FMaxLength;
/// <summary>
/// 最大长度
/// </summary>
[Browsable(true)]
[Description(
"MaxLength")]
[Category(
"Elane")]
[DefaultValue(
0)]
public virtual int MaxLengths
{
get { return FMaxLength; }
set { FMaxLength = value; }
}

private int FMinLength;
/// <summary>
/// 最大长度
/// </summary>
[Browsable(true)]
[Description(
"MinLength")]
[Category(
"Elane")]
[DefaultValue(
0)]
public virtual int MinLengths
{
get { return FMinLength; }
set { FMinLength = value; }
}

private bool FIsRequired;
/// <summary>
/// 是否必填
/// </summary>
[Browsable(true)]
[Description(
"是否必填")]
[Category(
"Elane")]
[DefaultValue(
false)]
public virtual bool IsRequired
{
get { return FIsRequired; }
set { FIsRequired = value; }
}

/// <summary>
/// 重写text
/// </summary>
public override string Text
{
get { return base.Text.Trim(); }
set { base.Text = value; }
}

protected override void AddAttributesToRender(HtmlTextWriter writer)
{
this.Attributes.Add("onclick", "testTextEditor();");
base.AddAttributesToRender(writer);
}

protected override void OnPreRender(EventArgs e)
{
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(this.GetType(), "TextEditorLibrayJs"))
{
this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "TextEditorLibrayJs", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "Controls.TextEditor.Resources.jVal.js"));
}

if (!this.Page.ClientScript.IsClientScriptIncludeRegistered(this.GetType(), "TextEditorJs"))
{
this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "TextEditorJs", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "Controls.TextEditor.Resources.TextEditor.js"));
}
}
}
}

 

 设置资源的属性:生成操作=嵌入的资源; 

 

 引入资源时的路径:Controls.TextEditor.Resources.TextEditor.js 而不是Elane.Controls.TextEditor.Resources.TextEditor.js

  文档上说是根命名空间加资源的路径,但我使用Elane.Controls.TextEditor.Resources.TextEditor.js却不行,锤子。

转载于:https://www.cnblogs.com/guatai/articles/1337114.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值