Click here to Skip to main content
15,884,648 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am using Jqery Fancybox on my page. I have preivew and upload image button in gridview. I am uploading images using upload image button. If image is uploaded user can see that image on clicking preview button. If image is uploaded iam opening image in fancy box. If image is not uploaded im showing alert message. Problem is alert is showing at the same time fancybox also showing if image is not uploaded. I dont want to show fancybox if image is not uploaded. Please help me on preventing fancybox if image is not uploaded. Please let me know if i am not clear.

Below is my javascript.

C#
function fnOpenPreview(ImgName) {
            var hdnImagepath =                       document.getElementById("ContentPlaceHolder1_hdnImagepath");
            var pnlPreview = document.getElementById("pnlPreview");
            var img = document.getElementById("ContentPlaceHolder1_imgPreview");
            if (ImgName != "") {
                img.src = hdnImagepath.value + ImgName;
                $('.testdata').fancybox
                (
                {
                    'scrolling': 'no',
                    'href': '#pnlPreview'
                }
                );
                return false;
            }
            else {
                img.src = "";
                alert("No Preview avaiable.");
                return false;
            }
        }


Thank you...
Posted
Updated 22-May-13 20:14pm
v3
Comments
I guess the value of ImgName is creating the problem.

So, do one thing. Put a debugger like this.


function fnOpenPreview(ImgName) {
debugger;
//other codes.


Now you can check on FireBug of FireFox. Check what is the value of ImgName when you expect that it should be blank, I mean the condition when facy box should not show.

Please do this and let me know.
NaVeN Kumar 23-May-13 5:02am    
Hello Tadit Dash,

I have checked, ImgName is coming empty ("") when image is not uploaded.
So, it is not going inside the if statements, right ?
It is going to else and showing the alert, but also the fancy box shows, right ?
NaVeN Kumar 23-May-13 6:40am    
Absolutely... I tried fancybox.close also but did not work. Any suggestions..?
That means the previous fancy box is creating a problem.

At first attempt it must be working, I mean if the fancy box is not initialized once, then do this and check if only alert is coming or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900