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();
相关文档:
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 ......
如果想从网页提交参数到服务器,第一个想到的就是Http的Form标签。它将用户在客户端网页填写的数据通过HTTP Post,提交到服务端。这些提交的数据被放在HTTP消息的body里面,这样,用户提交的数据理论上是没有长度限制的。如果服务端用的是J2EE,HttpServletRequest可以非常轻松得取到所有参 ......
this是Javascript语言的一个关键字。
它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用。比如,
function test(){
this.x = 1;
}
随着函数使用场合的不同,this的值会发生变化。但是有一个总的原则,那就是this指的是,调用函数的那个对象。
下面分四种情况,详细讨论this的用法。
......
1.javascript与Html中的调用问题。
在javascript中要想更改html中的一些属性值,特别是在页面内容较多时,务必使用document.getElementById(id)的方式进行,否则javascript将不能更改属性!
2.Date类。
在Date类中的getMonth()等方法返回值为number。因此可以使用数组存储月份信息如month=[“1月”,&ldq ......
C#生成com组件,供asp调用
一、vs2005—新建项目—C#类库
类库源码如下(包含接口,类,事件接口):
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
namespace entryclass
{
  ......