1
我有一個ASP.NET Web窗體頁面,圖像控件綁定到動畫gif。如果我在Internet Explorer(而不是其他瀏覽器)中打開它並單擊該頁面上的一個按鈕(打開文件),即使打開並關閉文件,gif也會停止移動。在我刷新瀏覽器之前它不會再啓動。我試着用下面的代碼來解決這個問題:C#和ASP.NET會話轉換錯誤
protected void lnkStart_Click(object sender, EventArgs e) // Link Button Click Event
{
imgRefresher.Enabled = 1 == 1; // setting Timer Control Enabled to 1
Session["TimerEnabled"] = imgRefresher.Enabled; // storing 1 in Session
Session["FileName"] = "myFile.exe";
}
protected void imgRefresher_Tick(object sender, EventArgs e) // Timer Control Tick Event
{
if (((int)Session["TimerEnabled"]) == 1) // This line gives me an invalid cast error
{
Session["TimerEnabled"] = 0 == 1;
string fileName = Session["FileName"].ToString();
// This part I stole off the internet and will actually open the file.
System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
if (fileInfo.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(fileInfo.FullName);
Response.End();
}
}
imgRefresher.Enabled = 0 == 1;
}
行IF(((字節)會議[ 「TimerEnabled」]^1)== 0)給了我一個無效的轉換錯誤。我試着把它轉換成一個整數,一個字節,一個char,一個float和一個double。目標是將Session [「TimerEnabled」]從1切換到0,以便下一次關閉定時器控制。
imgRefresher .Enabled = 0 == 1; = Enablade值爲False ...不是整數 – 2014-11-21 07:29:44
是不是0與false相同? – ostrichchasedwormaroundfield 2014-11-21 07:30:55
jap ..但是您不能將Bool投射到Int這種方式 – 2014-11-21 07:34:54