开发者

Change img src in ASP.NET with Ajax

I have a .aspx page with an <img> tag which has an src subject to change depending on some controls values on the page. Pratically I change src with a runtime built-in querystring that cause src change and and wait for server response (server is returning a byte[] of the image).

My issue is that my <img> flicker (it becomes white) while is waiting for server's response. How can I update it once the server h开发者_开发知识库as done? Can JavaScript and JQuery accomplish this?

Thanks in advance!


You can preload the image and set it when it's preloaded like this:

$('<img>').attr('src', 'path/to/image/you/want/to/preload.png')
          .bind('load', function() {
              $('#image-to-replace').attr('src', $(this).attr('src'));
          });

With jQuery, this creates an <img>, sets its src attribute and attaches an event handler to the image's load event so that when the image is done loading, you can set the image's src to whatever #image-to-replace you have in your markup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜