示例#1
0
		/// <summary>
		/// 使页面上指定选择器的元素成为自定义插件.
		/// </summary>
		/// <param name="selector">用于指定页面上元素的选择器.</param>
		/// <param name="setting">自定义插件设置, 比如: TimerSetting, RepeaterSetting 等.</param>
		/// <param name="variableName">如果不为空, 则生成同名的 javascript 脚本变量.</param>
		public void Plusin ( string selector, PlusinSetting setting, string variableName = null )
		{

			if ( string.IsNullOrEmpty ( selector ) )
				throw new ArgumentNullException ( "selector", "选择器不能为空" );

			if ( null == setting )
				throw new ArgumentNullException ( "setting", "Plusin 设置不能为空" );

			string key = string.Format ( "__js{0}", setting.PlusinType );

			if ( !ScriptHelper.IsBuilt ( new RazorScriptHolder ( this.page ), key ) )
			{
				ScriptHelper script = new ScriptHelper ( );

				//foreach
				//script.AppendCode ( setting.GetDependentScripts ( ) );

				script.Build ( new RazorScriptHolder ( this.page ), key, ScriptBuildOption.Startup );
			}

			this.code += "$(function(){" + ( string.IsNullOrEmpty ( variableName ) ? string.Empty : ( "window['" + variableName + "'] = " ) ) + new JQueryUI ( selector ).Plusin ( setting ).Code + "});";
		}
	protected void cmdTestAlert_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		ScriptHelper scriptHelper = new ScriptHelper ();

		result += "测试方法 ScriptHelper.Alert(string)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Alert", FunctionType.Method, new Type[] { typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "'你好1'" },
				new object[] { "'\"你好2\"'" }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.Alert(string, bool)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Alert", FunctionType.Method, new Type[] { typeof ( string ), typeof ( bool ) }, null, null, null,
			new object[][] {
				new object[] { "'你好1, 追加? true'", true },
				new object[] { "'\"你好2\", 追加? false'", false }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this );
	}
	protected void cmdNext3_Click ( object sender, EventArgs e )
	{
		// 创建 ScriptHelper 对象
		ScriptHelper scriptHelper = new ScriptHelper ();
		string name = this.txtName3.Text;

		if ( name == string.Empty )
			// 没有写用户名, 添加弹出消息框的脚本
			scriptHelper.Alert ( "'请填写用户名'" );
		else
		{
			// 隐藏第一步, 显示第二步, 记录用户名到隐藏字段
			ScriptHelper.RegisterAttribute ( this, "r1", "style.display", "none" );
			ScriptHelper.RegisterAttribute ( this, "r2", "style.display", "block" );
			ScriptHelper.RegisterHidden ( this, "r1name", name );
		}

		// 生成脚本
		scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
	}
	protected void cmdTestConfirm_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		ScriptHelper scriptHelper = new ScriptHelper ();

		result += "测试方法 ScriptHelper.Confirm(string)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Confirm", FunctionType.Method, new Type[] { typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "'确定1?'" },
				new object[] { "'\"确定2?\"'" }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.Confirm(string, string)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Confirm", FunctionType.Method, new Type[] { typeof ( string ), typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "'确定? 返回结果到变量 c1'", "c1" },
				new object[] { "'确定? 但没有返回到变量'", null }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.Confirm(string, bool)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Confirm", FunctionType.Method, new Type[] { typeof ( string ), typeof ( bool ) }, null, null, null,
			new object[][] {
				new object[] { "'确定1? 追加? true'", true },
				new object[] { "'\"确定2?\", 追加? false'", false }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.Confirm(string, string, bool)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Confirm", FunctionType.Method, new Type[] { typeof ( string ), typeof ( string ), typeof ( bool ) }, null, null, null,
			new object[][] {
				new object[] { "'确定? 返回结果到变量 c1, 追加? true'", "c1", true },
				new object[] { "'确定? 但没有返回到变量, 追加? false'", null, false }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this );
	}
	protected void cmdRun2_Click ( object sender, EventArgs e )
	{
		// 创建 ScriptHelper 对象
		ScriptHelper scriptHelper = new ScriptHelper ();
		string code = this.txtCode2.Text;

		if ( code == string.Empty )
		{
			// 没有脚本, 添加弹出消息框的脚本
			scriptHelper.Alert ( "'没有任何脚本'" );
			scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
			return;
		}

		ScriptHelper.RegisterAttribute ( this, this.lblCode2.ClientID, "innerText", code );
		scriptHelper.AppendCode ( code );

		// 生成脚本到页面
		scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
	}
	protected void cmdAdd1_Click ( object sender, EventArgs e )
	{
		// 创建 ScriptHelper 对象
		ScriptHelper scriptHelper = new ScriptHelper ();
		string name = this.txtName1.Text;
		string ageString = this.txtAge1.Text;

		bool isInfoValid = true;

		int age = 0;

		if ( name == string.Empty )
		{
			// 没有写姓名, 添加弹出消息框的脚本
			scriptHelper.Alert ( "'请填写姓名'" );
			isInfoValid = false;
		}
		else if ( name.Length < 2 || name.Length > 4 )
		{
			// 姓名格式错误, 添加弹出消息框的脚本
			scriptHelper.Alert ( "'姓名应有 2 到 4 个字'" );
			isInfoValid = false;
		}
		else if ( !int.TryParse ( ageString, out age ) )
		{
			// 年龄格式错误, 添加弹出消息框的脚本
			scriptHelper.Alert ( "'年龄应该是数字'" );
			isInfoValid = false;
		}

		if ( !isInfoValid )
		{
			// 因为存在错误, 生成脚本到页面并返回
			scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
			return;
		}

		int result = 0;
		// 在这里将数据提交到数据库, 并将下面的语句去掉
		result = new Random ().Next ( 0, 2 );

		switch ( result )
		{
			case 0:
				// 添加成功, 添加显示成功消息的脚本
				scriptHelper.Alert ( "'添加成功'" );
				// 设置页面的标签 span1 为绿色并显示姓名和年龄
				ScriptHelper.RegisterAttribute ( this, "span1", "innerHTML", string.Format ( "被添加内容: {0}, {1}", name, age ) );
				ScriptHelper.RegisterAttribute ( this, "span1", "style.color", "#00ff00" );
				break;

			case 1:
				// 添加失败, 添加显示失败消息的脚本
				scriptHelper.Alert ( "'添加失败'" );
				// 设置页面的标签 span1 为红色并显示姓名和年龄
				ScriptHelper.RegisterAttribute ( this, "span1", "innerHTML", string.Format ( "被添加内容: {0}, {1}", name, age ) );
				ScriptHelper.RegisterAttribute ( this, "span1", "style.color", "#ff0000" );
				break;
		}

		// 生成脚本到页面
		scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
	}
	protected void cmdTestClearTimeout_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		ScriptHelper scriptHelper = new ScriptHelper ();

		result += "测试方法 ScriptHelper.ClearTimeout(string)<br />";

		scriptHelper.SetInterval ( "'alert(\"句柄 timer1\");'", 5000, "timer1" );

		foreach ( object code in tracer.Execute ( scriptHelper, null, "ClearTimeout", FunctionType.Method, new Type[] { typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "timer1" },
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.ClearTimeout(string, bool)<br />";

		scriptHelper.SetInterval ( "'alert(\"句柄 timer2\");'", 5000, "timer2" );

		foreach ( object code in tracer.Execute ( scriptHelper, null, "ClearTimeout", FunctionType.Method, new Type[] { typeof ( string ), typeof ( bool ) }, null, null, null,
			new object[][] {
				new object[] { "timer2", false }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this );
	}
	protected void cmdTestSetTimeout_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		ScriptHelper scriptHelper = new ScriptHelper ();

		result += "测试方法 ScriptHelper.SetTimeout(string, int)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "SetTimeout", FunctionType.Method, new Type[] { typeof ( string ), typeof ( int ) }, null, null, null,
			new object[][] {
				new object[] { "'alert(\"hello, 5 秒钟触发\")'", 5000 },
				new object[] { "function(){alert('函数方式触发, 5 秒钟触发');}", 5000 }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.SetTimeout(string, int, string)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "SetTimeout", FunctionType.Method, new Type[] { typeof ( string ), typeof ( int ), typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "'alert(\"hello, 20 秒钟触发, 句柄保存到 timer1\")'", 20000, "timer1" },
				new object[] { "function(){alert('函数方式触发, 20 秒钟触发, 句柄保存到 timer2');}", 20000, "timer2" }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.SetTimeout(string, int, bool)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "SetTimeout", FunctionType.Method, new Type[] { typeof ( string ), typeof ( int ), typeof ( bool ) }, null, null, null,
			new object[][] {
				new object[] { "'alert(\"hello, 5 秒钟触发, 不追加\")'", 5000, false },
				new object[] { "function(){alert('函数方式触发, 5 秒钟触发, 不追加');}", 5000, false }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.SetTimeout(string, int, string, bool)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "SetTimeout", FunctionType.Method, new Type[] { typeof ( string ), typeof ( int ), typeof ( string ), typeof ( bool ) }, null, null, null,
			new object[][] {
				new object[] { "'alert(\"hello, 20 秒钟触发, 句柄保存到 timer1, 不追加\")'", 20000, "timer1", false },
				new object[] { "function(){alert('函数方式触发, 20 秒钟触发, 句柄保存到 timer2, 不追加');}", 20000, "timer2", false }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this );
	}
示例#9
0
	protected void cmdTestVal_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		JQuery jQuery1 = new JQuery ( "'#myTextBox1'" );
		JQuery jQuery2 = new JQuery ( jQuery1 );

		result += "测试方法 JQuery.Val()<br />";

		tracer.Execute ( jQuery1, null, "Val", FunctionType.Method, new Type[] { }, null, null, null,
			new object[][] {
				new object[] { }
			},
			false
			);

		result += "jQuery1.Code = " + jQuery1.Code + "<br />";

		result += "测试方法 JQuery.Val(string)<br />";

		tracer.Execute ( jQuery2, null, "Val", FunctionType.Method, new Type[] { typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "'jack'" }
			},
			false
			);

		result += "jQuery2.Code = " + jQuery2.Code + "<br />";

		ScriptHelper scriptHelper = new ScriptHelper ();
		scriptHelper.Alert ( "'myTextBox1.value = ' + " + jQuery1.Code );

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
		jQuery2.Build ( this, option: ScriptBuildOption.Startup );
	}
	protected void cmdTestClear_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		ScriptHelper scriptHelper = new ScriptHelper ();

		result += "测试方法 ScriptHelper.Clear(string)<br />";

		scriptHelper.Confirm ( "'有名字?'", "n" );
		scriptHelper.Alert ( "'一句话'" );

		tracer.Execute ( scriptHelper, null, "Clear", FunctionType.Method, null, null, null, null,
			new object[][] {
				new object[] { }
			},
			false
			);

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this );
	}
	protected void cmdTestAppendScript_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		ScriptHelper scriptHelper = new ScriptHelper ();

		result += "测试方法 ScriptHelper.AppendScript(string)<br />";

		scriptHelper.Confirm ( "'有名字?'", "n" );

		tracer.Execute ( scriptHelper, null, "AppendScript", FunctionType.Method, new Type[] { typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "if(n){n = '有名字';}else{n = '没有名字';}" }
			},
			false
			);

		scriptHelper.Alert ( "'名字? ' + n" );

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this );
	}
	protected void cmdTestNavigate_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		ScriptHelper scriptHelper = new ScriptHelper ();

		/*
		result += "测试方法 ScriptHelper.Navigate(string)<br />";

		tracer.Execute ( scriptHelper, null, "Navigate", FunctionType.Method, new Type[] { typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "'http://www.google.com/'" }
			},
			false
			);
		*/

		result += "测试方法 ScriptHelper.Navigate(string, NavigateOption)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Navigate", FunctionType.Method, new Type[] { typeof ( string ), typeof ( NavigateOption ) }, null, null, null,
			new object[][] {
				new object[] { "'http://www.google.com/'", NavigateOption.NewWindow },
				new object[] { "'http://www.google.com/'", NavigateOption.SelfWindow }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "测试方法 ScriptHelper.Navigate(string, NavigateOption, bool)<br />";

		foreach ( object code in tracer.Execute ( scriptHelper, null, "Navigate", FunctionType.Method, new Type[] { typeof ( string ), typeof ( NavigateOption ), typeof ( bool ) }, null, null, null,
			new object[][] {
				new object[] { "'http://www.google.com/'", NavigateOption.NewWindow, true },
				new object[] { "'http://www.google.com/'", NavigateOption.SelfWindow, false }
			},
			false
			)
			)
			result += "返回: " + code.ToString () + "<br />";

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this );
	}
示例#13
0
		/// <summary>
		/// 将目前所有的脚本输出.
		/// </summary>
		/// <param name="key">脚本块的关键字.</param>
		public void WriteScript ( string key = null )
		{

			if ( this.code == string.Empty )
				return;

			ScriptHelper script = new ScriptHelper ( );
			script.AppendCode ( this.code );
			script.Build ( new RazorScriptHolder ( this.page ), key );
			this.code = string.Empty;
		}
示例#14
0
	protected void cmdTestIs_Click ( object sender, EventArgs e )
	{
		string result = string.Empty;
		Tracer tracer = new Tracer ();

		JQuery jQuery = new JQuery ( "'li'" );

		result += "测试方法 JQuery.Is(string)<br />";

		tracer.Execute ( jQuery, null, "Is", FunctionType.Method, new Type[] { typeof ( string ) }, null, null, null,
			new object[][] {
				new object[] { "'.happy'" }
			},
			false
			);

		result += "jQuery.Code = " + jQuery.Code + "<br />";

		ScriptHelper scriptHelper = new ScriptHelper ();
		scriptHelper.Alert ( "'li is(.happay) = ' + " + jQuery.Code );

		result += "scriptHelper.Code = " + scriptHelper.Code + "<br />";

		this.lblResult.Text = result;

		scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
	}
	protected void cmdOK3_Click ( object sender, EventArgs e )
	{
		// 创建 ScriptHelper 对象
		ScriptHelper scriptHelper = new ScriptHelper ();
		string password = this.txtPassword3.Text;

		// 隐藏第一步, 设置记录的用户名到隐藏字段
		ScriptHelper.RegisterAttribute ( this, "r1", "style.display", "none" );
		ScriptHelper.RegisterHidden ( this, "r1name", this.Request["r1name"] );

		if ( password == string.Empty )
		{
			// 没有写密码, 添加弹出消息框的脚本, 并显示第二步
			scriptHelper.Alert ( "'请填写密码'" );
			ScriptHelper.RegisterAttribute ( this, "r2", "style.display", "block" );
		}
		else
		{
			// 显示注册结果
			ScriptHelper.RegisterAttribute ( this, "r3", "style.display", "block" );
			ScriptHelper.RegisterAttribute ( this, "rr1", "innerText", string.Format ( "用户名: {0}, 密码: {1}", this.Request["r1name"], password ) );
		}

		// 生成脚本
		scriptHelper.Build ( this, option: ScriptBuildOption.Startup );
	}
	protected void cmdOK4_Click ( object sender, EventArgs e )
	{
		// 创建 ScriptHelper 对象
		ScriptHelper scriptHelper = new ScriptHelper ();

		// 声明用于存储颜色值得数组
		ScriptHelper.RegisterArray ( this, "colors", "10, 99, 10" );

		// 添加可以得到不同颜色的函数
		scriptHelper.AppendCode ( "function GetNextColor(){colors[0]++;colors[1]--;colors[2]+=2;if(colors[0]>99){colors[0]=10;}if(colors[1]<10){colors[1]=99;}if(colors[2]>99){colors[2]=10;}return '#' + colors[0].toString() + colors[1].toString() + colors[2].toString(); }" );

		// 设置时钟, 改变标签的颜色
		scriptHelper.SetInterval ( "function(){document.getElementById('span4').style.color = GetNextColor();}", 100 );

		// 生成脚本
		scriptHelper.Build ( this, option:ScriptBuildOption.Startup );
	}
示例#17
0
		protected override void Render ( HtmlTextWriter writer )
		{

			if ( !this.Visible )
				return;

			if ( this.isFaceless ( ) )
				writer.Write ( "<span style=\"font-family: Verdana; background-color: #FFFFFF; font-size: 10pt;\"><strong>{0}:</strong> {1}</span>", "AjaxManager", this.ID );

			if ( this.DesignMode )
				return;

			ScriptHelper script = new ScriptHelper ( );

			//!+ The following code is similar with AutocompleteSetting.Recombine, WidgetSetting.Recombine

			foreach ( AjaxSetting ajax in this.ajaxs )
				if ( !string.IsNullOrEmpty ( ajax.ClientFunction ) )
				{
					string data;

					if ( string.IsNullOrEmpty ( ajax.MethodName ) )
						data = "data";
					else
						// According to the .NET version to determine the location of JSON
						if ( Environment.Version.Major <= 2 || ( Environment.Version.Major == 3 && Environment.Version.Minor == 0 ) )
							data = "data";
						else
							data = "data.d";

					if ( !string.IsNullOrEmpty ( ajax.Success ) )
						ajax.Success = ajax.Success.Replace ( "-:data", data );

					if ( !string.IsNullOrEmpty ( ajax.Complete ) )
						ajax.Complete = ajax.Complete.Replace ( "-:data", data );

					if ( !string.IsNullOrEmpty ( ajax.Error ) )
						ajax.Error = ajax.Error.Replace ( "-:data", data );

					JQuery jquery = JQueryUI.Create ( ajax );

					if(null != jquery)
						script.AppendCode ( "function " + ajax.ClientFunction + "(" + ajax.ClientParameter + ") {" + jquery.Code + "}" );

				}

			script.Build ( new ASPXScriptHolder ( this ), this.ClientID, ScriptBuildOption.Startup );
		}