web页里有一个按钮和一个显示标签
private void Button1_Click(object sender, System.EventArgs e)
{
this.Label1.Text=Bbs2.FileName;
}
赋给一个Label1控件看看上传的文件名....当我上传图片时..图片可以上传成但是在Button1_Click时Bbs2.FileName;取不到自定义控件里的.文件名
======================================
======================================
public class bbs : WebControl, INamingContainer
{
public Button mybutton;
public HtmlInputFile UploadFile;
public Label Label1;
public bbs()
{
this.EnsureChildControls();
}
private void mybutton_Click(object sender, System.EventArgs e)
{
if(UploadFile.PostedFile.FileName.Trim()!="")
{
//上传文件
extension = Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper();
fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
string path = mydirectory + "/UploadFile/" + fileName + extension;
UploadFile.PostedFile.SaveAs(path);
}
}
protected void myScript(string java)
{
Page.RegisterStartupScript("fsf","<script language=javascript>alert('"+java+"');</script>"); } protected override void CreateChildControls()
{
mybutton=new Button();
UploadFile=new HtmlInputFile();
Label1=new Label();
mybutton.Text="提交";
this.Controls.Add(UploadFile);
this.Controls.Add(mybutton);
this.Controls.Add(new LiteralControl("<p>"));
this.Controls.Add(Label1);
this.Controls.Add(new LiteralControl("</p>"));
mybutton.Click+=new EventHandler(mybutton_Click);
}
//----------------------------
protected int filelength;
protected string fileName;
protected string mydirectory;
protected string extension;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
[
DescriptionAttribute("文件大小")
]
public int FileLength
{
set{filelength=value;}
get{return filelength;}
}
[
DescriptionAttribute("图片名字")
]
public string FileName
{
set{fileName=value;}
get{return fileName;}
}
[
DescriptionAttribute("文件路径")
]
public string MyDirectory
{
get{return mydirectory;}
set{mydirectory=value;}
}
[
DescriptionAttribute("图片的扩展名")
]
public string Extension
{
get{return extension;}
set{extension=value;}
}
private void Button1_Click(object sender, System.EventArgs e)
{
this.Label1.Text=Bbs2.FileName;
}
赋给一个Label1控件看看上传的文件名....当我上传图片时..图片可以上传成但是在Button1_Click时Bbs2.FileName;取不到自定义控件里的.文件名
======================================
======================================
public class bbs : WebControl, INamingContainer
{
public Button mybutton;
public HtmlInputFile UploadFile;
public Label Label1;
public bbs()
{
this.EnsureChildControls();
}
private void mybutton_Click(object sender, System.EventArgs e)
{
if(UploadFile.PostedFile.FileName.Trim()!="")
{
//上传文件
extension = Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper();
fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
string path = mydirectory + "/UploadFile/" + fileName + extension;
UploadFile.PostedFile.SaveAs(path);
}
}
protected void myScript(string java)
{
Page.RegisterStartupScript("fsf","<script language=javascript>alert('"+java+"');</script>"); } protected override void CreateChildControls()
{
mybutton=new Button();
UploadFile=new HtmlInputFile();
Label1=new Label();
mybutton.Text="提交";
this.Controls.Add(UploadFile);
this.Controls.Add(mybutton);
this.Controls.Add(new LiteralControl("<p>"));
this.Controls.Add(Label1);
this.Controls.Add(new LiteralControl("</p>"));
mybutton.Click+=new EventHandler(mybutton_Click);
}
//----------------------------
protected int filelength;
protected string fileName;
protected string mydirectory;
protected string extension;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
[
DescriptionAttribute("文件大小")
]
public int FileLength
{
set{filelength=value;}
get{return filelength;}
}
[
DescriptionAttribute("图片名字")
]
public string FileName
{
set{fileName=value;}
get{return fileName;}
}
[
DescriptionAttribute("文件路径")
]
public string MyDirectory
{
get{return mydirectory;}
set{mydirectory=value;}
}
[
DescriptionAttribute("图片的扩展名")
]
public string Extension
{
get{return extension;}
set{extension=value;}
}
解决方案 »
- .NET using System引用集问题
- 请教一下,Asp.net如何读取flash里的值?
- 用微软ajax控件怎么弹出对话框
- 页面跳转的问题!!!!谢谢各位了
- c#的类改写成Java的类,需要注意哪些问题?请大哥大嫂兄弟姐妹们提个意见,谢谢了!!
- TreeView的疑难问题,头都快想暴了,高手进来看看,谢谢!
- 怎样根据sql server的备份文件到另一台机器上重建数据库?请高手指教
- 求高手解答vbscript的问题
- 关于VWD2005编译WEB工程
- 感谢项目组的兄弟们的大力支持!!!
- 一个信息交易网源代码,需要的请留下伊妹儿
- 我只安装了netframework 1.1,请问能不能把一个纯文本的C++代码文件编译?
http://blog.csdn.net/kgdiwss/archive/2005/06/23/400995.aspx
Label1.Text = fileName;
Label1.Text = fileName;
-------------------------------------------------------
up