我先定義了Label1的Visible 為false在下面的事件中,沒有效果,但如果不要UploadFile();這一句(我自定義的一個函數)就可以了,請問這個問題如何解決?? protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Visible = true;
UploadFile();
}
{
this.Label1.Visible = true;
UploadFile();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
this.label1.Visible = true;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Visible = true;
UploadFile();
}
你改成
protected void Button1_Click(object sender, EventArgs e)
{
UploadFile();
this.Label1.Visible = true; }试试
的代码不会有问题吧?
UploadFile();
this.Label1.Visible = true;
Label1.Invalidate();
試試。
public void UploadFile()
{
if (FileUpload1.PostedFile != null)
{
string name = FileUpload1.FileName;
string dtstr = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString();// +DateTime.Now.Minute.ToString();
FileUpload1.PostedFile.SaveAs(Server.MapPath("Email") + "\\" + dtstr + name); ReadFile(Server.MapPath("Email") + "\\" + dtstr + name);
}
}
private void ReadFile(string path)
{
if (con.ConnectionString == "") { con.ConnectionString = dtconn.getconn(); }
if (con.State.ToString() == "Closed") { con.Open(); } if (System.IO.File.Exists(path))
{
StreamReader reader = new StreamReader(path, System.Text.Encoding.GetEncoding("GB2312"));
string oneline;
trans = con.BeginTransaction();
try
{
while ((oneline = reader.ReadLine()) != null)
{
oneline = oneline.Trim();
if (oneline != "")
{
string[] ss = oneline.Split(" ".ToCharArray());
string Smonth = "", Sday = "", Stime = "", Ssystem = "";//保存時間 if (!(ss[0].ToString().Length == 0))
{
Smonth = ss[0].ToString();
Sday = ss[1].ToString();
Stime = ss[2].ToString();
Ssystem = ss[3].ToString(); StringBuilder sb = new StringBuilder();
sb.Append("insert into logdetails values(");
int i;
sb.Append("'" + Smonth + "'" + ",");
sb.Append("'" + Sday + "'" + ",");
sb.Append("'" + Stime + "'" + ",");
sb.Append("'" + Ssystem + "'" + ","); sb.Append("'");
for (i = 4; i < ss.Length; i++)
{
if (ss[i].Contains("'"))
{
string[] child = ss[i].ToString().Split("'".ToCharArray());
if (!(child[0].ToString().Length == 0))
{
for (int k = 0; k < child.Length; k++)
{
sb.Append(child[k] + "''");
}
sb.Remove(sb.ToString().LastIndexOf("''"), 2);
sb.Append(" ");
}
}
else
{
sb.Append(ss[i] + " ");
}
}
sb.Append("'");
sb.Append(")");
sqlexecute(sb.ToString());
}
} }
reader.Close();
Response.Write(" <script language='javascript'>alert('导入数据完成!');history.go(-1); </script>");
}
catch (Exception ex)
{
trans.Rollback();
Response.Write(" <script language='javascript'>alert('出现错误,事务已经回滚!');history.go(-1); </script>");
}
finally
{
trans.Commit();
con.Close();
}
}
else
{
Response.Write(" <script language='javascript'>alert('指定的文件不存在!');history.go(-1); </script>");
Response.End();
}
}
再看看生成的页面有没有label1
等你传输完毕后 服务器才把VISABLE值为false
页面刷新,按钮才消失
你可以用JS把按钮阴了····在前台按钮添加 OnClick='document.all.buttonName.style.display="none";'就行了