我先定義了Label1的Visible 為false在下面的事件中,沒有效果,但如果不要UploadFile();這一句(我自定義的一個函數)就可以了,請問這個問題如何解決??    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Label1.Visible = true;      
        UploadFile();
    }

解决方案 »

  1.   


    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;
            }
        }
    }
      

  2.   

    在这边是可以的 开始还以为是没有刷新所致 faint
      

  3.   


        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;          }试试
      

  4.   

    你自己写的uploadfile()的代码给出
      

  5.   

    UploadFile(); 
    的代码不会有问题吧?
      

  6.   

    你在 UploadFile(); 是否执行了 this.Label1.Visible = false;    ?
      

  7.   

    沒有执行this.Label1.Visible = false
      

  8.   

     
                UploadFile(); 
                this.Label1.Visible = true;    
                Label1.Invalidate();
    試試。
      

  9.   

    web下沒有Label1.Invalidate();吧??
      

  10.   

    在UploadFile(); 里面可能有this.Label1.Visible的操作!!  
      

  11.   

    我对UploadFile()里面的内容很感兴趣
      

  12.   

    下面是UploadFile(),沒有把属性改成false 
    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); 
            } 
        }
      

  13.   

    接上面 
    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(); 
            } 
        }
      

  14.   

    会不会是ReadFile(string path) 中的数据库连接没有正常关闭?
      

  15.   

    先打断点,看看label1.visable=true有没有被执行
    再看看生成的页面有没有label1
      

  16.   

    你在上传文件的时候 服务器并没有完你的请求···
    等你传输完毕后 服务器才把VISABLE值为false
    页面刷新,按钮才消失
    你可以用JS把按钮阴了····在前台按钮添加 OnClick='document.all.buttonName.style.display="none";'就行了
      

  17.   

    看意思应该是显示上载文件信息用的,其实不用设置visable,只要把TEXT=“”就不会看到该控件,而当TEXT有字符时才看到该控件显示字符,而不用隐藏控件本身。