摘录的.net开发笔记资料
[ 2005-11-12 15:32:14 | 作者: admin ]
开发笔记资料
1. 数据验证
public static bool ValidateUserid(string inString)
{
Regex r = new Regex("^[A-Za-z0-9]{8}$");
return r.IsMatch(inString)
}
^[A-Za-z0-9]{8}$ 8个字的种子
2. 后期绑定
<%# DataBinder.Eval(Container.DataItem,"price","{0:c}") %> 货币格式
3. 注册客户端脚本
string sClose = null;
sClose = @"<script language = javascript>
window.close();
</script>";
RegisterClientScriptBlock("clsBlock",sClose);
4. 访问DataGrid的模板控件
(CheckBox)dgd.Items[i].Cells[0].Controls[1];
5. 给服务器控件增加客户端属性
DataGrid1.Attributes.Add("ondblclick","window.open('Require.aspx')"); ---双击事件
DataGrid1.Attributes.Add("onclick","window.open('Require.aspx')"); ---单击事件
6. 客户端日期控件(javascript)
7. 视图状态的应用
不要用static,而用viewstate保存数据. 不需要时禁用控件的viewstate.
8. 数据验证控件应用
9. 模态页面与非模态页面
10. 页面之间的值传递, 引用传递.
11.
RegisterStartupScript() 方法可用于添加要在加载页面后运行的脚本块。
通过这种方法添加的脚本块位于 Web 窗体的结尾处,
因为必须在脚本运行前定义脚本要修改的 HTML 元素。
也就是说,如果您要使用客户端脚本将焦点设置到文本框,
必须确保文本框的 HTML 标记位于设置该文本框的焦点的脚本之前。
例如,下面的 HTML 将显示一个文本框,并将焦点设置到该文本框:
<input type="text" id="myTextBox" />
<script language="JavaScript">
<!--
document.getElementById("myTextBox").focus();
// -->
</script>
相反,以下 HTML 不会将焦点设置到文本框,因为文本框是在脚本块“之后”定义的:
<script language="JavaScript">
<!--
document.getElementById("myTextBox").focus();
// -->
</script>
<input type="text" id="myTextBox" />
12.
如果使用这个关键字调用两次 RegisterClientScriptBlock() 或 RegisterStartupScript() 方法,
则第二次调用会被认为是复制脚本块而被忽略
那些显示为 HTML 元素的服务器控件,
如 TextBox、Button、DataGrid 等等,是从 System.Web.UI.WebControls.WebControl 类导出的,
而那些不产生 HTML 元素的控件,如 Literal、Repeater 等,是从 System.Web.UI.Control 类导出的。
13.
请注意,onclick 事件将返回 confirm() 函数调用的结果。
当通过单击提交按钮来提交表单时,
如果提交按钮的 onclick 事件返回 False,则表单未被提交。
因此,只有在用户确认后,可以使用 confirm() 函数提交表单
14.ViewState 一般用法
bool SortAscending {
get {
object o = ViewState["SortAscending"];
if (o == null) {
return true;
}
return (bool)o;
}
set {
ViewState["SortAscending"] = value;
}
}
15.总是在裁人,简称总裁;老是板着脸,故称老板;经常不理人那叫经理。
16.
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem,"yymc") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
17.文件上传
<%@ Page language="c#" Codebehind="UpLoad.aspx.cs" AutoEventWireup="false" Inherits="WebPortal.Upload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>多文件上传</title>
<script language="JavaScript">
function addFile()
{
var str = '<INPUT type="file" size="50" NAME="File">'
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<div align="center">
<h3>多文件上传</h3>
<P id="MyFile"><INPUT type="file" size="50" NAME="File"></P>
<P>
<input type="button" value="增加(Add)" onclick="addFile()">
<input onclick="this.form.reset()" type="button" value="重置(ReSet)">
<asp:Button Runat="server" Text="开始上传" ID="UploadButton"></asp:Button>
</P>
<P>
<asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="9pt"
Width="500px" BorderStyle="None" BorderColor="White"></asp:Label>
</P>
</div>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebPortal
{
/// <summary>
/// UpLoad 的摘要说明。
/// 实现多文件上传
/// </summary>
public class Upload : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button UploadButton;
protected System.Web.UI.WebControls.Label strStatus;
private void Page_Load(object sender, System.EventArgs e)
{
/// 在此处放置用户代码以初始化页面
if (this.IsPostBack) this.SaveImages();
}
private Boolean SaveImages()
{
///'遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
/// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch(System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ID = "Upload";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
18. 上传文件到oracle数据库
void uploadFile()
{
FileStream objFs = new FileStream(File1.Value,FileMode.Open, FileAccess.Read);
BinaryReader objBr = new BinaryReader(objFs);
byte [] bytFile = objBr.ReadBytes((int)objFs.Length);
OracleConnection objOconn = new OracleConnection("user id=system;Data Source=tsems;password=system");
objOconn.Open();
OracleCommand objOcmd = new OracleCommand();
objOcmd.Connection = objOconn;
objOcmd.CommandText = "INSERT INTO HR.TESTFILEUPLOAD VALUES(:VPKID,:VFILENAME , :VFILE)";
objOcmd.Parameters.Add("VPKID", OracleType.VarChar);
objOcmd.Parameters["VPKID"].Value = "2006";
objOcmd.Parameters.Add("VFILENAME",OracleType.VarChar);
objOcmd.Parameters["VFILENAME"].Value = Path.GetFileName(File1.Value);
objOcmd.Parameters.Add("VFILE",OracleType.Blob,bytFile.Length);
objOcmd.Parameters["VFILE"].Value = bytFile;
objOcmd.ExecuteNonQuery();
objOconn.Close();
Response.Write("true");
}
19. 取得查询字符串value (javascript)
function getQuery(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return unescape(r[2]); return null;
}
getQuery("fb")
20.
onmouseout="this.bgColor=document.getElementById('DataGrid1').getAttribute('singleValue')"
21. Response.Write("<Script>document.parentWindow.location.reload();</script>");
22. 从oracle下载数据
将Oracle数据库中HR方案下的TESTFILEUPLOAD表中的文件下载至系统临时目录。
void downloadFile()
{
OracleConnection objOcon = new OracleConnection("user id=system;Data Source=tsems;password=system");
OracleCommand objOcmd = new OracleCommand();
objOcmd.Connection = objOcon;
objOcmd.CommandText = "SELECT * FROM HR.TESTFILEUPLOAD WHERE PKID='2006'";
FileStream objFs;
BinaryWriter objBw;
int bufferSize = 260;
byte [] outByte = new byte[bufferSize];
long retval;
long startIndex = 0;
string fileName = "";
objOcon.Open();
OracleDataReader objDr = objOcmd.ExecuteReader(CommandBehavior.SequentialAccess);
objDr.Read();
fileName = objDr["FILENAME"].ToString();
objFs = new FileStream(Path.GetTempPath()+fileName, FileMode.OpenOrCreate,FileAccess.Write);
objBw = new BinaryWriter(objFs);
startIndex = 0;
retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
while ( retval == bufferSize)
{
objBw.Write(outByte);
objBw.Flush();
startIndex += bufferSize;
retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
}
objBw.Write(outByte, 0, (int)retval -1);
objBw.Flush();
objBw.Close();
objFs.Close();
bjDr.Close();
objOcon.Close();
}
23. 客户端调用
function IsSaveMessageBox(strMessage)
{
if (confirm(strMessage))
{
__doPostBack('btnSave','');
}
}
24
<script language="jscript">
//取得网络上的打印机
function getnetprinter()
{
var obj=new ActiveXObject("WScript.Network");
var netprinter=obj.EnumPrinterConnections();
for(i=0;i<netprinter.Count();i+=2)
{
document.writeln(netprinter.Item(i)+"="+netprinter.Item(i+1));
}
}
//取得磁盘信息 传入参数如:getdiskinfo('c')
function getdiskinfo(para)
{
var fs=new ActiveXObject("scripting.filesystemobject");
d=fs.GetDrive(para);
s="卷标:" + d.VolumnName;
s+="------" + "剩余空间:" + d.FreeSpace/1024/1024 + "M";
s+="------" + "磁盘序列号:" + d.serialnumber;
alert(s)
}
//取得系统目录
function getprocessnum()
{
var pnsys=new ActiveXObject("WScript.shell");
pn=pnsys.Environment("PROCESS");
alert(pn("WINDIR"));
}
//启动计算器
function runcalc()
{
var calc=new ActiveXObject("WScript.shell");
calc.Run("calc");
}
//读取注册表中的值
function readreg()
{
var myreadreg=new ActiveXObject("WScript.shell");
try{
alert(myreadreg.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\NeroCheck"));
}
catch(e)
{
alert("读取的值不存在!");
}
}
//写注册表
function writereg()
{
var mywritereg=new ActiveXObject("WScript.shell");
try{
mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe");
alert("写入成功!");
}
catch(e)
{
alert("写入路径不正确!");
}
}
//删除注册表
function delreg()
{
var mydelreg=new ActiveXObject("WScript.shell");
if(confirm("是否真的删除?"))
{
try{
mydelreg.RegDelete("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest");
alert("删除成功!");
}
catch(e)
{
alert("删除路径不正确");
}
}
}
//取得计算机名域名用户名
function netinfo()
{
var mynetinfo=new ActiveXObject("WScript.network");
alert("计算机名:"+mynetinfo.ComputerName+"域名:"+mynetinfo.UserDomain+"用户名:"+mynetinfo.UserName);
}
//返回系统中特殊目录的路径 (Fonts,AllUsersDesktop,Desktop,MyDocuments,Recent.....)
function getspecialfolder()
{
var mygetfolder=new ActiveXObject("WScript.shell");
if(mygetfolder.SpecialFolders("Fonts")!=null)
{
alert(mygetfolder.SpecialFolders("Fonts"));
}
}
//取得文件信息 调用方式如:getfileinfo('E:\\MyPlace\\TEST\\myjs.htm')
function getfileinfo(para)
{
var myfile=new ActiveXObject("scripting.filesystemobject");
var fi=myfile.GetFile(para);
alert("文件类型:"+fi.type+"文件大小:"+fi.size/1024/1024+"M"+"最后一次访问时间:"+fi.DateLastAccessed);
}
//取得客户端的信息
function clientInfo()
{
strClientInfo="availHeight= "+window.screen.availHeight+"\n"+
"availWidth= "+window.screen.availWidth+"\n"+
"bufferDepth= "+window.screen.bufferDepth+"\n"+
"colorDepth= "+window.screen.colorDepth+"\n"+
"colorEnable= "+window.navigator.cookieEnabled+"\n"+
"cpuClass= "+window.navigator.cpuClass+"\n"+
"height= "+window.screen.height+"\n"+
"javaEnable= "+window.navigator.javaEnabled()+"\n"+
"platform= "+window.navigator.platform+"\n"+
"systemLanguage= "+window.navigator.systemLanguage+"\n"+
"userLanguage= "+window.navigator.userLanguage+"\n"+
"width= "+window.screen.width;
alert(strClientInfo);
}
//Dilog Helper对象的使用
function changeColor()//Dilog Helper对象的使用之调用系统调色板
{
var sColor=dlgHelper.choosecolordlg();
sColor=sColor.toString(16);
if (sColor.length < 6) {
var sTempString = "000000".substring(0,6-sColor.length);
sColor = sTempString.concat(sColor);
}
alert(sColor);
mybody.style.backgroundColor=sColor;
}
function getFonts()//Dilog Helper对象的使用之取得系统支持的字体
{
var strFonts="";
for(var i=1;i<dlgHelper.fonts.count;i++)
{
strFonts=strFonts+dlgHelper.fonts(i)+"|";
}
alert(strFonts);
}
function getBlockFormat()//Dilog Helper对象的使用之取得系统中块的格式信息(如:标题1、标题2....)
{
var strBlockFormat="";
for(var i=1;i<dlgHelper.BlockFormats.count;i++)
{
strBlockFormat=strBlockFormat+dlgHelper.BlockFormats(i)+"|";
}
alert(strBlockFormat);
}
function createTxtLink()//给选中的文本创建链接
{
var sText=document.selection.createRange();
if(sText.text!="")
{
document.execCommand("CreateLink");
if(sText.parentElement().tagName=="A")
{
sText.parentElement().innerText=sText.parentElement().href;
document.execCommand("ForeColor",false,"#ffff00");
}
}
}
//以下为取得BlockFormats,填充Select(id为myselect)并根据选择不同的BlockFormat改变样式
//函数fillselect()和changeformat()
//对execCommand的一点说明:Executes a command over the given selection or text range
function fillselect()
{
var item=document.createElement("OPTION")
item.text="请选择";
item.value="";
myselect.add(item);
for(var i=1;i<dlgHelper.BlockFormats.count;i++)
{
item=document.createElement("OPTION");
item.text=dlgHelper.BlockFormats(i);
item.value=dlgHelper.BlockFormats(i);
myselect.add(item);
}
}
function changeformat()
{
var sSelect=myselect.options[myselect.selectedIndex].value;
document.execCommand("FormatBlock",false,sSelect);
}
//取得驱动器类型,调用如:ShowDriveType('c:')
function ShowDriveType(drvpath)
{
fs=new ActiveXObject("scripting.filesystemobject");
disk=fs.GetDrive(drvpath);
var whichtype="";
switch(disk.DriveType)
{
case 0:
whichtype="Unknown"
break
case 1:
whichtype="Removable"
break
case 2:
whichtype="Fixed"
break
case 3:
whichtype="Network"
break
case 4:
whichtype="CD-ROM"
break
case 5:
whichtype="RAM Disk"
}
alert(whichtype);
//显示磁盘的SerialNumber
try{
alert(disk.SerialNumber);
}
catch(e){
alert(e.message);
}
alert(disk.VolumeName);//取得卷标
}
</script>
-------------------------
<OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT>
var mywritereg=new ActiveXObject("WScript.shell");
try{
mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe");
alert("写入成功!");
}
catch(e)
{
alert("写入路径不正确!");
}
}
//删除注册表
function delreg()
{
var mydelreg=new ActiveXObject("WScript.shell");
if(confirm("是否真的删除?"))
{
try{
mydelreg.RegDelete("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest");
alert("删除成功!");
}
catch(e)
{
alert("删除路径不正确");
}
}
}
//取得计算机名域名用户名
function netinfo()
{
var mynetinfo=new ActiveXObject("WScript.network");
alert("计算机名:"+mynetinfo.ComputerName+"域名:"+mynetinfo.UserDomain+"用户名:"+mynetinfo.UserName);
}
//返回系统中特殊目录的路径 (Fonts,AllUsersDesktop,Desktop,MyDocuments,Recent.....)
function getspecialfolder()
{
var mygetfolder=new ActiveXObject("WScript.shell");
if(mygetfolder.SpecialFolders("Fonts")!=null)
{
alert(mygetfolder.SpecialFolders("Fonts"));
}
}
//取得文件信息 调用方式如:getfileinfo('E:\\MyPlace\\TEST\\myjs.htm')
function getfileinfo(para)
{
var myfile=new ActiveXObject("scripting.filesystemobject");
var fi=myfile.GetFile(para);
alert("文件类型:"+fi.type+"文件大小:"+fi.size/1024/1024+"M"+"最后一次访问时间:"+fi.DateLastAccessed);
}
//取得客户端的信息
function clientInfo()
{
strClientInfo="availHeight= "+window.screen.availHeight+"\n"+
"availWidth= "+window.screen.availWidth+"\n"+
"bufferDepth= "+window.screen.bufferDepth+"\n"+
1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="return false;" 防止复制
5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标
6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标
7. <input style="ime-mode:disabled"> 关闭输入法
8. 永远都会带着框架
<script language="javascript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script>
9. 防止被人frame
<SCRIPT LANGUAGE=javascript><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>
10. <noscript><iframe src=*.html></iframe></noscript> 网页将不能被另存为
11. <input type=button value=查看网页源代码
onclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">
12. 怎样通过asp的手段来检查来访者是否用了代理
<% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then
response.write "<font color=#FF0000>您通过了代理服务器,"& _
"真实的IP为"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
end if
%>
13 ^[-+]?\d+(\.\d+)?$
可以。。本人是用javascript写的,你可以拿来参考一下。
document.write("<div style='border: 1px solid #999999;background-color: #eeeeee;vertical-align: middle; text-
align:center;position:absolute;top:30;width:500px; height:200px;left:120;font-size:9pt;' id='loading'>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<span id='loading_text' style='margin-top:100px;color: #0066CC;'>正在查询数据,请稍等......</span>")
document.write("</div>")
document.write("<scr" + "ipt>")
document.write("function flashs(){")
document.write("if(loading_text.style.color=='#eeeeee'){")
document.write(" loading_text.style.color='#0066CC';")
document.write(" setTimeout('flashs()',500);")
document.write(" }")
document.write("else{")
document.write(" loading_text.style.color='#eeeeee';")
document.write(" setTimeout('flashs()',500);")
document.write(" }")
document.write("}")
document.write("</sc"+"ript>")
记得要先调用一次flashs()函数,否则几个中文字不会闪动。
Session State or ViewState?
There are certain cases where holding a state value in ViewState is not the best option. The most commonly used alternative is Session state, which is generally better suited for:
Large amounts of data. Since ViewState increases the size of both the page sent to the browser (the HTML payload) and the size of form posted back, it's a poor choice for storing large amounts of data.
Secure data that is not already displayed in the UI. While the ViewState data is encoded and may optionally be encrypted, your data is most secure if it is never sent to the client. So, Session state is a more secure option. (Storing the data in the database is even more secure due to the additional database credentials.
You can add SSL for even better link security.)
But if you've displayed the private data in the UI,
presumably you're already comfortable with the security of the link itself.
In this case, it is no less secure to put the same value into ViewState as well.
Objects not readily serialized into ViewState,
for example, DataSet. The ViewState serializer is optimized for a small set of common object types,
listed below. Other types that are serializable may be persisted in ViewState,
but are slower and generate a very large ViewState footprint.
<add key ="DB" value = "SQL Server"></add>
<add key ="ConnectString" value ="server=zhonghongpeng;uid=sa;pwd=sa;database=Requirement pool size=10;"/>
**//定时从一个页面转向另一个页面
在<head>区加一句:
<meta http-equiv="refresh" content="10;URL=d.htm">
在 content 中,前面是时间,后面是要转向的页面地址
<controller.mapping>
<entries>
<entry key="/patterns/frontc/3/Page1.aspx" url="ActualPage1.aspx" />
<entry key="/patterns/frontc/3/Page2.aspx" url="ActualPage2.aspx" />
</entries>
</controller.mapping>
<httpHandlers>
<add verb="*" path="Page*.aspx" type="Handler,FrontControler" />;
</httpHandlers>
<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<sampleSection setting1="Value1" setting2="value two"
setting3="third value" />
<section name="summary"
type="System.Configuration.SingleTagSectionHandler"/><!--"鍖婚櫌绠€浠?-->
<summary
鍖婚櫌姒傚喌="on"
涓撶浠嬬粛="on"
涓撳浠嬬粛="on"
涓€鍛ㄩ棬璇婃帓鐝?= "on"
/>
我用了一个框架做页面的,我想让用户session过期后不是让登陆页面出现在mainframe里面怎么做
加上这个
<script language="JavaScript">
<!--
function window.onload()
{
if (window.location != top.location) {
top.location = window.location;
}
if(top.document.location.href != document.location.href){
top.document.location.href = document.location.href;
}
}
//-->
</script>
'左软键
<do type="accept" label="返回上级" optional="false">
<go href="http://wap.un165.com/hswap/index.jsp?Dir=10000000000965" sendreferer="false" method="get"/>
</do>
'右软健
<do type="options" label="回首页" optional="false">
<go href="http://wap.uni-info.com.cn" sendreferer="false" method="get"/>
</do>
<browserCaps>
<result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<use var="HTTP_USER_AGENT"/>
browser=Unknown
version=0.0
majorversion=0
minorversion=0
frames=false
tables=false
cookies=false
backgroundsounds=false
vbscript=false
javascript=false
javaapplets=false
activexcontrols=false
win16=false
win32=false
beta=false
ak=false
sk=false
aol=false
crawler=false
cdf=false
gold=false
authenticodeupdate=false
tagwriter=System.Web.UI.Html32TextWriter
ecmascriptversion=0.0
msdomversion=0.0
w3cdomversion=0.0
platform=Unknown
css1=false
css2=false
xml=false
mobileDeviceManufacturer = "Unknown"
mobileDeviceModel = "Unknown"
gatewayVersion = "None"
gatewayMajorVersion = "0"
gatewayMinorVersion = "0"
preferredRenderingType = "wml11"
preferredRenderingMime = "text/vnd.wap.wml"
preferredImageMime = "image/vnd.wap.wbmp"
defaultScreenCharactersWidth = "12"
defaultScreenCharactersHeight = "6"
defaultScreenPixelsWidth = "96"
defaultScreenPixelsHeight = "72"
defaultCharacterWidth = "8"
defaultCharacterHeight = "12"
screenBitDepth = "1"
isColor = "false"
inputType = "telephoneKeypad"
numberOfSoftkeys = "0"
maximumSoftkeyLabelLength = "5"
canInitiateVoiceCall = "false"
canSendMail = "true"
hasBackButton = "true"
rendersWmlDoAcceptsInline = "true"
rendersWmlSelectsAsMenuCards = "false"
rendersBreaksAfterWmlAnchor = "false"
rendersBreaksAfterWmlInput = "false"
rendersBreakBeforeWmlSelectAndInput = "false"
requiresAttributeColonSubstitution = "false"
requiresPhoneNumbersAsPlainText = "false"
requiresUrlEncodedPostfieldValues = "false"
requiredMetaTagNameValue = ""
rendersBreaksAfterHtmlLists = "true"
requiresUniqueHtmlCheckboxNames = "false"
requiresUniqueHtmlInputNames = "false"
requiresUniqueFilePathSuffix = "false"
supportsCss = "false"
hidesRightAlignedMultiselectScrollbars = "false"
canRenderAfterInputOrSelectElement = "true"
canRenderInputAndSelectElementsTogether = "true"
canRenderOneventAndPrevElementsTogether = "true"
canCombineFormsInDeck = "true"
canRenderMixedSelects = "true"
canRenderPostBackCards = "true"
canRenderSetvarZeroWithMultiSelectionList = "true"
supportsImageSubmit = "false"
supportsSelectMultiple = "true"
requiresHtmlAdaptiveErrorReporting = "false"
requiresContentTypeMetaTag = "false"
requiresDBCSCharacter = "false"
requiresOutputOptimization = "false"
supportsAccesskeyAttribute = "false"
supportsInputIStyle = "false"
supportsInputMode = "false"
supportsIModeSymbols = "false"
supportsJPhoneSymbols = "false"
supportsJPhoneMultiMediaAttributes = "false"
maximumRenderedPageSize = "2000"
requiresSpecialViewStateEncoding = "false"
requiresNoBreakInFormatting = "false"
requiresLeadingPageBreak = "false"
supportsQueryStringInFormAction = "true"
supportsCacheControlMetaTag = "true"
supportsUncheck = "true"
canRenderEmptySelects = "true"
supportsRedirectWithCookie = "true"
supportsEmptyStringInCookieValue = "true"
cachesAllResponsesWithExpires = "false"
requiresNoSoftkeyLabels = "false"
defaultSubmitButtonLimit = "1"
supportsBold = "false"
supportsItalic = "false"
supportsFontSize = "false"
supportsFontName = "false"
supportsFontColor = "true"
supportsBodyColor = "true"
supportsDivAlign = "true"
supportsDivNoWrap = "false"
supportsCharacterEntityEncoding = "true"
isMobileDevice="false"
</browserCaps>
在ASP.NET中嵌入wml标记
用ASP.NET开发WAP程序,使用Mobile Control很方便,也比较容易上手,可是有时候想利用wml的一些元素,有不想很费劲的写adapter。比如:想在页面中添加一个wml的prev元素,如果用wml直接写就可以写成 <anchor title="Back">Back<prev /></anchor>
可是在一个mobile form中如何添加呢?我试了这么几种方法:
1、直接利用Response。就是在该MobileWebForm的Page_Load里面填写
string aa = "<card id=\"card1\" title=\"Title\">";
aa += "<P>";
aa += "<anchor title=\"back\">返回<prev/></anchor>";
aa += "</P>";
Response.Write(aa);
当然应该加一些设备兼容性的工作,这里省略。
这样做的问题是,这样写出来的东西肯定是在页面的最顶端。
2、利用Application_EndRequest
要想将内容放到最后,就要在Response的内容Render完之后再添加,不过直接将上面的代码放到这个事件中,在Openwave中却显示不出来,可能是因为openwave认为这个card已经在结束标志之后了,所以这样做了一下。
在Page_Load中写
string aa = "<card id=\"card1\" title=\"Title\">";
Response.Write(aa);
然后再EndRequest中写
if(this.Request.FilePath.IndexOf("yourmobileform.aspx") != -1)
{
string aa += "<P>";
aa += "<anchor title=\"back\">返回<prev/></anchor>";
aa += "</P>";
Response.Write(aa);
}
就把Openwave骗过去了
3、使用DeviceSpecific控件。
这种方法属于正统解决方法。在Form上拖一个Devicespecific控件,设计为
<mobile:DeviceSpecific id="DeviceSpecific2" runat="server">
<Choice Filter="isWML11">
<FooterTemplate>
<P>
<anchor title="back">返回<prev /></anchor>
</P>
</FooterTemplate>
</Choice>
</mobile:DeviceSpecific>
可能是我不怎么会用Openwave的缘故,openwave不理会我上面的东西。后来就自己加了一个设备筛选器,判断isMobileDevice=true。这样就可以了。
用<FooterTemplate>放在最后,用<HeaderTemplate>和<ScriptTemplate>都放在最上面了。
4、还有就是写自己的Adapter,这个从略,我试过HtmlAdapter,没问题,但是写了一个Wml的Adapter, openwave不理会的,搞不大明白openwave究竟接收什么类型的东西。
做一些补充,前面说的都是放在最前或者最后,要是放在中间怎么办。
可以在Form上放一个Panel,然后将这个DeviceSpecific放在这个panel中,然后在<ContentTemplate>中放wml内容
<P><anchor title="ddd">3eee<prev /></anchor></P>
这后面就可以放你要放的东西了
比如<mobile:Label id="Label1" runat="server">Label</mobile:Label>
可是这个Label不能被代码访问到,所以需要手动添加事件
<mobile:Label id="Label1" runat="server" OnLoad="SetText">Label</mobile:Label>
然后在.cs中加入这个函数实现
public void SetText(object sender,System.EventArgs e)
{
(sender as System.Web.UI.MobileControls.Label).Text = "dkkd";
}
继续更新(2004.9.9)
要放在中间,不一定要用DeviceSpecific,我们可以使用自定义控件来实现,比如我们可以从Label派生一个出来,然后重载OnRender
protected override void OnRender(System.Web.UI.HtmlTextWriter writer)
{
if(this.MobilePage.Device.PreferredRenderingType == "xhtml-mp" ||
this.MobilePage.Device.PreferredRenderingType == "wml11")
{
writer.WriteBeginTag("anchor");
writer.Write(" title=\"" + this.title + "\">" + this.Text);
writer.WriteBeginTag("prev");
writer.WriteEndTag("prev");
writer.WriteEndTag("anchor"); }
else
base.OnRender(writer);
}
然后将这个控件拖到Form中就可以实现了
'Alter session set NLS_LANGUAGE=American';
3> sql "ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''";
telnet IP:port
x=getOutputStream();
x.write(MT指令);
1. 数据验证
public static bool ValidateUserid(string inString)
{
Regex r = new Regex("^[A-Za-z0-9]{8}$");
return r.IsMatch(inString)
}
^[A-Za-z0-9]{8}$ 8个字的种子
2. 后期绑定
<%# DataBinder.Eval(Container.DataItem,"price","{0:c}") %> 货币格式
3. 注册客户端脚本
string sClose = null;
sClose = @"<script language = javascript>
window.close();
</script>";
RegisterClientScriptBlock("clsBlock",sClose);
4. 访问DataGrid的模板控件
(CheckBox)dgd.Items[i].Cells[0].Controls[1];
5. 给服务器控件增加客户端属性
DataGrid1.Attributes.Add("ondblclick","window.open('Require.aspx')"); ---双击事件
DataGrid1.Attributes.Add("onclick","window.open('Require.aspx')"); ---单击事件
6. 客户端日期控件(javascript)
7. 视图状态的应用
不要用static,而用viewstate保存数据. 不需要时禁用控件的viewstate.
8. 数据验证控件应用
9. 模态页面与非模态页面
10. 页面之间的值传递, 引用传递.
11.
RegisterStartupScript() 方法可用于添加要在加载页面后运行的脚本块。
通过这种方法添加的脚本块位于 Web 窗体的结尾处,
因为必须在脚本运行前定义脚本要修改的 HTML 元素。
也就是说,如果您要使用客户端脚本将焦点设置到文本框,
必须确保文本框的 HTML 标记位于设置该文本框的焦点的脚本之前。
例如,下面的 HTML 将显示一个文本框,并将焦点设置到该文本框:
<input type="text" id="myTextBox" />
<script language="JavaScript">
<!--
document.getElementById("myTextBox").focus();
// -->
</script>
相反,以下 HTML 不会将焦点设置到文本框,因为文本框是在脚本块“之后”定义的:
<script language="JavaScript">
<!--
document.getElementById("myTextBox").focus();
// -->
</script>
<input type="text" id="myTextBox" />
12.
如果使用这个关键字调用两次 RegisterClientScriptBlock() 或 RegisterStartupScript() 方法,
则第二次调用会被认为是复制脚本块而被忽略
那些显示为 HTML 元素的服务器控件,
如 TextBox、Button、DataGrid 等等,是从 System.Web.UI.WebControls.WebControl 类导出的,
而那些不产生 HTML 元素的控件,如 Literal、Repeater 等,是从 System.Web.UI.Control 类导出的。
13.
请注意,onclick 事件将返回 confirm() 函数调用的结果。
当通过单击提交按钮来提交表单时,
如果提交按钮的 onclick 事件返回 False,则表单未被提交。
因此,只有在用户确认后,可以使用 confirm() 函数提交表单
14.ViewState 一般用法
bool SortAscending {
get {
object o = ViewState["SortAscending"];
if (o == null) {
return true;
}
return (bool)o;
}
set {
ViewState["SortAscending"] = value;
}
}
15.总是在裁人,简称总裁;老是板着脸,故称老板;经常不理人那叫经理。
16.
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem,"yymc") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
17.文件上传
<%@ Page language="c#" Codebehind="UpLoad.aspx.cs" AutoEventWireup="false" Inherits="WebPortal.Upload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>多文件上传</title>
<script language="JavaScript">
function addFile()
{
var str = '<INPUT type="file" size="50" NAME="File">'
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<div align="center">
<h3>多文件上传</h3>
<P id="MyFile"><INPUT type="file" size="50" NAME="File"></P>
<P>
<input type="button" value="增加(Add)" onclick="addFile()">
<input onclick="this.form.reset()" type="button" value="重置(ReSet)">
<asp:Button Runat="server" Text="开始上传" ID="UploadButton"></asp:Button>
</P>
<P>
<asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="9pt"
Width="500px" BorderStyle="None" BorderColor="White"></asp:Label>
</P>
</div>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebPortal
{
/// <summary>
/// UpLoad 的摘要说明。
/// 实现多文件上传
/// </summary>
public class Upload : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button UploadButton;
protected System.Web.UI.WebControls.Label strStatus;
private void Page_Load(object sender, System.EventArgs e)
{
/// 在此处放置用户代码以初始化页面
if (this.IsPostBack) this.SaveImages();
}
private Boolean SaveImages()
{
///'遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
/// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch(System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ID = "Upload";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
18. 上传文件到oracle数据库
void uploadFile()
{
FileStream objFs = new FileStream(File1.Value,FileMode.Open, FileAccess.Read);
BinaryReader objBr = new BinaryReader(objFs);
byte [] bytFile = objBr.ReadBytes((int)objFs.Length);
OracleConnection objOconn = new OracleConnection("user id=system;Data Source=tsems;password=system");
objOconn.Open();
OracleCommand objOcmd = new OracleCommand();
objOcmd.Connection = objOconn;
objOcmd.CommandText = "INSERT INTO HR.TESTFILEUPLOAD VALUES(:VPKID,:VFILENAME , :VFILE)";
objOcmd.Parameters.Add("VPKID", OracleType.VarChar);
objOcmd.Parameters["VPKID"].Value = "2006";
objOcmd.Parameters.Add("VFILENAME",OracleType.VarChar);
objOcmd.Parameters["VFILENAME"].Value = Path.GetFileName(File1.Value);
objOcmd.Parameters.Add("VFILE",OracleType.Blob,bytFile.Length);
objOcmd.Parameters["VFILE"].Value = bytFile;
objOcmd.ExecuteNonQuery();
objOconn.Close();
Response.Write("true");
}
19. 取得查询字符串value (javascript)
function getQuery(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return unescape(r[2]); return null;
}
getQuery("fb")
20.
onmouseout="this.bgColor=document.getElementById('DataGrid1').getAttribute('singleValue')"
21. Response.Write("<Script>document.parentWindow.location.reload();</script>");
22. 从oracle下载数据
将Oracle数据库中HR方案下的TESTFILEUPLOAD表中的文件下载至系统临时目录。
void downloadFile()
{
OracleConnection objOcon = new OracleConnection("user id=system;Data Source=tsems;password=system");
OracleCommand objOcmd = new OracleCommand();
objOcmd.Connection = objOcon;
objOcmd.CommandText = "SELECT * FROM HR.TESTFILEUPLOAD WHERE PKID='2006'";
FileStream objFs;
BinaryWriter objBw;
int bufferSize = 260;
byte [] outByte = new byte[bufferSize];
long retval;
long startIndex = 0;
string fileName = "";
objOcon.Open();
OracleDataReader objDr = objOcmd.ExecuteReader(CommandBehavior.SequentialAccess);
objDr.Read();
fileName = objDr["FILENAME"].ToString();
objFs = new FileStream(Path.GetTempPath()+fileName, FileMode.OpenOrCreate,FileAccess.Write);
objBw = new BinaryWriter(objFs);
startIndex = 0;
retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
while ( retval == bufferSize)
{
objBw.Write(outByte);
objBw.Flush();
startIndex += bufferSize;
retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
}
objBw.Write(outByte, 0, (int)retval -1);
objBw.Flush();
objBw.Close();
objFs.Close();
bjDr.Close();
objOcon.Close();
}
23. 客户端调用
function IsSaveMessageBox(strMessage)
{
if (confirm(strMessage))
{
__doPostBack('btnSave','');
}
}
24
<script language="jscript">
//取得网络上的打印机
function getnetprinter()
{
var obj=new ActiveXObject("WScript.Network");
var netprinter=obj.EnumPrinterConnections();
for(i=0;i<netprinter.Count();i+=2)
{
document.writeln(netprinter.Item(i)+"="+netprinter.Item(i+1));
}
}
//取得磁盘信息 传入参数如:getdiskinfo('c')
function getdiskinfo(para)
{
var fs=new ActiveXObject("scripting.filesystemobject");
d=fs.GetDrive(para);
s="卷标:" + d.VolumnName;
s+="------" + "剩余空间:" + d.FreeSpace/1024/1024 + "M";
s+="------" + "磁盘序列号:" + d.serialnumber;
alert(s)
}
//取得系统目录
function getprocessnum()
{
var pnsys=new ActiveXObject("WScript.shell");
pn=pnsys.Environment("PROCESS");
alert(pn("WINDIR"));
}
//启动计算器
function runcalc()
{
var calc=new ActiveXObject("WScript.shell");
calc.Run("calc");
}
//读取注册表中的值
function readreg()
{
var myreadreg=new ActiveXObject("WScript.shell");
try{
alert(myreadreg.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\NeroCheck"));
}
catch(e)
{
alert("读取的值不存在!");
}
}
//写注册表
function writereg()
{
var mywritereg=new ActiveXObject("WScript.shell");
try{
mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe");
alert("写入成功!");
}
catch(e)
{
alert("写入路径不正确!");
}
}
//删除注册表
function delreg()
{
var mydelreg=new ActiveXObject("WScript.shell");
if(confirm("是否真的删除?"))
{
try{
mydelreg.RegDelete("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest");
alert("删除成功!");
}
catch(e)
{
alert("删除路径不正确");
}
}
}
//取得计算机名域名用户名
function netinfo()
{
var mynetinfo=new ActiveXObject("WScript.network");
alert("计算机名:"+mynetinfo.ComputerName+"域名:"+mynetinfo.UserDomain+"用户名:"+mynetinfo.UserName);
}
//返回系统中特殊目录的路径 (Fonts,AllUsersDesktop,Desktop,MyDocuments,Recent.....)
function getspecialfolder()
{
var mygetfolder=new ActiveXObject("WScript.shell");
if(mygetfolder.SpecialFolders("Fonts")!=null)
{
alert(mygetfolder.SpecialFolders("Fonts"));
}
}
//取得文件信息 调用方式如:getfileinfo('E:\\MyPlace\\TEST\\myjs.htm')
function getfileinfo(para)
{
var myfile=new ActiveXObject("scripting.filesystemobject");
var fi=myfile.GetFile(para);
alert("文件类型:"+fi.type+"文件大小:"+fi.size/1024/1024+"M"+"最后一次访问时间:"+fi.DateLastAccessed);
}
//取得客户端的信息
function clientInfo()
{
strClientInfo="availHeight= "+window.screen.availHeight+"\n"+
"availWidth= "+window.screen.availWidth+"\n"+
"bufferDepth= "+window.screen.bufferDepth+"\n"+
"colorDepth= "+window.screen.colorDepth+"\n"+
"colorEnable= "+window.navigator.cookieEnabled+"\n"+
"cpuClass= "+window.navigator.cpuClass+"\n"+
"height= "+window.screen.height+"\n"+
"javaEnable= "+window.navigator.javaEnabled()+"\n"+
"platform= "+window.navigator.platform+"\n"+
"systemLanguage= "+window.navigator.systemLanguage+"\n"+
"userLanguage= "+window.navigator.userLanguage+"\n"+
"width= "+window.screen.width;
alert(strClientInfo);
}
//Dilog Helper对象的使用
function changeColor()//Dilog Helper对象的使用之调用系统调色板
{
var sColor=dlgHelper.choosecolordlg();
sColor=sColor.toString(16);
if (sColor.length < 6) {
var sTempString = "000000".substring(0,6-sColor.length);
sColor = sTempString.concat(sColor);
}
alert(sColor);
mybody.style.backgroundColor=sColor;
}
function getFonts()//Dilog Helper对象的使用之取得系统支持的字体
{
var strFonts="";
for(var i=1;i<dlgHelper.fonts.count;i++)
{
strFonts=strFonts+dlgHelper.fonts(i)+"|";
}
alert(strFonts);
}
function getBlockFormat()//Dilog Helper对象的使用之取得系统中块的格式信息(如:标题1、标题2....)
{
var strBlockFormat="";
for(var i=1;i<dlgHelper.BlockFormats.count;i++)
{
strBlockFormat=strBlockFormat+dlgHelper.BlockFormats(i)+"|";
}
alert(strBlockFormat);
}
function createTxtLink()//给选中的文本创建链接
{
var sText=document.selection.createRange();
if(sText.text!="")
{
document.execCommand("CreateLink");
if(sText.parentElement().tagName=="A")
{
sText.parentElement().innerText=sText.parentElement().href;
document.execCommand("ForeColor",false,"#ffff00");
}
}
}
//以下为取得BlockFormats,填充Select(id为myselect)并根据选择不同的BlockFormat改变样式
//函数fillselect()和changeformat()
//对execCommand的一点说明:Executes a command over the given selection or text range
function fillselect()
{
var item=document.createElement("OPTION")
item.text="请选择";
item.value="";
myselect.add(item);
for(var i=1;i<dlgHelper.BlockFormats.count;i++)
{
item=document.createElement("OPTION");
item.text=dlgHelper.BlockFormats(i);
item.value=dlgHelper.BlockFormats(i);
myselect.add(item);
}
}
function changeformat()
{
var sSelect=myselect.options[myselect.selectedIndex].value;
document.execCommand("FormatBlock",false,sSelect);
}
//取得驱动器类型,调用如:ShowDriveType('c:')
function ShowDriveType(drvpath)
{
fs=new ActiveXObject("scripting.filesystemobject");
disk=fs.GetDrive(drvpath);
var whichtype="";
switch(disk.DriveType)
{
case 0:
whichtype="Unknown"
break
case 1:
whichtype="Removable"
break
case 2:
whichtype="Fixed"
break
case 3:
whichtype="Network"
break
case 4:
whichtype="CD-ROM"
break
case 5:
whichtype="RAM Disk"
}
alert(whichtype);
//显示磁盘的SerialNumber
try{
alert(disk.SerialNumber);
}
catch(e){
alert(e.message);
}
alert(disk.VolumeName);//取得卷标
}
</script>
-------------------------
<OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT>
var mywritereg=new ActiveXObject("WScript.shell");
try{
mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe");
alert("写入成功!");
}
catch(e)
{
alert("写入路径不正确!");
}
}
//删除注册表
function delreg()
{
var mydelreg=new ActiveXObject("WScript.shell");
if(confirm("是否真的删除?"))
{
try{
mydelreg.RegDelete("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest");
alert("删除成功!");
}
catch(e)
{
alert("删除路径不正确");
}
}
}
//取得计算机名域名用户名
function netinfo()
{
var mynetinfo=new ActiveXObject("WScript.network");
alert("计算机名:"+mynetinfo.ComputerName+"域名:"+mynetinfo.UserDomain+"用户名:"+mynetinfo.UserName);
}
//返回系统中特殊目录的路径 (Fonts,AllUsersDesktop,Desktop,MyDocuments,Recent.....)
function getspecialfolder()
{
var mygetfolder=new ActiveXObject("WScript.shell");
if(mygetfolder.SpecialFolders("Fonts")!=null)
{
alert(mygetfolder.SpecialFolders("Fonts"));
}
}
//取得文件信息 调用方式如:getfileinfo('E:\\MyPlace\\TEST\\myjs.htm')
function getfileinfo(para)
{
var myfile=new ActiveXObject("scripting.filesystemobject");
var fi=myfile.GetFile(para);
alert("文件类型:"+fi.type+"文件大小:"+fi.size/1024/1024+"M"+"最后一次访问时间:"+fi.DateLastAccessed);
}
//取得客户端的信息
function clientInfo()
{
strClientInfo="availHeight= "+window.screen.availHeight+"\n"+
"availWidth= "+window.screen.availWidth+"\n"+
"bufferDepth= "+window.screen.bufferDepth+"\n"+
1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="return false;" 防止复制
5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标
6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标
7. <input style="ime-mode:disabled"> 关闭输入法
8. 永远都会带着框架
<script language="javascript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script>
9. 防止被人frame
<SCRIPT LANGUAGE=javascript><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>
10. <noscript><iframe src=*.html></iframe></noscript> 网页将不能被另存为
11. <input type=button value=查看网页源代码
onclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">
12. 怎样通过asp的手段来检查来访者是否用了代理
<% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then
response.write "<font color=#FF0000>您通过了代理服务器,"& _
"真实的IP为"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
end if
%>
13 ^[-+]?\d+(\.\d+)?$
可以。。本人是用javascript写的,你可以拿来参考一下。
document.write("<div style='border: 1px solid #999999;background-color: #eeeeee;vertical-align: middle; text-
align:center;position:absolute;top:30;width:500px; height:200px;left:120;font-size:9pt;' id='loading'>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write("<span id='loading_text' style='margin-top:100px;color: #0066CC;'>正在查询数据,请稍等......</span>")
document.write("</div>")
document.write("<scr" + "ipt>")
document.write("function flashs(){")
document.write("if(loading_text.style.color=='#eeeeee'){")
document.write(" loading_text.style.color='#0066CC';")
document.write(" setTimeout('flashs()',500);")
document.write(" }")
document.write("else{")
document.write(" loading_text.style.color='#eeeeee';")
document.write(" setTimeout('flashs()',500);")
document.write(" }")
document.write("}")
document.write("</sc"+"ript>")
记得要先调用一次flashs()函数,否则几个中文字不会闪动。
Session State or ViewState?
There are certain cases where holding a state value in ViewState is not the best option. The most commonly used alternative is Session state, which is generally better suited for:
Large amounts of data. Since ViewState increases the size of both the page sent to the browser (the HTML payload) and the size of form posted back, it's a poor choice for storing large amounts of data.
Secure data that is not already displayed in the UI. While the ViewState data is encoded and may optionally be encrypted, your data is most secure if it is never sent to the client. So, Session state is a more secure option. (Storing the data in the database is even more secure due to the additional database credentials.
You can add SSL for even better link security.)
But if you've displayed the private data in the UI,
presumably you're already comfortable with the security of the link itself.
In this case, it is no less secure to put the same value into ViewState as well.
Objects not readily serialized into ViewState,
for example, DataSet. The ViewState serializer is optimized for a small set of common object types,
listed below. Other types that are serializable may be persisted in ViewState,
but are slower and generate a very large ViewState footprint.
<add key ="DB" value = "SQL Server"></add>
<add key ="ConnectString" value ="server=zhonghongpeng;uid=sa;pwd=sa;database=Requirement pool size=10;"/>
**//定时从一个页面转向另一个页面
在<head>区加一句:
<meta http-equiv="refresh" content="10;URL=d.htm">
在 content 中,前面是时间,后面是要转向的页面地址
<controller.mapping>
<entries>
<entry key="/patterns/frontc/3/Page1.aspx" url="ActualPage1.aspx" />
<entry key="/patterns/frontc/3/Page2.aspx" url="ActualPage2.aspx" />
</entries>
</controller.mapping>
<httpHandlers>
<add verb="*" path="Page*.aspx" type="Handler,FrontControler" />;
</httpHandlers>
<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<sampleSection setting1="Value1" setting2="value two"
setting3="third value" />
<section name="summary"
type="System.Configuration.SingleTagSectionHandler"/><!--"鍖婚櫌绠€浠?-->
<summary
鍖婚櫌姒傚喌="on"
涓撶浠嬬粛="on"
涓撳浠嬬粛="on"
涓€鍛ㄩ棬璇婃帓鐝?= "on"
/>
我用了一个框架做页面的,我想让用户session过期后不是让登陆页面出现在mainframe里面怎么做
加上这个
<script language="JavaScript">
<!--
function window.onload()
{
if (window.location != top.location) {
top.location = window.location;
}
if(top.document.location.href != document.location.href){
top.document.location.href = document.location.href;
}
}
//-->
</script>
'左软键
<do type="accept" label="返回上级" optional="false">
<go href="http://wap.un165.com/hswap/index.jsp?Dir=10000000000965" sendreferer="false" method="get"/>
</do>
'右软健
<do type="options" label="回首页" optional="false">
<go href="http://wap.uni-info.com.cn" sendreferer="false" method="get"/>
</do>
<browserCaps>
<result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<use var="HTTP_USER_AGENT"/>
browser=Unknown
version=0.0
majorversion=0
minorversion=0
frames=false
tables=false
cookies=false
backgroundsounds=false
vbscript=false
javascript=false
javaapplets=false
activexcontrols=false
win16=false
win32=false
beta=false
ak=false
sk=false
aol=false
crawler=false
cdf=false
gold=false
authenticodeupdate=false
tagwriter=System.Web.UI.Html32TextWriter
ecmascriptversion=0.0
msdomversion=0.0
w3cdomversion=0.0
platform=Unknown
css1=false
css2=false
xml=false
mobileDeviceManufacturer = "Unknown"
mobileDeviceModel = "Unknown"
gatewayVersion = "None"
gatewayMajorVersion = "0"
gatewayMinorVersion = "0"
preferredRenderingType = "wml11"
preferredRenderingMime = "text/vnd.wap.wml"
preferredImageMime = "image/vnd.wap.wbmp"
defaultScreenCharactersWidth = "12"
defaultScreenCharactersHeight = "6"
defaultScreenPixelsWidth = "96"
defaultScreenPixelsHeight = "72"
defaultCharacterWidth = "8"
defaultCharacterHeight = "12"
screenBitDepth = "1"
isColor = "false"
inputType = "telephoneKeypad"
numberOfSoftkeys = "0"
maximumSoftkeyLabelLength = "5"
canInitiateVoiceCall = "false"
canSendMail = "true"
hasBackButton = "true"
rendersWmlDoAcceptsInline = "true"
rendersWmlSelectsAsMenuCards = "false"
rendersBreaksAfterWmlAnchor = "false"
rendersBreaksAfterWmlInput = "false"
rendersBreakBeforeWmlSelectAndInput = "false"
requiresAttributeColonSubstitution = "false"
requiresPhoneNumbersAsPlainText = "false"
requiresUrlEncodedPostfieldValues = "false"
requiredMetaTagNameValue = ""
rendersBreaksAfterHtmlLists = "true"
requiresUniqueHtmlCheckboxNames = "false"
requiresUniqueHtmlInputNames = "false"
requiresUniqueFilePathSuffix = "false"
supportsCss = "false"
hidesRightAlignedMultiselectScrollbars = "false"
canRenderAfterInputOrSelectElement = "true"
canRenderInputAndSelectElementsTogether = "true"
canRenderOneventAndPrevElementsTogether = "true"
canCombineFormsInDeck = "true"
canRenderMixedSelects = "true"
canRenderPostBackCards = "true"
canRenderSetvarZeroWithMultiSelectionList = "true"
supportsImageSubmit = "false"
supportsSelectMultiple = "true"
requiresHtmlAdaptiveErrorReporting = "false"
requiresContentTypeMetaTag = "false"
requiresDBCSCharacter = "false"
requiresOutputOptimization = "false"
supportsAccesskeyAttribute = "false"
supportsInputIStyle = "false"
supportsInputMode = "false"
supportsIModeSymbols = "false"
supportsJPhoneSymbols = "false"
supportsJPhoneMultiMediaAttributes = "false"
maximumRenderedPageSize = "2000"
requiresSpecialViewStateEncoding = "false"
requiresNoBreakInFormatting = "false"
requiresLeadingPageBreak = "false"
supportsQueryStringInFormAction = "true"
supportsCacheControlMetaTag = "true"
supportsUncheck = "true"
canRenderEmptySelects = "true"
supportsRedirectWithCookie = "true"
supportsEmptyStringInCookieValue = "true"
cachesAllResponsesWithExpires = "false"
requiresNoSoftkeyLabels = "false"
defaultSubmitButtonLimit = "1"
supportsBold = "false"
supportsItalic = "false"
supportsFontSize = "false"
supportsFontName = "false"
supportsFontColor = "true"
supportsBodyColor = "true"
supportsDivAlign = "true"
supportsDivNoWrap = "false"
supportsCharacterEntityEncoding = "true"
isMobileDevice="false"
</browserCaps>
在ASP.NET中嵌入wml标记
用ASP.NET开发WAP程序,使用Mobile Control很方便,也比较容易上手,可是有时候想利用wml的一些元素,有不想很费劲的写adapter。比如:想在页面中添加一个wml的prev元素,如果用wml直接写就可以写成 <anchor title="Back">Back<prev /></anchor>
可是在一个mobile form中如何添加呢?我试了这么几种方法:
1、直接利用Response。就是在该MobileWebForm的Page_Load里面填写
string aa = "<card id=\"card1\" title=\"Title\">";
aa += "<P>";
aa += "<anchor title=\"back\">返回<prev/></anchor>";
aa += "</P>";
Response.Write(aa);
当然应该加一些设备兼容性的工作,这里省略。
这样做的问题是,这样写出来的东西肯定是在页面的最顶端。
2、利用Application_EndRequest
要想将内容放到最后,就要在Response的内容Render完之后再添加,不过直接将上面的代码放到这个事件中,在Openwave中却显示不出来,可能是因为openwave认为这个card已经在结束标志之后了,所以这样做了一下。
在Page_Load中写
string aa = "<card id=\"card1\" title=\"Title\">";
Response.Write(aa);
然后再EndRequest中写
if(this.Request.FilePath.IndexOf("yourmobileform.aspx") != -1)
{
string aa += "<P>";
aa += "<anchor title=\"back\">返回<prev/></anchor>";
aa += "</P>";
Response.Write(aa);
}
就把Openwave骗过去了
3、使用DeviceSpecific控件。
这种方法属于正统解决方法。在Form上拖一个Devicespecific控件,设计为
<mobile:DeviceSpecific id="DeviceSpecific2" runat="server">
<Choice Filter="isWML11">
<FooterTemplate>
<P>
<anchor title="back">返回<prev /></anchor>
</P>
</FooterTemplate>
</Choice>
</mobile:DeviceSpecific>
可能是我不怎么会用Openwave的缘故,openwave不理会我上面的东西。后来就自己加了一个设备筛选器,判断isMobileDevice=true。这样就可以了。
用<FooterTemplate>放在最后,用<HeaderTemplate>和<ScriptTemplate>都放在最上面了。
4、还有就是写自己的Adapter,这个从略,我试过HtmlAdapter,没问题,但是写了一个Wml的Adapter, openwave不理会的,搞不大明白openwave究竟接收什么类型的东西。
做一些补充,前面说的都是放在最前或者最后,要是放在中间怎么办。
可以在Form上放一个Panel,然后将这个DeviceSpecific放在这个panel中,然后在<ContentTemplate>中放wml内容
<P><anchor title="ddd">3eee<prev /></anchor></P>
这后面就可以放你要放的东西了
比如<mobile:Label id="Label1" runat="server">Label</mobile:Label>
可是这个Label不能被代码访问到,所以需要手动添加事件
<mobile:Label id="Label1" runat="server" OnLoad="SetText">Label</mobile:Label>
然后在.cs中加入这个函数实现
public void SetText(object sender,System.EventArgs e)
{
(sender as System.Web.UI.MobileControls.Label).Text = "dkkd";
}
继续更新(2004.9.9)
要放在中间,不一定要用DeviceSpecific,我们可以使用自定义控件来实现,比如我们可以从Label派生一个出来,然后重载OnRender
protected override void OnRender(System.Web.UI.HtmlTextWriter writer)
{
if(this.MobilePage.Device.PreferredRenderingType == "xhtml-mp" ||
this.MobilePage.Device.PreferredRenderingType == "wml11")
{
writer.WriteBeginTag("anchor");
writer.Write(" title=\"" + this.title + "\">" + this.Text);
writer.WriteBeginTag("prev");
writer.WriteEndTag("prev");
writer.WriteEndTag("anchor"); }
else
base.OnRender(writer);
}
然后将这个控件拖到Form中就可以实现了
'Alter session set NLS_LANGUAGE=American';
3> sql "ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''";
telnet IP:port
x=getOutputStream();
x.write(MT指令);
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=195
这篇日志没有评论。
此日志不可发表评论。