2014-02-18 100 views
0

我在AjaxFileUpload1的pageupload事件期間從頁面的文本框中爲變量賦值。問題是,我沒有從文本框中獲取值給我的可變即使沒有錯誤throws.My變量無法讀取文本框的值

 string scn = txtSCN.Text; 
     string line1 = txtLineitem.Text; 
     string aging1 = txtAging.Text; 

任何想法,爲什麼AjaxFileUpload1_UploadComplete是無法讀取的文本框的值

我的CS代碼是:

protected void AjaxFileUpload1_UploadComplete(object sender,  AjaxControlToolkit.AjaxFileUploadEventArgs e) 
     { 
    string c = System.IO.Path.GetFileName(e.FileName); 
     string dpath = "~/Profile/Images/"; 
     string scn = txtSCN.Text; 
     string line1 = txtLineitem.Text; 
     string aging1 = txtAging.Text;    
     AjaxFileUpload1.SaveAs(MapPath(Path.Combine(dpath,c))); 
     dpath = dpath + c; 
     string str1 = ConfigurationManager.ConnectionStrings["ProTracConnGMCH"].ConnectionString; 
     SqlConnection cn = new SqlConnection(str1); 
     cn.Open(); 
     string sql = "Update tbNoquoteFollowupupdate set MailreceivedURL = '" + dpath + "', chkMailreceived = 1 , Buyername = '" + buyername + "' where scn = '" + scn + "' AND lineItem = '" + line1 + "' and Aging ='" + aging1 + "' "; 
     SqlCommand cmd = new SqlCommand(sql, cn); 
     int i = cmd.ExecuteNonQuery(); 

     if (i > 0) 
     { 
      // AjaxFileUpload1.SaveAs(Path.Combine(dpath, e.FileName)); 
      //AjaxFileUpload1.SaveAs(MapPath(dpath)); 
     } 
     cn.Close(); 
     BindGridviewData1(); 
     cn.Open(); 
     string cmd2 = "Insert Into tbMulitmailsreived (scn, lineItem,followupdate, Aging,MailreceivedURL) Values ('" + scn + "', '" + line1 + "','" + DateTime.Now + "','" + aging1 + "','" + dpath + "')"; 
     SqlCommand sqlCommand2 = new SqlCommand(cmd2, cn); 
     sqlCommand2.ExecuteNonQuery(); 
     cn.Close(); 
    } 

請幫我

+0

我在這裏要設立一個長鏡頭,這不是交叉線程? – Schuere

回答

0

我想你需要添加!Page.IsPostBack到你的代碼。這樣

protected void AjaxFileUpload1_UploadComplete(object sender,  AjaxControlToolkit.AjaxFileUploadEventArgs e) 
{ 
    if(!Page.IsPostBack) 
    { 
     string c = System.IO.Path.GetFileName(e.FileName); 
     string dpath = "~/Profile/Images/"; 
     string scn = txtSCN.Text; 
     string line1 = txtLineitem.Text; 
     string aging1 = txtAging.Text;    
     AjaxFileUpload1.SaveAs(MapPath(Path.Combine(dpath,c))); 
     dpath = dpath + c; 
     string str1 = ConfigurationManager.ConnectionStrings["ProTracConnGMCH"].ConnectionString; 
     SqlConnection cn = new SqlConnection(str1); 
     cn.Open(); 
     string sql = "Update tbNoquoteFollowupupdate set MailreceivedURL = '" + dpath + "', chkMailreceived = 1 , Buyername = '" + buyername + "' where scn = '" + scn + "' AND lineItem = '" + line1 + "' and Aging ='" + aging1 + "' "; 
     SqlCommand cmd = new SqlCommand(sql, cn); 
     int i = cmd.ExecuteNonQuery(); 

     if (i > 0) 
     { 
     // AjaxFileUpload1.SaveAs(Path.Combine(dpath, e.FileName)); 
     //AjaxFileUpload1.SaveAs(MapPath(dpath)); 
     } 
     cn.Close(); 
     BindGridviewData1(); 
     cn.Open(); 
     string cmd2 = "Insert Into tbMulitmailsreived (scn, lineItem,followupdate, Aging,MailreceivedURL) Values ('" + scn + "', '" + line1 + "','" + DateTime.Now + "','" + aging1 + "','" + dpath + "')"; 
     SqlCommand sqlCommand2 = new SqlCommand(cmd2, cn); 
     sqlCommand2.ExecuteNonQuery(); 
     cn.Close(); 
    } 
} 
1

上週我花了一些時間來調查這個question但到底能不能找到這樣的一個簡單的解決方案。該問題中的OP通過在會話中存儲值解決了這個問題,但爲了實現這個目標,您仍然需要在某個階段進行回發。

顯然有計劃爲AjaxFileUpload控件傳遞Context Keys集合中的值的功能,但這絕不是implemented。這question描述如何自己實現這一點,雖然。

認爲我看到了另一個問題,圍繞同一主題和OP通過改變使用AsyncFileUpload控制解決了這個問題,但我堅持要糾正......