我在AjaxFileUpload1的pageupload事件期间从页面上的文本框中为变量赋值。问题是,即使没有错误抛出,我也没有从文本框中获取值到我的变量。我变量是
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 :(得分:1)
请将文本框中的值放入会话中,因为您可以从UpLoadComplete访问会话变量,所有内容都将以这种方式运行。
答案 1 :(得分:0)
您可以自定义AjaxFileUpload控件并将文本框值传递给UploadCompleted事件处理程序,如下所示:
function uploadStarted(sender, args) {
var latitude = $get("<%= tbUploaderLat.ClientID %>").value;
var longitude = $get("<%= tbUploaderLon.ClientID %>").value;
sender.contextKeys = { "latitude": latitude, "longitude": longitude };
}
在那之后,你可以得到纬度&amp; UploadComplete处理程序中的经度值:
protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
{
if (!string.IsNullOrEmpty(file.ContextKeys))
{
var longLat = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Dictionary<string, string>>(file.ContextKeys);
var longitude = longLat["longitude"];
var latitude = longLat["latitude"];
}
//code to save file
}