一、 关于DataGrid的分页
除了设置:AllowPaging是指允许分页,这个是最主要的。有了它,我们才能分页。PageSize是指定每页显示的记录数,如果不写,就会默认为10条。另外,还要加入:
OnPageIndexChanged="DataGrid1_PageIndexChanged"
public void DataGrid1_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)

{ DataGrid1.CurrentPageIndex =e.NewPageIndex;
DataGrid1.DataBind();
}
二、 关于上传文件
上传文件应加入: <form id="Form1" enctype="multipart/form-data" method="post" runat="server">
源文件里边加入:

上传文件
if(File1.PostedFile !=null)


{

File1.PostedFile.SaveAs (Server.MapPath ("file://1.jpg/"));

Image1.ImageUrl =Server.MapPath ("file://1.jpg/");

}


三、 关于自动刷新
HTML应加入: <meta http-equiv ="REFRESH" content ="10;URL=chat.aspx">
自动窗口ScrollWindow():

自动窗口
<script language =javascript 1.1>

function scrollWindow()


{

this.scroll(0,65000);

setTimeout('scrollWindow()',200);

}

scrollWindow();

</script>



四、 连到SQL Server数据库

连接SQL Server数据库
string _sql;

SqlConnection cn;

_sql="server=localhost;uid=sa;pwd=hz0222;database=Northwind";

cn=new SqlConnection (_sql);

cn.Open ();

//SqlCommand cmd =new SqlCommand ("select * from Products ",cn);

//SqlDataReader rs;

//rs=cmd.ExecuteReader();

SqlDataAdapter da=new SqlDataAdapter ("select * from Products",cn);

DataSet ds=new DataSet ();

da.Fill (ds,"Products");

DataGrid1.DataSource =ds.Tables["Products"].DefaultView ;

//DataGrid1.CurrentPageIndex = 0;

DataGrid1.DataBind ();

cn.Close ();


五、 查询IP地址
当然记得用引名字空间 System.Net
六、 在HTML中加载处理页面
<form method="post" action="index2.aspx">
七、 使用TreeView控件
a) 下载并安装IEWebControls:http://www.asp.net/IEWebControls/Download.aspx
b) 安装完以后,默认状态下会建立一个目录:\Program files\IEWeb Controls\,当然你也可改变安装目录。找到这个目录,双击build.bat文件执行,它会建立一个名为build的子目录,并且编译在src目录下的源文件,把编译结果和Runtime目录复制到build子目录中(自动)。在这个动作之后,在build目录下应该会有一个叫"Microsoft.Web.UI.WebControls.dll"文件和一个Runtime子目录。为了能在ASP.NET的Web应用程序中使用这个控件,你必须把\build\Runtime子目录下的内容复制到Web应用程序的 /webctrl_client/1_0子目录中,并且把"Microsoft.Web.UI.WebControls.dll"这个文件复制到Web应用程序的/bin目录下。这个过程在Readme.txt文件有详细的说明,不过是英文的。
c) 然后,你就可以在Toolbox中添加一个工具了(这个不用说明了吧)
八、 取消IE内容安全验证
a) page validateRequest="false" 注意:要加在Web.Config里面的<system.web></system.web>之间
九、 第三方的Dtable控件使用方法
a) 一定要把HTML中的<form……去掉
b) 所连接的表的第一个字段必需是自动编号的int类型,Sql的验证最好加上ASP.NET这个帐号
c) 其它问题请参考论坛http://dtable.2smm.com/
十、 关于JavaScript
-1、 使用热键
<body onkeydown="if(event.keyCode==13)query_data()">
0、 调用JS弹出对话框
Page.Response.Write("<script language=javascript>alert('密码错误!');window.history.back(-1);</script>");
Page.Response.End();
1、 调用JS程序要把"()"加上,例如:checkinput()
2、 在HTML中调用JS的代码片如下:


<script language="javascript">

function closeWnd()


{

window.close();

}

</script>

<input type="button" value='关闭' onclick='closeWnd()'>


3、 关于Document对象的使用:如果你的窗体(名称是Form1)中有一个控件(名称是Keyword)那么,引用方法为: Document.form1.Keyword.value
4、 相关示例见test_js.sln项目
5、 使用状态条:
<a href="tpage.htm" temp_href="tpage.htm" onMouseOver="window.status='Just another stupid link
'; return true">

input type="button" name="look" value="?" onclick="statbar('这是状态条喔

(statusbar) !');">

<input type="button" name="erase" value="d)" onclick="statbar('');">


6、使用日期的例子:
<script language="LiveScript">

<!-- Hiding

today = new Date()

document.write("?( ??/ ",today.getHours(),":",today.getMinutes())

document.write("<br>?) ?- : ", today.getMonth()+1,"/",today.getDate(),"/",today.getYear());

// end hiding contents -->

</script>


7、产生随机数
<script language="LiveScript">


function RandomNumber()
{

today = new Date();

num = Math.abs(Math.sin(today.getTime()));

return num;

}

</script>


8、打开一个新窗口:
<SCRIPT LANGUAGE="javascript">

<!--

window.open ('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no') //这句要写成一行

-->

</SCRIPT>


参数解释:
<SCRIPT LANGUAGE="javascript"> js脚本开始;
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
</SCRIPT> js脚本结束
9、自动关闭窗口
<script language="JavaScript">

function closeit()


{

setTimeout("self.close()",10000) //毫秒

}

</script>


10、打开窗口之Cookies
回想一下,上面的弹出窗口虽然酷,但是有一点小毛病(沉浸在喜悦之中,一定 没有发现吧?)比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?
有解决的办法吗?Yes! Follow me.我们使用cookie来控制一下就可以了。
首先,将如下代码加入主页面HTML的<HEAD>区:

打开窗口Cookie
<script>


function openwin()
{

window.open("page.html","","width=200,height=200")

}

function get_cookie(Name)


{

var search = Name + "="

var returnvalue = "";

if (document.cookie.length > 0)


{

offset = document.cookie.indexOf(search)

if (offset != -1)


{

offset += search.length

end = document.cookie.indexOf(";", offset);

if (end == -1)

end = document.cookie.length;

returnvalue=unescape(document.cookie.substring(offset, end))

}

}

return returnvalue;

}

function loadpopup()


{

if (get_cookie('popped')=='')


{

openwin()

document.cookie="popped=yes"

}

}

</script>


然后,用<body onload="loadpopup()">(注意不是openwin而是loadpop啊!)替换主页面中原有的<BODY>这一句即可。你可以试着刷新一下这个页面或重新进 入该页面,窗口再也不会弹出了。真正的Pop-Only-Once!
写到这里弹出窗口的制作和应用技巧基本上算是完成了!
11、前进后退和定位
<html>
<body>
<FORM NAME="buttonbar">
<INPUT TYPE="button" VALUE="Back" onClick="history.back()">
<INPUT TYPE="button" VALUE="JS- Home" onClick="location='script.html'">
<INPUT TYPE="button" VALUE="Next" onCLick="history.forward()">
</FORM>
</body>
</html>
12、Cookies全部搞定

Cookie操作
<script language="JavaScript">
<!--
var bVisitedToday = false;
var lastVisit = GetCookie("lastVisit");
if (lastVisit != null)


{
lastVisit = 1 * lastVisit;
var lastHere = new Date(lastVisit);
var rightNow = new Date();
if(lastHere.getYear() == rightNow.getYear()
&& lastHere.getMonth() == rightNow.getMonth()
&& lastHere.getDate() == rightNow.getDate())

{
bVisitedToday = true;
}
}
if(bVisitedToday == false)


{
setLastlastVisitCookie(); window.location="http://www.thehungersite.com/"
}
else


{
//window.location="about:blank"
}
function getCookieVal (offset)


{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)


{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;

while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function SetCookie (name, value)


{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function setLastlastVisitCookie ()


{
var rightNow = new Date();
var expdate = new Date();
expdate.setTime (expdate.getTime() + 1 * (24 * 60 * 60 * 1000)); //+1 day
SetCookie ("lastVisit", rightNow.getTime(), expdate, "/");
}

function ResetCookie()


{
SetCookie("lastVisit", 0, null, "/");
}
// -->
</script>
十一、 Asp.net 中 页面无刷新的做法
asp中为了实现无刷新,常常会将数据提交到隐藏框架中,在asp.net中有一个很简单的设置就可以实现
void Page_Load(Object sender, EventArgs e)

{
this.SmartNavigation = true;
}
或者直接写在<%@ Page language="c#" Codebehind="AllBook.aspx.cs" SmartNavigation = true AutoEventWireup="false" Inherits="wx.AllBook" %>
十二、 关于Asp的性能优化
前一段时间,因为工作需要,对一旧系统进行了性能优化。环境描述如下:
1.该系统为以信息为主要内容。采用asp实现表现层,数据库采用MS SqlServer 2000 .
2.asp代码混乱,并伴有许多错误,由于错误被屏蔽了,所以,系统才勉强可以使用。
3.所有的数据访问直接通过在asp程序中编写混合代码实现,并在同一文件中重复访问同一张表。
针对以上情况,经过分析,确定一下原则,
1.将数据库的处理和访问逻辑全部写到存储过程中。
2.asp只做显示输出的部分。
3.将原有的bug修正。
4.建立索引,并更改数据访问的sql,注意要点有
1)Where 的条件需要将索引字段的条件置前。
2)不允许出现count(*) ,以count(field1)取代。
3)不允许出现 select * 以select field1,field2 ...等代替
4)尽量不用IN ,采用exits替代
5) 对于单条的Insert Update和delete ,不采用事务,采用事务锁定表,影响并发的效率,某些特殊情况还需要进行
强制不锁表with(nolock)
十三、 关于传值(隐藏代码方式)
1、在第一个页的HTML中,确认Inherits属性添加到@Page指令:<%@ Page language="c#" Inherits="test_js.page1" %>
2、在第一个页中建立一个Public的属性
public string getName

{
get

{
return txtNumber.Text ;
}
}
3、添加传送指令如下: Server.Transfer ("edit.aspx");
4、第二个页面HTML设置如下: <%@ Reference Page="page1.aspx" %>
5、声明第一个的变量 public page1 fp1;
6、引用方法 //this.IsPostBack方法用于测试页面是否是回传
if (!this.IsPostBack )

{
fp1=(page1)Context.Handler ;
txtRc.Text =fp1.getName;
}


7、完成!
十四、 Application的事件
<script language="C#" runat="server">
void Application_OnBeginRequest(Object sender, EventArgs E)

{
}
void Application_OnEndRequest(Object sender, EventArgs E)

{ }
</script>


十五、 Session的事件
void Session_OnStart()


{
Session["username"]="";//初始化参数
}
void Session_OnEnd()


{
}


十六、 在本窗口打开页面 onclick ="window.open('?addnew=true','_self','')"
十七、 关于DropDownList的数据绑定
drp_Tech.DataSource =ds.Tables["职员表"].DefaultView ;
drp_Tech.DataTextField ="技术员";
drp_Tech.DataBind ();
十八、 Table的使用
1、可以用width=100%来使Table填充窗体的宽度
2、可以用<td colspan="3" align="center"> </td>来合并列,合并行用rowspan,Span的意思是跨度
十九、 DropDownList设置Item被选的方法
DropDownList2.Items.FindByText ("2").Selected =true;
二十、 在HTML中去掉多的边框(整体)
leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
二十一、 用Java下载
<script language="javascript">
var strDownloadUrl = "http://g.china.msn.com/7MEZH_CN/ZH-CHS/SETUPDL.EXE";

function LaunchDownload()
{location.href=strDownloadUrl;}
</script>


二十二、 滚动字的做法:
<marquee scrolldelay="180">欢迎登录海天客户关系管理系统!</marquee>
二十三、 层
在Login.aspx中可以使用层来解决位置的问题
<div id="Layer1"style="BORDER-RIGHT: #000000 0px; BORDER-TOP: #000000 0px; LEFT: 28%; OVERFLOW: hidden; BORDER-LEFT: #000000 0px; WIDTH: 432px; BORDER-BOTTOM: #000000 0px; POSITION: absolute; TOP: 24%; HEIGHT: 282px; visibility: visible;"></div>
二十四、 关于XML
DataSet dsXml =new DataSet ("Settings");
string filepath=Server.MapPath ("file://xml//set.xml");
dsXml.ReadXml(filepath);
DataGrid1.DataSource =dsXml;
Response.Write ("<br><br><br>第一个连接为:" + dsXml.Tables ["Set"].Rows[0]["ConnectionString1"].ToString ());
DataGrid1.DataMember ="Set";
DataGrid1.DataBind ();
二十五、 处理传入的参数
http://mov.hzgwbn.com/movie.asp?addnew=true
在void Form_Load()中加入:
string _addnew=Request.QueryString ["addnew"];
二十六、 关于__dopostback()
看看这个吧,可能有用!!
<SCRIPT language="JavaScript">
<!-- Hide from older browsers
function GetInput()

{
input = prompt('input value that your want to send server:','');
if ((input) && (input!=""))

{
document.forms['Form1'].elements['Hidden1'].value = input;
__doPostBack('Button1', '');
}
}
// Stop hiding -->
</SCRIPT>


其中使用了__DoPostBack这个系统的客户端函数,用来激发服务器事件。
2、为了完成这个完整的页面我们需要一个如下的Form
<form id="Form1" method="post" runat="server">
<INPUT id="Hidden1" type="hidden" name="Hidden1" runat="server">
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</form>
请注意里面的细节,这些都是运行在服务器上的(runat=server)
3、接着就是服务器端的代码(cs文件里面的),Page_load函数使得服务器控件Button1可以在呈现到客户端的时候具有onclick事件代码如下:
private void Page_Load(object sender, System.EventArgs e)
{ this.Button1.Attributes.Add("onclick","GetInput();"); }
4、最后就是按钮的事件了,代码如下,它将取到用户输入的一个值并且将这个值显示在TextBox里面,代码如下:
private void Button1_Click(object sender, System.EventArgs e)
{
string str = this.Hidden1.Value;
this.TextBox1.Text = str;
}
5、我自己的示例onclick="javascript:if(!confirm('ok')){return};__doPostBack('Button3','');"
6、注意:页面上一定要有LinkButton或是别的可以有__doPostBack的控件
二十七、 Toolbar
1、用Javascript处理

ToolBar
<script language="javascript">

function WitchB()



{if (event.srcNode!= null)


{

var bt=event.srcNode.getAttribute("id");

switch (bt)


{

case "C1":

aa();

break;

case "C2":

这里调用.aspx.cs中的过程,这句话该怎么写,用__dopostback()????

break;

}

}

}

function aa()



{
}

</script>

<body onload="Toolbar1.onbuttonclick=WitchB;" MS_POSITIONING="GridLayout">


2、在C#中处理
private void Toolbar1_ButtonClick(object sender, EventArgs e)


{

Response.Write (sender.ToString ());

TextBox1.Text =sender.ToString ();

if(sender.ToString ()=="ToolbarButton - button1")


{

Response.Redirect ("http://localhost/htcrm");

}

}

二十八、 模式对话框
Javascript有许多内建的方法来产生对话框,如:window.alert(), window.confirm(),window.prompt().等。 然而IE提供更多的方法支持对话框。如:
showModalDialog() (IE 4+ 支持)
showModelessDialog() (IE 5+ 支持)
window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框,由于是对话框,因此它并没有一般用window.open()打开的窗口的所有属性。
window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。
当我们用showModelessDialog()打开窗口时,不必用window.close()去关闭它,当以非模态方式[IE5]打开时, 打开对话框的窗口仍可以进行其他的操作,即对话框不总是最上面的焦点,当打开它的窗口URL改变时,它自动关闭。而模态[IE4]方式的对话框始终有焦点(焦点不可移走,直到它关闭)。模态对话框和打开它的窗口相联系,因此我们打开另外的窗口时,他们的链接关系依然保存,并且隐藏在活动窗口的下面。
使用方法如下:
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])
参数说明:
sURL
必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
vArguments
可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures
可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
dialogHeight 对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
dialogWidth: 对话框宽度。
dialogLeft: 距离桌面左的距离。
dialogTop: 离桌面上的距离。
center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。
还有几个属性是用在HTA中的,在一般的网页中一般不使用。
dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。
传入参数:
要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如:

test
test1.htm

====================


<script>

var mxh1 = new Array("mxh","net_lover","孟子E章")

var mxh2 = window.open("about:blank","window_mxh")

// 向对话框传递数组

window.showModalDialog("test2.htm",mxh1)

// 向对话框传递window对象

window.showModalDialog("test3.htm",mxh2)

</script>
test2.htm

====================


<script>

var a = window.dialogArguments

alert("您传递的参数为:" + a)

</script>
test3.htm

====================


<script>

var a = window.dialogArguments

alert("您传递的参数为window对象,名称:" + a.name)

</script>


可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:


test4.htm

===================


<script>

var a = window.showModalDialog("test5.htm")

for(i=0;i<a.length;i++) alert(a[i])

</script>


test5.htm

===================


<script>

function sendTo()


{

var a=new Array("a","b")

window.returnValue = a

window.close()

}

</script>

<body>

<form>

<input value="返回" type=button onclick="sendTo()">

</form>
常见问题:
1, 如何在模态对话框中进行提交而不新开窗口?
2, <base target="_self">
如果你 的 浏览器是IE5.5+,可以在对话框中使用带name属性的iframe,提交时可以制定target为该iframe的name。对于IE4+,你可以用高度为0的frame来作:例子,
2,可以通过http://servername/virtualdirname/test.htm?name=mxh方式直接向对话框传递参数吗?
答案是不能。但在frame里是可以的。
3,我的例子
<script language="javascript">
function KDMsgBox(info)

{
var sUrl = "messagedlg.jsp?locale=zh_cn";
var sFeature="dialogWidth:368px;dialogHeight:212px;center:yes;help:no;resizable:no;status:no;scroll:no";
var retObj= window.showModalDialog("error.htm",info,sFeature);
return retObj;
}
</script>
二十九、 防止被别人框架
加在不想被框架的HTML中的<head></head>中:
<SCRIPT LANGUAGE=javascript>
if (top.location != self.location) top.location=self.location;
</SCRIPT>

三十、 在重定向中打开新的Window
response.write("<script>window.open("store/Shop.Type.aspx?id=9")</script>") \
三十一、 IE的控制
<html>
<head>
<title>IE的控制</title>
</head>
<body>
<a href="#" onclick=document.execCommand("open")>打开</a><br>
<a href="#" onclick=location.replace("view-source:"+location)>使用 记事本 编辑</a><br>
<a href="#" onclick=document.execCommand("saveAs")>另存为</a><br>
<a href="#" onclick=document.execCommand("print")>打印</a><br>
<a href="#" onclick=window.close();return false)>关闭本窗口</a><br>
<a href="#" onclick=document.execCommand("selectAll")>全选</a><br>
<a href="#" onclick=location.reload()>刷新</a><a href="#" onclick=history.go(0)>刷新</a><br>
<a href="#" onclick=location.replace("view-source:"+location)>查看源文件</a> <br>
<a href="#" onclick=window.open(document.location,"url","fullscreen")>全屏显示</a> <br>
<a href="javascript:window.external.AddFavorite('http://homepage.yesky.com', '天极网页陶吧')">添加到收藏夹</a> <br>
<a href="#" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a> <br>
<a href="#" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet选项</a> <br>
<a href="#" onclick=history.go(1)>前进1</a><a href="#" onclick=history.forward()>前进2</a><br>
<a href="#" onclick=history.go(-1)>后退1</a><a href="#" onclick=history.back()>后退2</a><br>
<a href="#" onclick=setTimeout(window.close(),3000)>3秒关闭本窗口</a><br>
</body>
</html>
三十二、 .NET Data Provider(.NET数据驱动)
.Net 的数据连接可以分为两种方式:
1、SQL .NET DATA Provider,支持Microsoft SQL Server 7.0及 2000以上版本,专用于Sql Server,速度很快
2、OLEDB .NET DATA Provider,支持DBase、Foxpro、Excel、Acess、Oracle等,也可以是Sql Server,但速度不如上一个
三十三、 关于Sql中的单引号(')
可以用sqlstr.Replace("‘","’‘") 来替换,因为Sql会把两个连续的单引号看成是一个单引号
三十四、 用DataReader读取数据的过程
1、使用SqlConnection建立连接
2、使用SqlCommand对象的ExcuteReader()方法执行查询
3、使用DataReader接收查询的结果集
4、DataReader常见的方法和属性:
Read()方法,用于读取数据,并返回Bool值
FieldCount属性,返回记录集字段总数
GetName(i)方法,返回第i列的字段名称
GetValue(i)方法,返回第i列的字段内容
DataReader(i),返回第i列的数据内容
DataReader[“字段名”],返回字段内容
GetDataTypeName(i),返回第i列字段的数据类型
GetOrdinal(i),返回第i列字段的下标
IsDBNull(i),返回第i列的字段是否为空
Close()方法,关闭DataReader对象
三十五、 参数传递的三种方式
1、传值:GetName(string i)
2、传地址1(引用):GetName(ref string i)
3、传地址2(输出参数):GetName(out string i)
2和3的区别在于2的参数必需要初始化,而3不要
如:myCommand.Execute(out myDataReader);
三十六、 DataSet使用方法
首先我们需要打开一个联结,我们的数据库还是用上一节的吧:)
string MyConnString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:/test/test.mdb;";
string strComm = "select * from UserList";
ADOConnection MyConnection = new ADOConnection(MyConnString);
ADODataSetCommand MyComm = new ADODataSetCommand(strComm,MyConnection);
这里我们为了讲解方便,只在DataSet存入一个表的内容:
DataSet MyDataSet = new DataSet();
MyComm.FillDataSet(MyDataSet,"UserList");
1、添加数据
DataRow dr=MyDataSet.Tables["UserList"].NewRow();
dr["UserName"] = "周讯";
dr["ReMark"] = "100";
dr["Comment"] = "漂亮MM";
MyDataSet.Tables.Rows.Add(dr);
2、修改数据
MyDataSet.Tables["UserList"].Rows[0]["UserName"]="飞刀大哥";
3、删除数据
删除数据,主要是使用RowsCollection提供的Delete方法,看下面的程序也是很简单的事情啦:)
MyDataSet.Tables["UserList"],Rows[0].Delete();
4、恢复数据有时候我们添加/修改数据会出现错误,这时候,就需要恢复原来的数据。下面的程序,显示如何判断是否有错误发生:if(MyDataSet.HasErrors)
{
MyDataSet.RejectChanges();
}
5、看Dataset是否有改动
if(MyDataSet.HasChanges)
{
//保存
}
else
{
//不进行任何操作
}
6、更新保存
我们上面的操作,都只是针对DataSet的,没有操作数据库,但是我们的目的还是要将数据保存到数据中去,所以我们这里就需要调用DataSetCommand的Update方法。下面的程序显示如何将DataSet的数据交给数据库。
MyComm.Update(MyDataSet);
很简单的一句,呵呵。这里要注意,如果一个DataSet中包含有多个表,而我们只更新一个,那我们就必须写明更新的数据表名:
MyComm.Update(MyDataSet,"UserList");
三十七、 在线人员
本论坛的在线,没有采用传统数据库表格保存的方式,而是利用Cache来做
这样避免了频繁地读写数据库,但相应地增加了服务器内存的开销
好在Online的开销不是很大,而且是应用程序级,但不知这两种方法孰优孰劣?
源代码如下:

在线人员统计
//保存在线
public void SaveOnline(string userPlace)



{

DataTable online;

if (HttpContext.Current.Cache["online"]==null)


{

online = new DataTable();

online.Columns.Add("onlineID",typeof(string));

online.Columns.Add("userID",typeof(string));

online.Columns.Add("userName",typeof(string));

online.Columns.Add("userLevelName",typeof(string));

online.Columns.Add("userLevelImg",typeof(string));

online.Columns.Add("userIP",typeof(string));

online.Columns.Add("userPlace",typeof(string));

online.Columns.Add("logoTime",typeof(DateTime));

online.Columns.Add("actionTime",typeof(DateTime));

online.Columns.Add("userOS",typeof(string));

online.Columns.Add("userCLR",typeof(string));

online.Columns.Add("userBorwser",typeof(string));


HttpContext.Current.Cache["online"] = online;

}


DataRow[] dr1;

DataRow dr2;

online = (DataTable)HttpContext.Current.Cache["online"];

dr1 = online.Select("onlineID='" + onlineID + "'");

if (dr1.Length>0)


{

dr1[0][1] = UserID;

dr1[0][2] = UserName;

dr1[0][4] = UserLevelImg;

dr1[0][6] = userPlace;

dr1[0][8] = DateTime.Now;

online.AcceptChanges();

}

else


{

dr2 = online.NewRow();

dr2[0] = onlineID;

dr2[1] = UserID;

dr2[2] = UserName;

dr2[3] = userLevelName;

dr2[4] = UserLevelImg;

dr2[5] = UserIP;

dr2[6] = userPlace;

dr2[7] = DateTime.Now;

dr2[8] = DateTime.Now;

dr2[9] = UserOS;

dr2[10] = UserCLR;

dr2[11] = UserBrowser;

online.Rows.Add(dr2);

}

DeleteOnline();

}






//清除超时用户

private void DeleteOnline()



{

DataTable online = (DataTable)HttpContext.Current.Cache["online"];

for (int i=0;i<online.Rows.Count;i++)


{

if (Convert.ToDateTime(online.Rows[i][7])<DateTime.Now.AddMinutes(-10.0))

online.Rows[i].Delete();

}

online.AcceptChanges();

}


三十八、 关于Cache
1、无变化的Cache
<%@ OutputCache Duration="60" VaryByParam="none" %>
2、根据参数变化的Cache
<%@ OutputCache Duration="60" VaryByParam="state" %>
3、通过复杂控制Cache
应用程序若要更多地控制与缓存相关的 HTTP 标头,可使用 System.Web.HttpCachePolicy 类提供的功能。下面的示例显示等效于上例中使用的页指令的代码。
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
若要使之成为变化的过期策略(即每次请求页时都重新设置过期时间),请按以下代码所示来设置 SlidingExpiration 属性。
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetSlidingExpiration(true);
注意:启用变化的过期后 (SetSlidingExpiration(true)),对原服务器的请求总是会生成一个响应。在下游缓存可满足客户端请求(缓存中的内容尚未过期)而无须从原服务器请求内容的情况下,使用变化的过期时间是很有用的。
从 ASP 移植过来的应用程序可能已用 ASP 属性设置了缓存策略;例如:
Response.CacheControl = "Public";
Response.Expires = 60;
三十九、 关于呼出表单
注:本处所指表单就是层
<SCRIPT LANGUAGE='JavaScript'>

function showdtablesearchlay()


{

if (document.getElementById('dtablesearch'))


{

var x=window.screen.width;

var y=window.screen.height;

dtablesearch.style.left=(x-360)/2;dtablesearch.style.top=(y-360)/2;

dtablesearch.style.visibility='visible';

}

}

function hiddendtablesearchlay()


{

if (document.getElementById('dtablesearch'))


{

dtablesearch.style.visibility='hidden';

}

}

</SCRIPT>


附:建立一个浮动表单
<div id='dtablesearch' style="position:absolute; width:360px; height:174px; z-index:1; left: 161px; top: 18px; background-color: #ffffff; border: 1px outset #000000; visibility: hidden;filter:progid:DXImageTransform.Microsoft.Shadow(Color=#333333,Direction=120,strength=5)" onDblClick="hiddendtablesearchlay();"></div>
附2:下拉菜单

下拉菜单
<script Language="JavaScript">

//***********默认设置定义.*********************

tPopWait=50;//停留tWait豪秒后显示提示。

tPopShow=5000;//显示tShow豪秒后关闭提示

showPopStep=20;

popOpacity=99;


//***************内部变量定义*****************

sPop=null;

curShow=null;

tFadeOut=null;

tFadeIn=null;

tFadeWaiting=null;


document.write("<style type='text/css'id='defaultPopStyle'>");

document.write(".cPopText { background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");

document.write("</style>");

document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");



function showPopupText()
{

var o=event.srcElement;

MouseX=event.x;

MouseY=event.y;


if(o.alt!=null && o.alt!="")
{o.dypop=o.alt;o.alt=""};


if(o.title!=null && o.title!="")
{o.dypop=o.title;o.title=""};


if(o.dypop!=sPop)
{

sPop=o.dypop;

clearTimeout(curShow);

clearTimeout(tFadeOut);

clearTimeout(tFadeIn);

clearTimeout(tFadeWaiting);


if(sPop==null || sPop=="")
{

dypopLayer.innerHTML="";

dypopLayer.style.filter="Alpha()";

dypopLayer.filters.Alpha.opacity=0;

}


else
{

if(o.dyclass!=null) popStyle=o.dyclass

else popStyle="cPopText";

curShow=setTimeout("showIt()",tPopWait);

}


}

}







function showIt()
{

dypopLayer.className=popStyle;

dypopLayer.innerHTML=sPop;

popWidth=dypopLayer.clientWidth;

popHeight=dypopLayer.clientHeight;

if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24

else popLeftAdjust=0;

if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24

else popTopAdjust=0;

dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;

dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;

dypopLayer.style.filter="Alpha(Opacity=0)";

fadeOut();

}







function fadeOut()
{


if(dypopLayer.filters.Alpha.opacity<popOpacity)
{

dypopLayer.filters.Alpha.opacity+=showPopStep;

tFadeOut=setTimeout("fadeOut()",1);

}


else
{

dypopLayer.filters.Alpha.opacity=popOpacity;

tFadeWaiting=setTimeout("fadeIn()",tPopShow);

}

}







function fadeIn()
{


if(dypopLayer.filters.Alpha.opacity>0)
{

dypopLayer.filters.Alpha.opacity-=1;

tFadeIn=setTimeout("fadeIn()",1);

}

}

document.onmouseover=showPopupText;







function CheckAll(form)
{


for (var i=0;i<form.elements.length;i++)
{

var e = form.elements[i];

if (e.name != 'chkall') e.checked = form.chkall.checked;

}

}






//下拉菜单相关代码

var h;

var w;

var l;

var t;

var topMar = 1;

var leftMar = -2;

var space = 1;

var isvisible;

var MENU_SHADOW_COLOR='#999999';//定义下拉菜单阴影色

var global = window.document

global.fo_currentMenu = null

global.fo_shadows = new Array






function HideMenu()



{

var mX;

var mY;

var vDiv;

var mDiv;

if (isvisible == true)



{

vDiv = document.all("menuDiv");

mX = window.event.clientX + document.body.scrollLeft;

mY = window.event.clientY + document.body.scrollTop;


if ((mX < parseInt(vDiv.style.left)) || (mX > parseInt(vDiv.style.left)+vDiv.offsetWidth) || (mY < parseInt(vDiv.style.top)-h) || (mY > parseInt(vDiv.style.top)+vDiv.offsetHeight))
{

vDiv.style.visibility = "hidden";

isvisible = false;

}

}

}







function ShowMenu(vMnuCode,tWidth)
{

vSrc = window.event.srcElement;

vMnuCode = "<table id='submenu' cellspacing=1 cellpadding=3 style='width:"+tWidth+"' class=tableborder1 onmouseout='HideMenu()'><tr height=23><td nowrap align=left class=tablebody1>" + vMnuCode + "</td></tr></table>";






h = vSrc.offsetHeight;

w = vSrc.offsetWidth;

l = vSrc.offsetLeft + leftMar+4;

t = vSrc.offsetTop + topMar + h + space-2;

vParent = vSrc.offsetParent;

while (vParent.tagName.toUpperCase() != "BODY")


{

l += vParent.offsetLeft;

t += vParent.offsetTop;

vParent = vParent.offsetParent;

}






menuDiv.innerHTML = vMnuCode;

menuDiv.style.top = t;

menuDiv.style.left = l;

menuDiv.style.visibility = "visible";

isvisible = true;

makeRectangularDropShadow(submenu, MENU_SHADOW_COLOR, 4)

}






function makeRectangularDropShadow(el, color, size)



{

var i;

for (i=size; i>0; i--)


{

var rect = document.createElement('div');

var rs = rect.style

rs.position = 'absolute';

rs.left = (el.style.posLeft + i) + 'px';

rs.top = (el.style.posTop + i) + 'px';

rs.width = el.offsetWidth + 'px';

rs.height = el.offsetHeight + 'px';

rs.zIndex = el.style.zIndex - i;

rs.backgroundColor = color;

var opacity = 1 - i / (i + 1);

rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';

el.insertAdjacentElement('afterEnd', rect);

global.fo_shadows[global.fo_shadows.length] = rect;

}

}

四十、 关于Web.config文件
几乎在每本介绍Asp.Net编程的书里,在谈到如何管理数据库连接字符串的时候,都是采用将数据库连接字符串以如下形式放在Web.Config文件中
< appSettings>
< add key="ConnectionString" value="data source=localhost;initial catalog=Database;user id=;password="/>
</appSettings>
然后在程序中采用以下方式访问
System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]
这样做的好处非常明显:当数据库有变动的时候,只需要改变web.config中的连接字符串,而不需要重新编译整个应用程序,给应用的部署和移植带来非常大的方便。
附:写入Web.config的函数
/// <summary>

/// 修改web.config文件appSettings配置节中的Add里的value属性

/// </summary>

/// <remarks>

/// 注意,调用该函数后,会使整个Web Application重启,导致当前所有的会话丢失

/// </remarks>

/// <param name="key">要修改的键key</param>

/// <param name="strValue">修改后的value</param>

/// <exception cref="">找不到相关的键</exception>

/// <exception cref="">权限不够,无法保存到web.config文件中</exception>


修改Web.Config
public void Modify(string key,string strValue)


{

string XPath="/configuration/appSettings/add[@key='?']";

XmlDocument domWebConfig=new XmlDocument();


domWebConfig.Load( (HttpContext.Current.Server.MapPath("web.config")) );

XmlNode addKey=domWebConfig.SelectSingleNode( (XPath.Replace("?",key)) );

if(addKey == null)


{

throw new ArgumentException("没有找到<add key='"+key+"' value=
/>的配置节");

}

addKey.Attributes["value"].InnerText=strValue;

domWebConfig.Save( (HttpContext.Current.Server.MapPath("web.config")) );


}
四十一、 如何使用T-SQL来给系统增加计划任务
declare @RunTime char(5)

declare @String char(100)

set @RunTime=left(convert(char(5),getdate(),8),2) + ':' + convert(char(2),convert(int,right(convert(char(5),getdate(),8),2) )+1,2)

set @String='at '+ @RunTime + ' /interactive ' + ' C:windowssystem32 otepad.exe'

exec ('master..xp_cmdshell "'+@String +'"')
上面的脚本是在当前时间后的1分钟增加一个任务。如果直接执行
xp_cmdshell @String 会报错,最终还是在MSDN的Community中找到了解决的办法。
四十二、 在网页上右键弹出菜单的子菜单范例

右键弹出菜单
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >


<html>

<head>

<title>PopupMenuTest</title>

<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" Content="C#">

<meta name=vs_defaultClientScript content="JavaScript">

<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">

</head>

<body MS_POSITIONING="GridLayout" oncontextmenu="return DisplayPopupMenu();">


<script language="javascript">

function DisplayPopupMenu()


{

menuTree.show(event.x, event.y);

return false;

}


function menuTreeBeforePopup()


{

}


function menuTreeClick(objTree)


{


switch(event.menuData)


{

case "refresh": alert('refresh clicked.');

break;

case "property":alert('property clicked.');

break;

case "message":alert('message clicked.');

break;

case "email":alert('email clicked.');

break;

}

}

</script>

<form id="Form1" method="post" runat="server">

<?XML:NAMESPACE PREFIX="hGui" /><?import namespace="hGui" implementation="/webcontrols/sMenu.htc" />

<hGui:smenu id="menuTree" onmenuclick="menuTreeClick()" onbeforepopup="menuTreeBeforePopup();" style="Z-INDEX: 100">

刷新,,,,./images/refresh.gif,refresh;

新建,subMenu1,,,,submenu1;

-,0,,,,;

属性,,,,./images/property.gif,property

</hGui:smenu>


<?XML:NAMESPACE PREFIX="hGui" /><?import namespace="hGui" implementation="/webcontrols/sMenu.htc" />


<hGui:smenu id="subMenu1" onmenuclick="menuTreeClick()" onbeforepopup="menuTreeBeforePopup();" style="Z-INDEX: 100">

短消息,,,,./images/refresh.gif,message;

-,0,,,,;

发送E-Mail,,,,./images/property.gif,email

</hGui:smenu>

</form>

</body>

</html>
四十三、 contentEditable="true" 的妙用 - 打印
不知道各位有没有做过用于打印的Web页。
我帮客户做这个页面的时候,喜欢把某些区域定为contentEditable="true",目的是让客户可以随便修改这些地方。
例如:
<Asp:Panel runat=server contentEditable="true"/>..<Asp:Label runat=server id=PrintTitle Text=PrintTitle/>..</Asp:Panel>
四十四、 防止重复提交

防止重复提交

function _doPostBack()
{};

if(typeof("__doPostBack")=="function")



{

_doPostBack=__doPostBack;

__doPostBack=_doPostBackNew;

}
document.attachEvent("onmousemove",_onmousemove);

var _isPosting=false;

var _divMask=null;

function _onmousemove()



{

if(_divMask)

with(_divMask.runtimeStyle)


{

left=event.clientX+document.body.scrollLeft-4;

top=event.clientY+document.body.scrollTop-4;

}

}

function _makeMask()



{

var div=document.createElement("DIV");

with(div.runtimeStyle)


{

position="absolute";

zIndex=999999;

fontSize="1px";

left=event.clientX+document.body.scrollLeft-4;

top=event.clientY+document.body.scrollTop-4;

width="8px";

height="8px";

cursor="wait";


backgroundColor="gray";

filter="alpha(opacity=10)";

}

try


{

document.body.insertAdjacentElement("BeforeEnd",div);

div.onblur=new Function("this.focus()");

div.focus();

}


catch(x)
{}


if(_divMask)_divMask.removeNode(true);

_divMask=div;

}

function _doPostBackNew(sender,args)



{

if(_isPosting)

return event.returnValue=!(event.cancelBubble=true);

status="正在更新页面
";

_doPostBack(sender,args);

_isPosting=true;

_makeMask();

}


function _onformsubmit()



{

if(_isPosting)

return event.returnValue=!(event.cancelBubble=true);

_isPosting=true;

_makeMask();

}

new function _attachForms()



{

with(new Enumerator(document.forms))

for(;!atEnd();moveNext())


{

item().attachEvent("onsubmit",_onformsubmit);

var div=document.createElement("div");

div.runtimeStyle.width="0px";

div.runtimeStyle.hight="0px";

div.runtimeStyle.overflow="hidden";

div.runtimeStyle.position="absolute";

item(0).insertAdjacentElement("afterbegin",div);

div.innerHTML="<INPUT TYPE=Submit name='webformpatchsubmitelement' onclick='return event.returnValue=false' id='webformpatchsubmitelement' value='webformpatchsubmitelement'/>";

}

}
把这个作为 <-script src=.....js-><-/script-> 的形式Render到每个页面中就可以了。|
如果有PageBase,则在Init的时候用RegisterClientScriptBlock放上去更好。
因为客户没有抱怨过,所以也没有改进过。
四十五、 WebServices服务调用详细
WebService1.lists.Lists weblist = new WebService1.lists.Lists();
weblist.Url = "http://190.1.1.111:800/_vti_bin/Lists.asmx";
weblist.PreAuthenticate = true;
weblist.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode ndlist = weblist.GetListCollection();
四十六、 如何实现文本框焦点自动跳转及通过回车键提交表单
该文章讲的是在ASP.NET登录页面中如何实现文本框焦点自动跳转及通过回车键提交表单。
所需的Javascript代码:

实现文本框焦点自佛那个跳转通过回车实现提交
<script language="JavaScript">
NS4 = (document.layers) ? true : false;
function checkEnter(event,element)


{
var code = 0;
if (NS4)
code = event.which;
else
code = event.keyCode;

if (code==13)

{
if(element.name=='tbUserName')//tbUserName-用户名文本框的Name

{ document.frmLogin.tbPassword.focus();//frmLogin-表单名称,tbPassword-密码文本杠框的Name
}
if(element.name=='tbPassword')

{
//document.frmLogin.submit();用这种方式提交,Asp.net页面会闪一下,但实际并未提交
//用下面的代码才能提交,我是从asp.net生成的页面中查看源文件然后复制出来的
if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) __doPostBack('lblLogin','');
}
}
}
</script>
我将这些代码放在了一个LoginScript.js文件中,然后在Login.cs文件中添加如下代码就实现这样的功能:
tbUserName.Attributes.Add("onKeyPress","checkEnter(event,this)");
tbPassword.Attributes.Add("onKeyPress","checkEnter(event,this)");
System.IO.StreamReader sr=new System.IO.StreamReader(MapPath("Script")+"file://LoginScript.js/");
this.RegisterClientScriptBlock("LoginScript",sr.ReadToEnd());
sr.Close();
四十七、 显示和隐藏主菜单

显示和隐藏主菜单
<script LANGUAGE="JavaScript">

function toggleMenu()


{


// hide the menu

if(document.all.toggleMenuImg.value == '1')


{

document.all.toggleMenuImg.value = '0';

document.all.toggleMenuImg.src="images/tbnt_mc.gif";

top.document.getElementById('WindowLeft').cols = "0px,*";

}

// display the menu

else


{

document.all.toggleMenuImg.value = '1';

document.all.toggleMenuImg.src="images/tbtn_mo.gif";

top.document.getElementById('WindowLeft').cols = "170px,*";

}


}

</script>


四十八、 使用iFrame
<iframe name="mainframe" id="mainframe" src="http://www.yahoo.com/" frameborder="0" noresize
scrolling="auto" style="BORDER-RIGHT:medium none;PADDING-RIGHT:0px;BORDER-TOP:medium none;PADDING-LEFT:0px;RIGHT:0px;PADDING-BOTTOM:0px;BORDER-LEFT:medium none;WIDTH:100%;PADDING-TOP:0px;BORDER-BOTTOM:medium none;POSITION:absolute;TOP:26px;HEIGHT:95%">
</iframe>
四十九、 DataGrid中的bool值转换成"是"与"否"
有很多人问如何在DataGrid中显示是与否的显示方法..其实还是比较容易实现的.
<asp:TemplateColumn HeaderText="情况">
<ItemTemplate>
<%# (bool)DataBinder.Eval(Container,"DataItem.IsActive")?"是":"否"%>
</ItemTemplate>
</asp:TemplateColumn>
五十、 C#中Random.Next()的错误
用Random.Next(rang1,rang2)产生的随机数,竟然前后几次都是相同的!
后改用Random.NextDouble()产生0.1-1.0的浮点数就可以了,真是的,搞了我几个小时
五十一、 IIS上运行的不是ASP 1.1服务器
vs.net检测到指定的web服务器运行的不是asp.net1.1版,将无法运行web服务或应用程序 这是装完IIS后运行vs中的asp.net出现的,我的系统装的是XP sp2
解决方法如下:
aspnet_regiis/I
五十二、 按CTRL+回车提交表单
在文本框中按CTRL+回车,需要执行文本框的ONKEYUP事件,
<textarea name="TextBox1" id="TextBox1" onkeyup="post();" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 16px"></textarea>
我这里共有二个解决方法(实际上也是一个)
在ASP.NET中,所有的服务器控件提交到服务器的时候,都会调用__doPostBack这个函数,所以,我们第一种方法就是利用__doPostBack
‘********************************网上摘来的****************************
在asp.net中服务器控件回送表单是通过调用__doPostBack函数来回送表单,触发事件的,先来看看__doPostBack函数:

function __doPostBack(eventTarget, eventArgument)
{


if (theForm.onsubmit == null || theForm.onsubmit())
{

theForm.__EVENTTARGET.value = eventTarget;

theForm.__EVENTARGUMENT.value = eventArgument;

theForm.submit();

}

}
第一个参数是控件名称,第二个参数包含事件的额外信息.
***********************************************
为方便查看我就直接在ASPX页添加JS。
当按CTRL+回事,执行BUTTON1事件
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write("<script>alert(""oks"")</script>")
'Response.Redirect(Request.RawUrl)
End Sub
A.ASPX
<SCRIPT LANGUAGE='JavaScript'><!--
function post(){
if (event.ctrlKey && window.event.keyCode==13)
{
alert("ok");
__doPostBack('button1','');
}
}
//-->
</script>
当你的页面没有__doPostBack这个函数(在程序运行时,右击,查看源文件),就可以不能使用__doPostBack了,
<SCRIPT LANGUAGE='JavaScript'><!--
function post(){
if (event.ctrlKey && window.event.keyCode==13)
{
alert("ok");document.forms(0).Button1.click();
}
}
//-->
</script>
五十三、 关掉FrameSet(上级窗口)
top.location.href='javascript:window.close()';