//uploadFile.aspx.csusing System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace test { /// <summary> /// uploadFile 的摘要说明。 /// </summary>
public class uploadFile : UserControl { private System.Web.UI.WebControls.TextBox FileName; public string FileName_Text { get { return FileName.Text; } set { FileName.Text = value; } } protected void ButtonClick(object sender,EventArgs e) { FileName.Text = FileName_Text + "aoa"; }
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace test
{
/// <summary>
/// uploadFile 的摘要说明。
/// </summary>
public class uploadFile : UserControl
{
private System.Web.UI.WebControls.TextBox FileName; public string FileName_Text
{
get
{
return FileName.Text;
}
set
{
FileName.Text = value;
}
} protected void ButtonClick(object sender,EventArgs e)
{
FileName.Text = FileName_Text + "aoa";
}
}
}//-----------------------------------------------
//uploadFile.ascx<%@ Control Language="C#" Inherits="test.uploadFile"%><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<link rel="stylesheet" href="CSS/ALL.CSS">
<style type="text/css">
<!--
.style1 {color: #0033FF}
.style2 {color: #FFFFFF}
-->
</style>
</head>
<p> </p>
<div align="center">
<table width="60%" border="1">
<caption>
</caption>
<tr bgcolor="#457aac">
<td colspan="2"><div align="center" class="style2">【 文 件 上 传 】</div></td>
</tr>
<tr>
<td width="37%" bgcolor="#FFFFFF"><div align="center" class="style3 style1">请输入该文件要显示的文件名</div></td>
<td width="63%"><div align="left">
<asp:TextBox id="FileName" runat="server"/>
</div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><div align="center" class="style3 style1">请选择要上传文件</div></td>
<td><div align="left">
<input name="file" type="file" id="file">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<asp:Button ID="submit" OnClick="ButtonClick" runat="server" Text="submit"></asp:Button>
</div></td>
</tr>
</table>
</div>
//-------------------------------------------------------------------------------
//upload.aspx<%@ Register TagPrefix="uploadFile" TagName="uploadFile" src="uploadFile.ascx" Assembly="test"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<script language="c#">
protected void Page_Load(object sender,EventArgs e)
{
if(IsPostBack)
{
form1.style.visibility = "hidden";
}
}
</script>
<div id="panel" style="visibility:visible">
<form name="form1" method="post" action="ShowData.aspx" enctype="multipart/form-data" runat="server">
<uploadFile:uploadFile id="upload" runat="server"/>
</form>
</div>
</body>
</html>
===>
protected System.Web.UI.WebControls.TextBox FileName2. give form a id: <form ID="form1" method="post" action="ShowData.aspx" enctype="multipart/form-data" runat="server">3. add a runat="server" to your script block:<script language="c#" runat="server">
protected void Page_Load(object sender,EventArgs e)
{
if(IsPostBack)
{
form1.Style["visibility"] = "hidden";
}
}
</script>4. <%@ Register TagPrefix="uploadFile" TagName="uploadFile" src="uploadFile.ascx" Assembly="test"%>
===>
<%@ Register TagPrefix="uploadFile" TagName="uploadFile" src="uploadFile.ascx"%>