webControl 中使用资源 与嵌入资源
来源:互联网 发布:bring with it的it 编辑:程序博客网 时间:2024/05/10 03:46
不废话了.打开VS2005 新建一个解决方案 驗證控件
1 新建一个类库
2 把class.cs改名为 "使用资源读取,输出等.cs"
3,添加资源
3.1 选择 "属性"
添加完成後如下圖
在 輸入代碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Resources;
using System.Web.UI.WebControls;
[assembly: WebResource("FormValidation.Validation.xml", "text/xml")]
[assembly: WebResource("FormValidation.Sunset.jpg", "Image/jpg")]
/**//*
* [assembly: WebResource("WebCtrl.cutecat.jpg", "image/jpg")]
* 我们可以看msdn里有WebResource的参数说明:第一个是资源的名字,第二个是资源的mime-type名。
该技术是通过在控件代码里调用GetWebResourceUrl方法,这个方法指向一个名为WebResource.axd的内置HTTP处理程序的URL。通过加载一个名为AssemblyResourceLoader的HttpHandler类,ASP.NET运行时响应WebResource.axd的请求,返回指定资源的URL。
然后在程序中调用如下:
* m_Image.ImageUrl = this.Page.GetWebResourceUrl(typeof(WebCustom), "WebCtrl.cutecat.jpg");
*/
namespace FormValidation
...{
[DefaultProperty("Text")]
[ToolboxData("<{0}:FormValidationVer3 runat=server></{0}:FormValidationVer3>")]
public class FormValidation : WebControl
...{
// private System.Resources.ResourceManager rm; //新建一个资源管理
[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;
}
}
protected override void RenderContents(HtmlTextWriter output)
...{
ResourceManager R资源管理 = new ResourceManager("驗證控件.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
String script = R资源管理.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).GetString("Validation");//得到字符串
output.Write(script);
// System.Drawing.Image img = R资源管理.GetObject("Sunset");
string ss = R资源管理.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).GetString("HTMLPage1");
/**/////////////////
string xmlurl = Page.ClientScript.GetWebResourceUrl(GetType(), "Validation.xml");
//output.Write(R资源管理.GetObject("FormValidation.Validation.xml"));
string url = Page.ClientScript.GetWebResourceUrl(GetType(), "Sunset.jpg");
output.Write("<img src="" + url+"" />");
output.Write(xmlurl);//动态生成WebResource
output.Write(ss);//输出文本文件
output.Write(Text);
}
/**//// <summary>
/// 重写 OnPreRender 方法。 输出一回 脚本 东东
/// </summary>
/// <param name="e">包含事件数据的 EventArgs 对象。</param>
protected override void OnPreRender(EventArgs e)//注册脚本的操作
...{
string str = "<script language="javascript" type="text/javascript">function bb(){alert('我是AA如果注册了 只会出一个AA 不是就出错哒 "+Page.Form.Name+"');} </script>";
ClientScriptManager aa = Page.ClientScript;
if (!aa.IsClientScriptBlockRegistered("aa"))//看看这个关键字的脚本是不是已经注册了
...{
aa.RegisterClientScriptBlock(this.GetType(), "aa", str);//最简单的一种注册方式
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Resources;
using System.Web.UI.WebControls;
[assembly: WebResource("FormValidation.Validation.xml", "text/xml")]
[assembly: WebResource("FormValidation.Sunset.jpg", "Image/jpg")]
/**//*
* [assembly: WebResource("WebCtrl.cutecat.jpg", "image/jpg")]
* 我们可以看msdn里有WebResource的参数说明:第一个是资源的名字,第二个是资源的mime-type名。
该技术是通过在控件代码里调用GetWebResourceUrl方法,这个方法指向一个名为WebResource.axd的内置HTTP处理程序的URL。通过加载一个名为AssemblyResourceLoader的HttpHandler类,ASP.NET运行时响应WebResource.axd的请求,返回指定资源的URL。
然后在程序中调用如下:
* m_Image.ImageUrl = this.Page.GetWebResourceUrl(typeof(WebCustom), "WebCtrl.cutecat.jpg");
*/
namespace FormValidation
...{
[DefaultProperty("Text")]
[ToolboxData("<{0}:FormValidationVer3 runat=server></{0}:FormValidationVer3>")]
public class FormValidation : WebControl
...{
// private System.Resources.ResourceManager rm; //新建一个资源管理
[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;
}
}
protected override void RenderContents(HtmlTextWriter output)
...{
ResourceManager R资源管理 = new ResourceManager("驗證控件.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
String script = R资源管理.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).GetString("Validation");//得到字符串
output.Write(script);
// System.Drawing.Image img = R资源管理.GetObject("Sunset");
string ss = R资源管理.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).GetString("HTMLPage1");
/**/////////////////
string xmlurl = Page.ClientScript.GetWebResourceUrl(GetType(), "Validation.xml");
//output.Write(R资源管理.GetObject("FormValidation.Validation.xml"));
string url = Page.ClientScript.GetWebResourceUrl(GetType(), "Sunset.jpg");
output.Write("<img src="" + url+"" />");
output.Write(xmlurl);//动态生成WebResource
output.Write(ss);//输出文本文件
output.Write(Text);
}
/**//// <summary>
/// 重写 OnPreRender 方法。 输出一回 脚本 东东
/// </summary>
/// <param name="e">包含事件数据的 EventArgs 对象。</param>
protected override void OnPreRender(EventArgs e)//注册脚本的操作
...{
string str = "<script language="javascript" type="text/javascript">function bb(){alert('我是AA如果注册了 只会出一个AA 不是就出错哒 "+Page.Form.Name+"');} </script>";
ClientScriptManager aa = Page.ClientScript;
if (!aa.IsClientScriptBlockRegistered("aa"))//看看这个关键字的脚本是不是已经注册了
...{
aa.RegisterClientScriptBlock(this.GetType(), "aa", str);//最简单的一种注册方式
}
}
}
}
- webControl 中使用资源 与嵌入资源
- dotnet中使用嵌入资源
- dotnet中使用嵌入资源
- dotnet中使用嵌入资源
- WebControl 资源文件 MineType
- C#中使用嵌入资源的图像
- 在.net中使用嵌入的资源
- flex中使用Embed方式嵌入资源
- .NET中使用嵌入的资源
- C#中使用嵌入的资源
- C#中使用WebBrowser显示嵌入资源
- flex中使用Embed方式嵌入资源
- 内容与嵌入资源
- 控件中嵌入资源
- PyQt中嵌入图片资源
- winform 嵌入资源读取使用
- 使用SWFObject嵌入Flash资源
- 嵌入资源
- ASP.NET技术的学习顺序问题
- 指针指向常量的结果!
- 2007透明加密一览(3)-选择透明加密产品的方法以及市场准入条件
- 如何编写一个shell脚本
- ADO.NET入门
- webControl 中使用资源 与嵌入资源
- ZT+YC 算法经典解释
- 在 ADO.NET 数据集中浏览多个相关表
- 如何能得到快乐
- 2007透明加密一览(4)-撰写中
- 游戏的精髓
- 2007-6-15
- 2007-6-16
- 2007-6-17