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();
相关文档:
这篇开始会分析流行的js库之写类方式。各种库的写类方式虽然千奇百怪,但仍然逃离不了本质---用构造函数和原型
来组装类。
6、Prototype.js的写类方式
//prototype.js中的代码
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
//简化 ......
9、YUI的写类方式
这里引入的是YUI 2.7.0版,只需引入yahoo.js。YUI引入了命名空间,类似于java的包。以下yahoo的工具函数包
YAHOO.namespace
YAHOO.lang
YAHOO.lang.hasOwnProperty
YAHOO.lang.extend
YAHOO.lang.augment
YAHOO.log
YAHOO_config and YAHOO.env
YUI Module Names
写类方式:
//定义包� ......
Do you want an ultra fast web site? Get JSL and optimize your JavaScript loading now!
Imagine there's a 4-lane highway between your web browser and the internet itself. This highway is optimize to let pictures, text, and css fly by. But, when it comes to external scripts, the highway crea ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; //引用命名空间
namespace DAL
{
/*******************************************************************************
&n ......
下面这段C# 代码可以用来压缩和修复Access数据库,不管它是一个简单的".mdb"ACCESS数据库还是一个".mdw"网络共享数据库,这个过程和你在用MS Access应用程序中使用的"工具-数据库实用工具-压缩和修复"时执行的操作完全一样.实例代码使用了"迟绑定"(运行中在内存中建立COM对象),这样就不需要在工程中加入COM引用了,也不需要在P ......