[英]asp.net handler.ashx running only on refresh in ajax
我試圖在運行時在asp.net頁面中顯示圖像,所以我編寫了一個處理程序頁面。 並在按鈕單擊事件中將該頁面用作url源,例如image.imageurl =“〜/ handler.ashx”。
但是,當我將圖像框和按鈕放在ajax更新面板中時。 處理程序中的代碼僅在頁面加載后第一次單擊時執行,而不在第二次單擊時執行。 我需要刷新頁面。 如何在不刷新按鈕的情況下實現圖像更新?
提前致謝。
代碼處理程序,該處理程序返回從wcf服務獲得的圖像
public class Handler : IHttpHandler
{
imageService.HelloWorldServiceClient cli = new imageService.HelloWorldServiceClient();
public void ProcessRequest (HttpContext context)
{
byte [] buffer = cli.getImage();
context.Response.ContentType = "image/jpeg";
context.Response.Buffer = true;
context.Response.BinaryWrite(buffer);
context.Response.Flush();
context.Response.End();
}
我可以在按鈕單擊上使用以下代碼
Image1.ImageUrl = "~/Handler.ashx";
圖像控件和按鈕都位於ajax更新面板中。
好的,我通過對代碼進行以下更改來解決問題
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/Handler.ashx?guid=" + Guid.NewGuid();
}
關鍵是每次都需要一個新的URL。
有關更多詳細信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.