结合MS AJAX将资源文件编译到动态链接库
2007-09-25 12:45
211 查看
一、创建类库项目LocalizingScriptResources。
二、添加System.Web 和 System.Web.Extensions命名控件引用。
三、添加一个Jscript文件。
四、将如下代码加入到js文件中:
function CheckAnswer()
{
var firstInt = $get('firstNumber').innerText;
var secondInt = $get('secondNumber').innerText;
var userAnswer = $get('userAnswer');
if (parseInt(firstInt)+parseInt(secondInt) ==userAnswer.value)
{
alert(Answer.Correct);
return true;
}
else
{
alert(Answer.Incorrect);
return false;
}
}
五、右键js文件的属性,在高级里将“生成操作”设置成“嵌入的资源”。
六、添加类ClientVerification代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Resources;
namespace LocalizingScriptResources
{
public class ClientVerification : Control
{
private Button _button;
private Label _firstLabel;
private Label _secondLabel;
private TextBox _answer;
private int _firstInt;
private int _secondInt;
protected override void CreateChildControls()
{
Random random = new Random();
_firstInt = random.Next(0, 20);
_secondInt = random.Next(0, 20);
ResourceManager rm = new ResourceManager("LocalizingScriptResources.VerificationResources", this.GetType().Assembly);
Controls.Clear();
_firstLabel = new Label();
_firstLabel.ID = "firstNumber";
_firstLabel.Text = _firstInt.ToString();
_secondLabel = new Label();
_secondLabel.ID = "secondNumber";
_secondLabel.Text = _secondInt.ToString();
_answer = new TextBox();
_answer.ID = "userAnswer";
_button = new Button();
_button.ID = "Button";
_button.Text = rm.GetString("Verify");
_button.OnClientClick = "return CheckAnswer();";
Controls.Add(_firstLabel);
Controls.Add(new LiteralControl(" + "));
Controls.Add(_secondLabel);
Controls.Add(new LiteralControl(" = "));
Controls.Add(_answer);
Controls.Add(_button);
}
}
}
上边的代码创建了一个ASP.NET控件。这个控件包含两个文本框、一个Label控件,和一个按钮。Label控件用来显示两个随机的数字,往文本框里输入这两个数字的和,点击按钮就会调用CheckAnswer函数。
七、向项目中添加一个资源文件VerificationResources.resx。
八、添加三个字符串资源,如下:
名称 值
Correct Yes, your answer is correct。
Incorrect No, your answer is incorrect。
Verify Verify Answer
二、添加System.Web 和 System.Web.Extensions命名控件引用。
三、添加一个Jscript文件。
四、将如下代码加入到js文件中:
function CheckAnswer()
{
var firstInt = $get('firstNumber').innerText;
var secondInt = $get('secondNumber').innerText;
var userAnswer = $get('userAnswer');
if (parseInt(firstInt)+parseInt(secondInt) ==userAnswer.value)
{
alert(Answer.Correct);
return true;
}
else
{
alert(Answer.Incorrect);
return false;
}
}
五、右键js文件的属性,在高级里将“生成操作”设置成“嵌入的资源”。
六、添加类ClientVerification代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Resources;
namespace LocalizingScriptResources
{
public class ClientVerification : Control
{
private Button _button;
private Label _firstLabel;
private Label _secondLabel;
private TextBox _answer;
private int _firstInt;
private int _secondInt;
protected override void CreateChildControls()
{
Random random = new Random();
_firstInt = random.Next(0, 20);
_secondInt = random.Next(0, 20);
ResourceManager rm = new ResourceManager("LocalizingScriptResources.VerificationResources", this.GetType().Assembly);
Controls.Clear();
_firstLabel = new Label();
_firstLabel.ID = "firstNumber";
_firstLabel.Text = _firstInt.ToString();
_secondLabel = new Label();
_secondLabel.ID = "secondNumber";
_secondLabel.Text = _secondInt.ToString();
_answer = new TextBox();
_answer.ID = "userAnswer";
_button = new Button();
_button.ID = "Button";
_button.Text = rm.GetString("Verify");
_button.OnClientClick = "return CheckAnswer();";
Controls.Add(_firstLabel);
Controls.Add(new LiteralControl(" + "));
Controls.Add(_secondLabel);
Controls.Add(new LiteralControl(" = "));
Controls.Add(_answer);
Controls.Add(_button);
}
}
}
上边的代码创建了一个ASP.NET控件。这个控件包含两个文本框、一个Label控件,和一个按钮。Label控件用来显示两个随机的数字,往文本框里输入这两个数字的和,点击按钮就会调用CheckAnswer函数。
七、向项目中添加一个资源文件VerificationResources.resx。
八、添加三个字符串资源,如下:
名称 值
Correct Yes, your answer is correct。
Incorrect No, your answer is incorrect。
Verify Verify Answer
相关文章推荐
- 未能加载文件或程序集或它的某一个依赖项(针对资源问题,x86文件在x64上编译失败)
- Android 4.1源码编译找不到资源文件解决办法
- 程序编译运行时头文件或动态链接库的查找
- 程序编译与运行时头文件或动态链接库的查找(二)
- 关于PHP程序使用file_get_content()函数进行抓取PHP程序与smarty结合编译过程中产生的静态文件,抓取不了?连接超时?(地址映射)
- 资源文件的操作结合反射
- SpringMVC结合ajaxfileupload.js实现文件无刷新上传
- SpringMVC结合ajaxfileupload.js实现文件无刷新上传
- 反编译Android APK 源代码和资源文件详解
- ajax上传form表单或者文件以及结合validate验证
- 编译自己的资源文件编辑器(reseditor.exe)
- 【服务端知识点】(十五天)文件上传实现——30天node+mongo+react+redux+express搭建完美资源后台管理系统+前端(全栈工程师 结合antd)
- PHP结合jQuery插件ajaxFileUpload实现异步上传文件实例
- SpringMVC结合ajaxfileupload文件无刷新上传
- php结合Ajax如何实现异步文件上传的代码实例
- winform代码反编译后图片等资源文件恢复解决方案
- django上课笔记7-jQuery Ajax 和 原生Ajax-伪造的Ajax-三种Ajax上传文件方法-JSONP和CORS跨域资源共享
- [转]ExtJs入门之filefield:文件上传的配置+结合Ajax完美实现文件上传的asp.net示例
- apk资源文件编译报”MissingTranslation“错误
- Linux下反编译APK获取java代码和资源文件