Showing posts with label images. Show all posts
Showing posts with label images. Show all posts

Wednesday, March 28, 2012

Prefetching Images

I am using the update panel, and the timer control to automatically change a person's profile text, and their photo (small 65x65 pixels). Everything works well so far, except the transition is not always smooth for the photo.

Before the images/photos become cached in the browser, the default broken (link-to-image) image shows up, before the relevant photo loads. After that image loads the first time, the transition is smooth.

Is there a way to prefetch these images (approximately 8) when the page loads?

Thanks,

Karls

The easiest way I know of is to create a .js function to preload the images. Something like:

function preload(){
var imageUrls = ["img1.jpg","img2.jpg","img3.jpg"];
var images = [];
for(var i=0;i<imageUrls.length;i++){
var image = new Image();
image.src = imageUrls[i];
images.push(image);
}
}

That you'd call that function during pageLoad(). Setting the 'src' of the image object should cause the browser to start downloading that image.


Nice,

I would like to try that, but I am having a problem converting this to VB. Can anyone convert this?Huh?


No, i'ts javascript.


Ahh, makes sense now.

Thanks.

Saturday, March 24, 2012

Problem during Uploading the file

Hi

The Problem that am facing is

1)The path of the file that is saving in the database is "Path of the Server" + "images/"Up" of the path variable. I dont know why.

2) When i click on the Save Button, the code says File Uploaded but the file is missing from the location. Actually i think that "SaveAs" function is not working properly.

Boolean fileOK = false;
String path = Server.MapPath("/images/Uploads/employee/images/");
if (!(Directory.Exists(path)))
{
Directory.CreateDirectory(path);
}
lblInformation.Visible = true;
if (fuplEmployeeImage.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(fuplEmployeeImage.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}

if (fileOK)
{
if (File.Exists(path + fuplEmployeeImage.FileName))
{
lblInformation.Text = fuplEmployeeImage.FileName + " already Exists.Please Rename the file and try again.";
}
else
{
try
{
fuplEmployeeImage.PostedFile.SaveAs(path + fuplEmployeeImage.FileName);
_prEmployee.Attachment = path + fuplEmployeeImage.FileName;
lblInformation.Text = fuplEmployeeImage.FileName + " File Uploaded!";
}
catch (Exception ex)
{
lblInformation.Text = fuplEmployeeImage.FileName + " File could not be Uploaded.";
}
}
}
else
{
lblInformation.Text = "Cannot accept files of this type.";
}
}

Any help is greatly appreciated.

Thanx

If you're using AJAX with the FileUpload control, it's never going to work. See this thread for more details:

http://forums.asp.net/t/1107788.aspx


Hi

Thanx for your response.

I know this thing that File Upload Control doesn't work inside Update Panel of AJAX.For that purpose i had fire PostBacktrigger for thec control which actually calls FileUpload Control.

So that is not an issue

Bye


Hi,deepakleo2003

I'd like to give you a demo:

<%@. Page Language="C#" %>
<%@. Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Boolean fileOK = false;
String path = Server.MapPath("images/");
if (!(Directory.Exists(path)))
{
Directory.CreateDirectory(path);
}
lblInformation.Visible = true;
if (fuplEmployeeImage.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(fuplEmployeeImage.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".jpg", ".png", ".jpeg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
break;
}
}

if (fileOK)
{
if (File.Exists(path + fuplEmployeeImage.FileName))
{
lblInformation.Text = fuplEmployeeImage.FileName + " already Exists.Please Rename the file and try again.";
}
else
{
try
{
fuplEmployeeImage.PostedFile.SaveAs(path + fuplEmployeeImage.FileName);
//_prEmployee.Attachment = path + fuplEmployeeImage.FileName;
lblInformation.Text = fuplEmployeeImage.FileName + " File Uploaded!";
}
catch
{
lblInformation.Text = fuplEmployeeImage.FileName + " File could not be Uploaded.";
}
}
}
else
{
lblInformation.Text = "Cannot accept files of this type.";
}
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblInformation" Visible="false" runat="server" Text="lblInformation"></asp:Label>
<asp:FileUpload ID="fuplEmployeeImage" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>

If this help you,don't forget mark it as a answer.Thanks!

Let me know if you need more info.