2011-11-04 30 views
3

我有一個非常有趣的困境,那就是讓我頭痛的颶風。我在這裏看到過類似的問題,但用戶沒有發佈代碼,所以沒有解決。這是一個asp.net,sql服務器和c#應用程序。如何防止我的文本框在回發中清除文本。

在我的應用程序,我使用JavaScript來顯示在TextBox虛擬數據,而一個長期的過程運行到娛樂用戶。 (請注意,這是一個項目,而不是一個專業的應用程序)。

的問題是,一旦應用程序執行完畢,應用程序(我相信)刷新頁面並清除TextBox。我想防止這種情況發生,並在程序完成後繼續顯示文本。

我的問題是,在下面的代碼是刷新頁面?我如何重新編碼它以防止文本被清除?

我知道JavaScript或.aspx頁面沒有問題。我沒有設置或編制任何財產來清除文本。如果有人能夠解決這個問題,我將不勝感激。如果你需要更多的代碼,請告訴我。我將在此頁面上非常活躍,直到解決問題。再次感謝!

public partial class SendOrders : System.Web.UI.Page 
{ 
    protected enum EDIType 
    { 
     Notes, 
     Details 
    } 

    protected static string NextBatchNum = "1"; 
    protected static string FileNamePrefix = ""; 
    protected static string OverBatchLimitStr = "Batch file limit has been reached. No more batches can be processed today."; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     Initialize(); 
    } 

    protected void Page_PreRender(object sender, EventArgs e) 
    { } 

    protected void btnExit_Click(object sender, EventArgs e) 
    { 
     System.Diagnostics.Process.GetCurrentProcess().Kill(); 
    } 

    protected void Button_Click(object sender, EventArgs e) 
    { 
     PutFTPButton.Enabled = false; 
     Thread.Sleep(3000); 
     Button btn = (Button)sender; 
     KaplanFTP.BatchFiles bf = new KaplanFTP.BatchFiles(); 
     KaplanFTP.Transmit transmit = new KaplanFTP.Transmit(); 

     if (btn.ID == PutFTPButton.ID) 
     { 
      DirectoryInfo dir = new DirectoryInfo(@"C:\Kaplan"); 
      FileInfo[] BatchFiles = bf.GetBatchFiles(dir); 
      bool result = transmit.UploadBatchFilesToFTP(BatchFiles); 

      if (!result) 
      { 
       ErrorLabel.Text += KaplanFTP.errorMsg; 
       return; 
      } 

      bf.InsertBatchDataIntoDatabase("CTL"); 
      bf.InsertBatchDataIntoDatabase("HDR"); 
      bf.InsertBatchDataIntoDatabase("DET"); 
      bf.InsertBatchDataIntoDatabase("NTS"); 

      List<FileInfo> allfiles = BatchFiles.ToList<FileInfo>(); 
      allfiles.AddRange(dir.GetFiles("*.txt")); 
      bf.MoveFiles(allfiles); 

      foreach (string order in bf.OrdersSent) 
      { 
       OrdersSentDiv.Controls.Add(new LiteralControl(order + "<br />")); 
      } 

      btnExit.Visible = true; 
      OrdersSentDiv.Visible = true; 
      OrdersInfoDiv.Visible = false; 
      SuccessLabel.Visible = true; 
      NoBatchesToProcessLbl.Visible = true; 
      BatchesToProcessLbl.Visible = false; 
      PutFTPButton.Enabled = false; 
      BatchesCreatedLbl.Text = int.Parse(NextBatchNum).ToString(); 
      Thread.Sleep(20000); 

      if (KaplanFTP.errorMsg.Length != 0) 
      { 
       ErrorLabel.Visible = false; 
       SuccessLabel.Visible = true; 
       ErrorLabel.Text = KaplanFTP.errorMsg; 
      } 
     } 
    } 

    private void Initialize() 
    { 
      KaplanFTP.BatchFiles bf = new KaplanFTP.BatchFiles(); 

      if (!IsPostBack) 
      { 
       FileNamePrefix = bf.FileNamePrefix; 
       NextBatchNum = bf.NextBatchNum; 
       BatchesCreatedLbl.Text = (int.Parse(NextBatchNum) - 1).ToString(); 

       if (bf.CheckLocalForNewBatch() == true) 
       { 
        NoBatchesToProcessLbl.Visible = false; 
        BatchesToProcessLbl.Visible = true; 
        if (int.Parse(NextBatchNum) >= 50) 
        { 
         ErrorLabel.Text += ErrorLabel.Text + OverBatchLimitStr; 
         ErrorLabel.Visible = true; 
         PutFTPButton.Enabled = false; 
        } 
        else 
        { 
         bf.ReadyFilesForTransmission(); 
         ErrorLabel.Visible = false; 
         PutFTPButton.Enabled = true; 
         List<string[]> detStream = bf.GetBatchStream("DET"); 
         List<string[]> hdrStream = bf.GetBatchStream("HDR"); 
         OrdersInfoDiv.Visible = true; 

         DataTable dt = new DataTable(); 
         dt.Columns.Add("ORDER NUMBER"); 
         dt.Columns.Add("LINE NUMBER"); 
         dt.Columns.Add("ITEM NUMBER/ISBN"); 
         dt.Columns.Add("DESCRIPTION"); 
         dt.Columns.Add("QUANTITY"); 
         dt.Columns.Add("SHIPPING"); 

         Dictionary<string, string> orderShip = new Dictionary<string, string>(); 

         foreach (string[] hdrItems in hdrStream) 
         { 
          orderShip.Add(hdrItems[0], hdrItems[2]); 
         } 
         foreach (string[] detItems in detStream) 
         { 
          List<string> detLineList = new List<string>(detItems); 
          detLineList.Add(orderShip[detItems[0]]); 
          detLineList.RemoveAt(13); 
          detLineList.RemoveAt(12); 
          detLineList.RemoveAt(11); 
          detLineList.RemoveAt(10); 
          detLineList.RemoveAt(9); 
          detLineList.RemoveAt(8); 
          detLineList.RemoveAt(7); 
          detLineList.RemoveAt(4); 
          detLineList.RemoveAt(2); 
          detLineList[1] = detLineList[1].TrimStart('0'); 
          detLineList[4] = detLineList[4].TrimStart('0'); 
          dt.Rows.Add(detLineList.ToArray()); 
         } 

         BatchDetails.DataSource = dt; 
         BatchDetails.DataBind(); 
        } 
       } 
       else 
       { 
        NoBatchesToProcessLbl.Visible = true; 
        BatchesToProcessLbl.Visible = false; 
        PutFTPButton.Enabled = false; 
       } 
      } 
     } 
} 
+1

javascript/html在哪裏? – Nate

+0

我使用了後面的代碼。但是,所有的JavaScript都會在文本框中插入文本,就是這樣。你想讓我發佈這些代碼嗎? – javasocute

+1

是否在此代碼中引用了問題中的文本框?你在使用UpdatePanel嗎? – patmortech

回答

3

是的。你必須確定你的計算的狀態,並填充在機箱內部的Page_Load的控制,其中的IsPostBack是真實的:

protected void Page_Load(object sender, EventArgs e) { 
    if (IsPostBack) { 
     // re-populate javascript-fill UI 
    } else { 
    } 
    Initialize(); 
} 

可以大概也移動初始化()到else子句爲好。

+0

嗯,這是一個好主意。你會如何寫在JavaScript? – javasocute

+0

你不寫這是JavaScript。這必須在你的C#代碼後面通過回傳來保存數據。 – drdwilcox

+0

ahha我明白了。你先生是f *和王天才。非常感謝! – javasocute

0

由於您正在處理按鈕單擊服務器端(我假設用戶單擊該按鈕時發生問題?)必須有一個回發來處理它。

你可以嘗試把你的按鈕和標籤到updatepanel控制 - 它使用AJAX刷新其內容。

updatepanel S比信息,請參閱this page