ASP.NET编程中动态输出网页最简单的方法是用Response.Write(),但是这样一般只能在网页头部输出,不能做到在指定地方输出。
但是Label和Literal、LiteralControl就可以在网页指定地方输出。
Label与Literal、LiteralControl的区别是Label输出带<span></span>标记。而其他则没有。基于这些原因,我编程序的时候一般只用到LiteralControl,Label与Literal很少用(LiteralControl比Literal用起来感觉会更方便)。而且我经常要用到向网页中输出文字,于是就编写了一个函数直接向网页输出文字,程序见下。
但是Label和Literal、LiteralControl就可以在网页指定地方输出。
Label与Literal、LiteralControl的区别是Label输出带<span></span>标记。而其他则没有。基于这些原因,我编程序的时候一般只用到LiteralControl,Label与Literal很少用(LiteralControl比Literal用起来感觉会更方便)。而且我经常要用到向网页中输出文字,于是就编写了一个函数直接向网页输出文字,程序见下。
Tags: Code
///作用:FileUpLoad 上传大文件使用.net 的FileUpLoad 控件上传文件非常的方便, 在Web.config 中的<System.web>下添加如下的语句
<system.web>
<httpRuntime maxRequestLength="1000000" executionTimeout="45"/>
</system.web>
maxRequestLength 的单位为字节,executionTimeout的单位为秒
//upload code:
Boolean fileOK = false;
String path = Server.MapPath("~/Images/");
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
<system.web>
<httpRuntime maxRequestLength="1000000" executionTimeout="45"/>
</system.web>
maxRequestLength 的单位为字节,executionTimeout的单位为秒
//upload code:
Boolean fileOK = false;
String path = Server.MapPath("~/Images/");
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
Tags: Code
幻の小屋
|
软件&技术
|