c#和javascript交互
在asp.net開發中,經常會用到後台和前台的交互,就此總結了一點c#和javascript相互操作的方法
1.在後台c#代碼中調用jacascript的方法
javascript代碼:
<script type="text/javascript" language="javascript">
function test()
{
alert("oec2003");
return false;
}
</script>
c#代碼:
protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "clear", "<script>test()</script>");
}
2.javascript中調用c#方法
如果c#中的方法有返回值,可以用下面方法
c#代碼
public string GetAuthStatus()
{
ViewState["Auth"] = "Red";
return ViewState["Auth"].ToString();
}
javascript代碼
function getAuth()
{
var authStatus="<%=GetAuthStatus()%>";
return authStatus;
}
如果在javascript調用的c#方法沒有返回值,可以在一面中放一個button,然後在button的單擊事件中去寫想做的事情,在客戶端的腳本中寫下如下代碼就可以了
document.all("button1").click();
相关文档:
7、dojo.js的写类方式
dojo最新是1.3.1了,记得07年时还是0.4。文档也渐渐多了起来,用dojo的也慢慢多了。dojo还发布了core版,压缩后只有
27kb。dojo中用dojo.declare方法来定义一个类。dojo.declare的源码就不贴在这里了。dojo.declare有三个参
数,
参数1:类名className
参数2:继承的类superclass
参数3:构造器 ......
首先是十个JS FRAMEWORK
jquery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
jquery UI
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
Chrome Frame
<script src=& ......
1.javascript与Html中的调用问题。
在javascript中要想更改html中的一些属性值,特别是在页面内容较多时,务必使用document.getElementById(id)的方式进行,否则javascript将不能更改属性!
2.Date类。
在Date类中的getMonth()等方法返回值为number。因此可以使用数组存储月份信息如month=[“1月”,&ldq ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; //引用命名空间
namespace DAL
{
/*******************************************************************************
&n ......