0

I save image file into folder in Form_Load and used that image in client side. sometimes does not show image . but after refresh page image show. I want server wait till image saved complete.

  System.Drawing.Image barcodeImage = b.Encode(BarcodeLib.TYPE.CODE128, lstTicket[0].Barcode.ToString(), 250, 100);
   barcodeImage.Save(Server.MapPath("~/temp/") + lstTicket[0].Barcode.ToString() + ".jpg");

and Client Side

  <div id="Barcode" style="text-align: center; margin-top: 10px;">
      <img src="/temp/<%=item.Barcode + ".jpg"%>" style="width: 200px; height: 40px;" />
  </div>
Saeed Dini
  • 125
  • 1
  • 22
  • where is your Image save code? – Vishvadeep singh Nov 18 '17 at 06:58
  • Your question is a bit too broad for SO, as there are many ways to do this. Consider uploading the file with a different name or in a different folder, then renaming it after upload so the server can suddenly find it complete. You can also edit your question to show how the client uploads and how the server finds the image to show it, and it will make th question a lot more specific and a better fit for the site rules – Caius Jard Nov 18 '17 at 06:59
  • Please edit that code into your question. Make sure the lines has at least 4 spaces at th start so that it formats as code – Caius Jard Nov 18 '17 at 07:02
  • @CaiusJard Please Help me! – Saeed Dini Nov 18 '17 at 07:15

2 Answers2

1

I have the same problem and your solution is :

You can use

$(window).on("load"),function(){}

instead of

$(document).ready(function () {}

the alert box doesn't appear until after your barcode image are loaded and your problem will be solve

Amir H KH
  • 351
  • 2
  • 18
0

I'm amazed that the server can't write this image in time, but perhaps you should change the way it's done, rather than filling up the server hard disk with images of barcodes, write a handler that you put into the HTML as the img src e.g <img src="barcode generator.ashx?id=12345" ... and when the client browser calls to that handler to get the barcode, generate it as a png (not jpg, jpg should never be used for barcodes) and send it

See something like this: Display Image using ashx Handler

Here the guy is getting his avatar image out of db based on primary key supplies in URL - your situation is less complex - you can just generate the barcode data directly (put the barcode value you want to generate into the URL in the HTML , as a parameter

If you need more code samples etc google for something like "generate image dynamically ashx"

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • The problem is still exists. Sometimes does not show the Barcode image. – Saeed Dini Nov 18 '17 at 10:54
  • That seems unlikely; in a dynamic pattern, the browser is requesting the barcode data because it's ready to show the barcode image. If you correctly send it the image data it's asking for, it will show. There's no need to introduce an artificial delay into web page loading to "give a server more time to respond" – Caius Jard Nov 18 '17 at 17:58