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>
4
  • where is your Image save code? Commented Nov 18, 2017 at 6: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 Commented Nov 18, 2017 at 6: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 Commented Nov 18, 2017 at 7:02
  • @CaiusJard Please Help me! Commented Nov 18, 2017 at 7:15

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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"

2 Comments

The problem is still exists. Sometimes does not show the Barcode image.
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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.