asp.net 사용자 정의 컨트롤 은 새로 고침 없 이 업로드 그림 을 표시 하고 미리 보기 그림 을 저장 합 니 다.
5146 단어 asp.net사용자 정의 컨트롤리 셋 없 음사진 업로드
탐색 을 누 르 고 그림 을 선택 한 후 오른쪽 에 그림 을 표시 합 니 다.
첫 번 째 단계:
CtFileUpLoad.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CtFileUpLoad.ascx.cs"
Inherits="WebParts_CtFileUpLoad" %>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<iframe src="/WebParts/FileUpLoad.aspx?<%=ParsValue %>" width="240px" height="22px" frameborder="0" scrolling="no"></iframe>
</td>
<td>
<asp:TextBox runat="server" ID="tbFileName" style="display:none"></asp:TextBox>
<div id="dvImg" runat="server" style="position:absolute; margin-left:50px;">
</div>
</td>
</tr>
</table>
<script language="javascript">
function <%=ClientID %>CallLoaded()
{
<% =OnLoaded %>;
}
</script>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;
public partial class WebParts_CtFileUpLoad : System.Web.UI.UserControl
{
public bool AutoFileName
{
get
{
object ob = ViewState[ClientID + "AutoFileName"];
if (ob == null)
ob = true;
return (bool)ob;
}
set
{
ViewState[ClientID + "AutoFileName"] = value;
}
}
public string UpLoadPath
{
get
{
object ob = ViewState[ClientID + "UpLoadPath"];
if (ob == null)
ob = "UPLOADFILES";
return ob.ToString();
}
set
{
ViewState[ClientID + "UpLoadPath"] = value;
}
}
public string OnLoaded
{
get
{
object ob = ViewState[ClientID + "OnLoaded"];
if (ob == null)
ob = "";
return ob.ToString();
}
set
{
ViewState[ClientID + "OnLoaded"] = value;
}
}
public string SupportExtension
{
get
{
object ob = ViewState[ClientID + "SupportExtension"];
if (ob == null)
{
ob = "gif|png|jpeg|jpg";
}
return ob.ToString();
}
set
{
ViewState[ClientID + "SupportExtension"] = value.Replace(".", "");
}
}
public bool ShowImg
{
get
{
object ob = ViewState[ClientID + "ShowImg"];
if (ob == null)
ob = true;
return (bool)ob;
}
set
{
if ((bool)value)
dvImg.Style["display"] = "block";
else
dvImg.Style["display"] = "none";
}
}
public string FileName
{
get
{
return tbFileName.Text;
}
}
protected string ParsValue = "";
protected void Page_Load(object sender, EventArgs e)
{
ParsValue = "AutoFileName=" + AutoFileName.ToString() + "&SupportExtension=" + SupportExtension + "&UpLoadPath=" + UpLoadPath
+ "&ID=" + ClientID;
}
}
를 만 듭 니 다.두 번 째 단계:FileUpLoad.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpLoad.aspx.cs" Inherits="WebParts_FileUpLoad" %>
<!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 runat="server">
</head>
<body style="margin:0px;">
<form id="form1" runat="server">
<div>
<asp:FileUpload runat="server" ID="FileUpload1" onchange="upload(this);" />
<asp:Button runat="server" ID="btUp" style="display:none" OnClick="btUp_Click" />
</div>
</form>
</body>
</html>
<script language="javascript">
function upload(ob)
{
var expStr=/.*(<%=SupportExtension%>)$/i;
if(!expStr.test(ob.value))
{
alert(" 。
( :<%=SupportExtension%>)");
}
else
{
var btUp=document.getElementById("<%=btUp.ClientID %>");
btUp.click();
}
}
</script>
속성 을 만 듭 니 다.SupportExtension 사용자 정의 업로드 형식 을"|"로 구분 합 니 다.UpLoadPath 사용자 정의 로 서버 에 올 린 폴 더;AutoFileName ture 는 시간 에 따라 파일 이름 이 자동 으로 생 성 되 며 중복 되 지 않 음 을 표시 합 니 다.false 는 원래 의 그림 이름 을 표시 합 니 다.중복 되 는 것 은 덮어 씁 니 다.전재 출처 2009-12-24 18:39:27 by 제 학 가 를 표시 하 십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
작업 중 문제 해결 - (win 2003 asp. net) Session 과 페이지 전송 방법 으로 해결 방안 을 정상적으로 사용 할 수 없습니다.또한 F 는 처음에 우리 의 BP & IT 프로젝트 팀 이 Forms 폼 검증 을 사용 했다 고 판단 할 수 있 습 니 다. 페이지 를 뛰 어 넘 는 것 은http://hr.bingjun.cc/MyTask/MyTas...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.