成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

淺析ASP.NET多附件上傳的實現(xiàn)

開發(fā) 后端
本文介紹ASP.NET多附件上傳的實現(xiàn),以及介紹多附件上傳的原理與之類似,只不過需要事先通過腳本在頁面上動態(tài)創(chuàng)建多個input type='file'的標(biāo)簽

在寫這篇文章之前我也在Google上找到了很多有關(guān)多附件上傳的文章,有用ASP.NET多附件上傳實現(xiàn)的,也有用JSP、PHP等其它技術(shù)實現(xiàn)的,但基本前提都是事先通過js腳本來動態(tài)創(chuàng)建DOM,然后上傳的時候在服務(wù)端做一下處理,有點類似于163的郵件系統(tǒng)。文件上傳需要通過頁面的POST方法進(jìn)行提交,這個我在一次MOSS開發(fā)中iFrame表單提交的古怪問題解決一問中已經(jīng)闡述過,其中包括了如何使用頁面隱藏的iFrame來提交表單從而避免整個頁面提交到服務(wù)器而導(dǎo)致頁面的刷新。多附件上傳的原理與之類似,只不過需要事先通過腳本在頁面上動態(tài)創(chuàng)建多個input type='file'的標(biāo)簽,當(dāng)然,如果要想功能更加完美,你可能還需要通過腳本動態(tài)添加一些按鈕事件以讓用戶可以刪除他所添加的文件。下面是ASP.NET多附件上傳的實現(xiàn)


其中紅色方框內(nèi)的內(nèi)容是通過腳本在頁面上動態(tài)創(chuàng)建的,將用戶在客戶端所選文件的文件名動態(tài)添加到一個div里,同時在這個div中放一個隱藏的input type=’file’的標(biāo)簽,它的value為用戶所選文件的路徑,然后在div中放置一個img,添加onmouseover和onmouseout 事件為圖片增加了一些鼠標(biāo)滑動時的效果,onclick事件用來響應(yīng)用戶點擊img時刪除對應(yīng)的文件。看一下ASP.NET多附件上傳的代碼。

  1. <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind=
    "Default.aspx.cs"
    Inherits="WebApplication1._Default"%> 
  2.  
  3. //EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  4. <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> 
  5. <headrunatheadrunat="server"> 
  6. <title>title> 
  7. <scriptsrcscriptsrc="MultiAffix.js"type="text/javascript">script> 
  8. <scripttypescripttype="text/javascript"> 
  9. varcontrolName=1;//Thisvariableisforthedynamicfilecontrols'sname.  
  10.  
  11. functionaddImg(targetElement,savestatsElement,oldimgElement){  
  12. varbrowseimgElement=$get("browseimg");  
  13. vararr=browseimgElement.getElementsByTagName('input');  
  14. if(arr.length==0||arr[0].value.length==0){  
  15.  
  16. alert('Nofileinputs.');  
  17. return;  
  18. }  
  19. varoldbrowser=arr[0];  
  20. varfilename=getfilename(oldbrowser.value);  
  21. if(!validateimgtype(oldbrowser.value))return;  
  22. if(!validateimgcount(targetElement,3))return;  
  23. varimgtitles=savestatsElement.value+oldimgElement.value;  
  24. if(validateimgexist(filename,imgtitles))
    {alert('Youhavealreadyaddedthisimage!');return;}  
  25. if(oldbrowser!=undefined){  
  26. varnewbrowser=oldbrowser.cloneNode(true);  
  27. newbrowser.value='';  
  28. varnewfile=document.createElement('div');  
  29. newfile.innerHTML=filename+'  ';  
  30.  
  31. //Createabuttonelementfordeletetheimage.  
  32. varnewfileimgbutton=document.createElement('img');  
  33. newfileimgbutton.src='ShoutOut_Close.gif';  
  34. newfileimgbutton.alt='Delete';  
  35. newfileimgbutton.onclick=function(){  
  36. this.parentNode.parentNode.removeChild(this.parentNode);  
  37. savestatsElement.value=updatehiddenimgs(filename,savestatsElement.value);  
  38. }  
  39. newfileimgbutton.onmouseover=function(){  
  40. this.src='ShoutOut_Close_rollover.gif';  
  41. }  
  42. newfileimgbutton.onmouseout=function(){  
  43. this.src='ShoutOut_Close.gif';  
  44. }  
  45.  
  46. browseimgElement.replaceChild(newbrowser,oldbrowser);  
  47. oldbrowser.name=++controlName;  
  48. oldbrowser.style.display='none';  
  49. newfile.appendChild(oldbrowser);  
  50.  
  51. newfile.appendChild(newfileimgbutton);  
  52. targetElement.appendChild(newfile);  
  53.  
  54. $get("chkAgree").checked=false;  
  55. $get("btAdd").disabled=true;  
  56. savestatsElement.value+=filename+'|';  
  57. }  
  58. }  
  59. script> 
  60.  
  61. head> 
  62. <body> 
  63. <formidformid="form1"runat="server"> 
  64. <asp:ScriptManagerIDasp:ScriptManagerID="ScriptManager1"runat="server"> 
  65. asp:ScriptManager> 
  66. <div> 
  67. <div> 
  68. Description:  
  69. <asp:TextBoxIDasp:TextBoxID="tbDescription"MaxLength="2000"runat=
    "server"
    TextMode="MultiLine">asp:TextBox> 
  70. div> 
  71. <div> 
  72. Location:  
  73. <asp:DropDownListIDasp:DropDownListID="ddlLocation"runat="server"> 
  74. asp:DropDownList> 
  75. div> 
  76. <div> 
  77. DisplayPostedByUser:  
  78. <asp:CheckBoxIDasp:CheckBoxID="chkPostedByUser"Checked="true"runat="server"/> 
  79. div> 
  80. <div> 
  81. NotifyShoutoutUser:  
  82. <asp:CheckBoxIDasp:CheckBoxID="chkNotifyUser"runat="server"/> 
  83. div> 
  84. <div> 
  85. NotifyShoutouttoEmail:  
  86. <asp:TextBoxIDasp:TextBoxID="tbShoutoutToEmail"
    MaxLength="25"runat="server">asp:TextBox> 
  87. div> 
  88. <div> 
  89. Images:  
  90. <dividdivid="saveshoutoutimgs"runat="server"> 
  91. div> 
  92. <inputidinputid="btAddImage"type="button"onclick="$get('saveshoutoutaddimgs').
    style.display='block';this.disabled=true;"
     
  93. value="ClickheretoAddImage"/> 
  94. div> 
  95. <dividdivid="saveshoutoutdetailshowimg"> 
  96. <dividdivid="saveshoutoutaddimgs"style="display:none;"> 
  97. <div> 
  98. AddImage:div> 
  99. <dividdivid="browseimg"> 
  100. <inputtypeinputtype="file"/> 
  101. div> 
  102. <div> 
  103. Sizelimitoftheimagesis100kb.HieghtandWidthoftheimagesshouldnotexceed  
  104. 200px.div> 
  105. <div> 
  106. <inputidinputid="chkAgree"type="checkbox"onclick="$get('btAdd').
    disabled=!this.checked;"
    />I  
  107. agree.legalsignofftexttobedefined.  
  108. div> 
  109. <div> 
  110. <inputidinputid="btAdd"disabled="disabled"type="button"value="Add"runat="server"/> 
  111. div> 
  112. div> 
  113. div> 
  114. div> 
  115. <asp:TextBoxIDasp:TextBoxID="tbImgs"runat="server"Text="|"Style=
    "display:none;"
    >asp:TextBox> 
  116. <asp:TextBoxIDasp:TextBoxID="tbOldImgs"runat="server"Text="|"Style=
    "display:none;"
    >asp:TextBox> 
  117. form> 
  118. body> 
  119. html> 

【編輯推薦】

  1. ASP.NET插件的實現(xiàn)方式
  2. 概述ASP.NET應(yīng)用程序
  3. 淺談ASP.NET 2.0數(shù)據(jù)綁定
  4. ASP.NET阻止Java Script注入式攻擊
  5. ASP.NET MVC使用T4
責(zé)任編輯:佚名 來源: 51CTO博客
相關(guān)推薦

2009-06-17 10:21:34

ASP.NET多附件上

2009-07-20 16:09:39

2009-08-04 10:02:36

中國站長站

2009-07-28 10:01:16

ASP.NET Exc

2009-07-27 15:34:11

MembershipASP.NET

2009-08-05 18:36:12

ASP.NET Che

2009-07-24 13:41:15

ASP.NET AJA

2009-07-27 10:18:12

TypeResolveASP.NET

2009-07-22 18:03:00

ASP.NET ASP

2009-07-31 12:43:59

ASP.NET MVC

2009-08-05 15:50:13

ASP.NET優(yōu)點

2009-11-06 09:23:41

ASP.NET高效分頁

2009-07-24 10:53:51

ASP.NET實現(xiàn)靜態(tài)

2009-08-05 16:59:55

ASP.NET組件設(shè)計

2009-08-10 13:32:15

ASP.NET TimASP.NET組件設(shè)計

2009-07-29 14:12:45

ASP.NET tra

2009-07-29 09:34:54

IsPostBack屬ASP.NET

2009-08-04 17:16:16

ASP.NET代碼優(yōu)化

2009-08-05 16:17:29

ASP.NET For

2009-08-05 16:50:09

ASP.NET For
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 亚洲欧美在线观看 | 久久精品99 | 精品福利在线 | 一级毛片在线播放 | 国产99久久精品一区二区永久免费 | 久久精品一区二区三区四区 | 日韩一区二区三区在线视频 | 在线观看h视频 | 久久99这里只有精品 | 日韩av在线一区二区 | 欧美黑人一级爽快片淫片高清 | 国产区一区 | 久久91av| 成人h片在线观看 | www.日韩系列 | 欧美在线一区二区三区 | 一区二区三区免费 | 精品国产欧美一区二区三区成人 | av在线一区二区三区 | 日韩欧美在线一区二区 | 天天操网| 久久久久久国产精品 | 亚洲性视频网站 | 欧美日韩国产精品一区 | 国产精品一区二 | 国产精品99精品久久免费 | 精品一二| 91精品国产99久久 | 黑人巨大精品欧美一区二区免费 | 亚洲精品1区 | 亚洲国产精品成人无久久精品 | 免费特黄视频 | 精品日韩在线观看 | 欧美日在线 | 东方伊人免费在线观看 | 亚洲瑟瑟 | 不卡一区二区三区四区 | 免费在线视频精品 | 亚洲a一区| 国产精品免费一区二区三区四区 | 夜夜久久 |