OK. Part1:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="uploadtest.aspx.cs" Inherits="uploadtest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>无标题页</title> <script language="javascript">
function doSomething() { var doc = document.forms[0]; str=document.getElementById("FileUpload1").value; if(str=="") { alert('Please select a file which you want to upload...'); return false; }
function test() { alert(minutes); alert(seconds); alert(hours); alert(miliseconds); mydate2=new Date(); var minutes2=mydate2.getMinutes().toString(); var seconds2=mydate2.getUTCSeconds().toString(); var hours2=mydate2.getHours().toString(); var miliseconds2=mydate2.getMilliseconds().toString();
if(hours2==hours) var time1=((minutes2.valueOf()-minutes.valueOf())*60+(seconds2.valueOf()-seconds.valueOf())+(miliseconds2.valueOf()-miliseconds.valueOf())/1000); else time1=((seconds2.valueOf()-seconds.valueOf())+(miliseconds2.valueOf()-miliseconds.valueOf())/1000)+3600+(minutes2.valueOf()-minutes.valueOf())*60; var speed1=((605569/1024)/time1); var time=time1.toFixed(3); var time2=time1.toFixed(2); var speed=speed1.toFixed(2);
alert("Downloaded file size is 605569 bytes. The time used is "+time*1000+" miliseconds.\n" +"605569 bytes received in "+time2+" seconds.\nThe everage speed is "+speed+" kBytes/second, or " +speed*8+ " kpbs." ); // window.location="scalc.aspx?"+time+"&"+time2+"&"+speed; alert(filesize); alert('test last'); } </script>
part2:using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class uploadtest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // this.Button1.Attributes.Add("onClick", "return doSomething();"); } protected void Button1_Click(object sender, EventArgs e) { int filelength=0;
Asp? 不会, <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <script language="javascript">
function doSomething() { // var doc = document.forms[0]; // str=document.getElementById("FileUpload1").value; //// if(str=="") // { // alert('Please select a file which you want to upload...'); // return false; // }
mydate=new Date(); minutes=mydate.getMinutes().toString(); seconds=mydate.getSeconds().toString(); hours=mydate.getHours().toString(); miliseconds=mydate.getMilliseconds().toString(); // alert(miliseconds); //doc.submit(); } function test() { alert(window.minutes); //这里alert出来的是"undefined" alert(window.seconds); //这里alert出来的是"undefined" alert(window.hours); //这里alert出来的是"undefined" alert(window.miliseconds); mydate2=new Date(); var minutes2=mydate2.getMinutes().toString(); var seconds2=mydate2.getUTCSeconds().toString(); var hours2=mydate2.getHours().toString(); var miliseconds2=mydate2.getMilliseconds().toString(); } doSomething(); test(); </script>
<head id="Head1" runat="server">
<title>无标题页</title>
<script language="javascript">
function doSomething()
{
var doc = document.forms[0];
str=document.getElementById("FileUpload1").value;
if(str=="")
{
alert('Please select a file which you want to upload...');
return false;
}
mydate=new Date();
minutes=mydate.getMinutes().toString();
seconds=mydate.getSeconds().toString();
hours=mydate.getHours().toString();
miliseconds=mydate.getMilliseconds().toString();
doc.submit();
}
</script> <script language="javascript">
function test()
{
alert(minutes);
alert(seconds);
alert(hours);
alert(miliseconds);
mydate2=new Date();
var minutes2=mydate2.getMinutes().toString();
var seconds2=mydate2.getUTCSeconds().toString();
var hours2=mydate2.getHours().toString();
var miliseconds2=mydate2.getMilliseconds().toString();
if(hours2==hours)
var time1=((minutes2.valueOf()-minutes.valueOf())*60+(seconds2.valueOf()-seconds.valueOf())+(miliseconds2.valueOf()-miliseconds.valueOf())/1000);
else
time1=((seconds2.valueOf()-seconds.valueOf())+(miliseconds2.valueOf()-miliseconds.valueOf())/1000)+3600+(minutes2.valueOf()-minutes.valueOf())*60;
var speed1=((605569/1024)/time1); var time=time1.toFixed(3);
var time2=time1.toFixed(2);
var speed=speed1.toFixed(2);
alert("Downloaded file size is 605569 bytes. The time used is "+time*1000+" miliseconds.\n"
+"605569 bytes received in "+time2+" seconds.\nThe everage speed is "+speed+" kBytes/second, or "
+speed*8+ " kpbs." );
// window.location="scalc.aspx?"+time+"&"+time2+"&"+speed;
alert(filesize);
alert('test last');
}
</script>
</head>
<body>
<form id="form1" enctype="multipart/form-data" runat="server">
<div>
<asp:Label ID="Label2" runat="server" ForeColor="LightCoral" Text="Please select a file to upload:"></asp:Label><br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return doSomething();" OnClick="Button1_Click" /><br />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Return main page</asp:HyperLink><br />
<br />
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<br />
</div>
</form></body>
</html>
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class uploadtest : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{
// this.Button1.Attributes.Add("onClick", "return doSomething();");
}
protected void Button1_Click(object sender, EventArgs e)
{
int filelength=0;
if (FileUpload1.PostedFile != null)
{
FileUpload1.Visible = true;
string strDir = FileUpload1.PostedFile.FileName; int myPos = strDir.LastIndexOf("\\");
string strFileName;
if (myPos > 0)
strFileName = strDir.Substring(myPos);
else
{
strFileName = strDir;
strFileName="\\"+strFileName;
}
// this.Response.Write(strFileName);
string strPath;
strPath = Server.MapPath(".") + strFileName;
// this.Response.Write(strPath);
// this.Label3.Text = "保存路径: ";
// this.Label3.Text += strPath;
FileUpload1.PostedFile.SaveAs(strPath);
// this.Label2.Visible = true;
// this.Label4.Text = "文件名称: ";
// this.Label4.Text += FileUpload1.PostedFile.FileName;
// this.Label5.Text = "文件类型: ";
// this.Label5.Text += FileUpload1.PostedFile.ContentType;
// this.Label6.Text = "文件大小: ";
// this.Label6.Text += FileUpload1.PostedFile.ContentLength.ToString();
filelength = this.FileUpload1.PostedFile.ContentLength;
// string s5 = filelength.ToString();
// this.Response.Write("<script language=\"javascript\" type=\"text/javascript\">alert(1);</script>");
this.Response.Write("<script language=\"javascript\" type=\"text/javascript\">var filesize=" + filelength.ToString() + "</script>");
// this.Response.Write("<input id=\"aaaa\" type=\"hidden\" runat=\"server\" Text=\"aaa\">");
// this.Label1.Text = filelength.ToString();
// this.Label1.Visible = true;
// this.Response.Write(strPath);
// this.Response.Write("\n");
} string str;
str = "<script language='javascript'>";
str += "test()";
str += "</script>";
//Literal1.Visible=true;
Literal1.Text = str;
}}
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script language="javascript">
function doSomething()
{
// var doc = document.forms[0];
// str=document.getElementById("FileUpload1").value;
//// if(str=="")
// {
// alert('Please select a file which you want to upload...');
// return false;
// }
mydate=new Date();
minutes=mydate.getMinutes().toString();
seconds=mydate.getSeconds().toString();
hours=mydate.getHours().toString();
miliseconds=mydate.getMilliseconds().toString(); // alert(miliseconds);
//doc.submit();
}
function test()
{
alert(window.minutes); //这里alert出来的是"undefined"
alert(window.seconds); //这里alert出来的是"undefined"
alert(window.hours); //这里alert出来的是"undefined" alert(window.miliseconds);
mydate2=new Date();
var minutes2=mydate2.getMinutes().toString();
var seconds2=mydate2.getUTCSeconds().toString();
var hours2=mydate2.getHours().toString();
var miliseconds2=mydate2.getMilliseconds().toString();
}
doSomething();
test();
</script>
</head>
<body></body>
</html>写了一个HTML的。 你看看吧
doSomething()的
minutes=mydate.getMinutes().toString();
seconds=mydate.getSeconds().toString();
hours=mydate.getHours().toString();
miliseconds=mydate.getMilliseconds().toString();
1)
写Cookie/session中
执行test() 时,读出来对比
2)
赋值给<input type=hidden>--传来传去