9 Replies - 1915 Views - Last Post: 29 January 2013 - 05:40 PM Rate Topic: ***** 1 Votes

#1 smurpetx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-January 13

Object Required Error.

Posted 23 January 2013 - 09:02 PM

I've been ask to do a pasting an copied image from clipboard to Web Form and directly upload in web server. I've found some TUTORIAL about it, But its been dead for almost 4 years, I need someone to guide me, Im new in programming im currently taking my Internship as a programmer of php.

I could paste the image from Clipboard to Web Form, But when i start uploading it onto the server, i got this error "Object Required". I can't seem find a way to fix it.
function uplImages()
            {                                         
              flagUploadingStarted = true;
                    // Uploading Image 1 if its present.
                    if(document.getElementById("<%=hdnImageFileName1.Id%>").value != "")
                    {            
                        uploadImage1(document.getElementById("<%=hdnImageFileName1.Id%>").value) // This where i get the "Object Required"
                    }
            }


Thanks. Anyhelp would be really appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Object Required Error.

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3710
  • View blog
  • Posts: 5,958
  • Joined: 08-June 10

Re: Object Required Error.

Posted 23 January 2013 - 09:34 PM

I don't know a thing about ActiveX, so I can't help you there, but I can tell you that the code you posted, as well as that tutorial, seem to be using ASP.NET, not PHP.
Was This Post Helpful? 0
  • +
  • -

#3 smurpetx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-January 13

Re: Object Required Error.

Posted 23 January 2013 - 09:49 PM

The control ClipboardActiveX was made on VB.NET , im using it for my module in the webpage to allow me to paste the image to the webform. Anyways, Thanks for the info, :oops: didn't know yet the difference from PHP to ASP.NET.

View Postsmurpetx, on 23 January 2013 - 09:47 PM, said:

The control ClipboardActiveX was made on VB6 , im using it for my module in the webpage to allow me to paste the image to the webform. Anyways, Thanks for the info, :oops:/> didn't know yet the difference from PHP to ASP.NET.

Was This Post Helpful? 0
  • +
  • -

#4 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,673
  • Joined: 24-August 11

Re: Object Required Error.

Posted 24 January 2013 - 10:43 AM

Why are you using ASP in your Javascript getElementById call? The Javascript can do that on its own.

function uplImages() {
    flagUploadingStarted = true;

    // Uploading Image 1 if its present.
    if (document.getElementById("myControl1").value != "") {
        uploadImage1(document.getElementById("myControl1").value)
    }
}



Just put the ID of whatever control you're looking for into the parenthesis (I assume the control's ID is "hdnImageFileName1", so that's what you'd put in there).
Was This Post Helpful? 0
  • +
  • -

#5 smurpetx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-January 13

Re: Object Required Error.

Posted 24 January 2013 - 06:02 PM

View Posth4nnib4l, on 24 January 2013 - 10:43 AM, said:

Why are you using ASP in your Javascript getElementById call? The Javascript can do that on its own.

function uplImages() {
    flagUploadingStarted = true;

    // Uploading Image 1 if its present.
    if (document.getElementById("myControl1").value != "") {
        uploadImage1(document.getElementById("myControl1").value)
    }
}



Just put the ID of whatever control you're looking for into the parenthesis (I assume the control's ID is "hdnImageFileName1", so that's what you'd put in there).


I already tried using the control of the div
   uploadImage1(document.getElementById("myControl1").value)
   

And by using that code, i'll be able to Paste the image in the clipboard which the user copy (or using any Image Editing Tool, like Window Snipping Tool) onto the webform (onto the selected div) But , it won't allow me to Upload the image into the web server, and the results is always displaying this

 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="HttpUtil1.aspx.vb" Inherits="HttpUtil1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="frmHttpUtil" runat="server">
        <div>
        </div>
    </form>
</body>
</html>


 


This is the content of HttpUtil1.aspx, and onto that page should i be directed when i click "Upload Image To the Server". And, Nothing uploaded in to the server.


Thanks for the reply h4nnib4l. Hope you could help me in my problem :clap:
Was This Post Helpful? 0
  • +
  • -

#6 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,673
  • Joined: 24-August 11

Re: Object Required Error.

Posted 25 January 2013 - 08:17 AM

Quote

I already tried using the control of the div


I don't know what you mean by that, and I don't know why using the value of an elements "ID" attribute won't give you that element to work with. Do you know what's happening when you try to upload that image? Have you tried something like Fiddler to watch the exchanges between the client and the server?
Was This Post Helpful? 0
  • +
  • -

#7 rgfirefly24  Icon User is online

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,460
  • Joined: 07-April 08

Re: Object Required Error.

Posted 25 January 2013 - 11:28 AM

It may be that the getElementByID() is failing because of all the added fluff that ASP.NET WebForms puts on a control ID. You could try this and see if it works:

 uploadImage1(document.getElementById("<%=hdnImageFileName1.ClientID%>").value)



Also for us to really help you you're going to need to post the full code so we can look it over.

This post has been edited by rgfirefly24: 25 January 2013 - 11:29 AM

Was This Post Helpful? 1
  • +
  • -

#8 smurpetx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-January 13

Re: Object Required Error.

Posted 27 January 2013 - 06:00 PM

Thanks for the response. Here's the full code.

@h4nnib4l - Never tried that one, im new at this. Still learning a lot of things. But thanks for the info, i might try that one sooner. :sweatdrop:/>


@rgfirefly24 Here's the code, i've been using.

// Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style>
        .ImageDIV
        {
	        height:400px; 
	        width:500px; 
	        overflow:auto;
	        border:1px solid;
	        cursor:pointer;
        }
        .LinkImage
        {
            cursor:pointer;
        }
    </style>
</head>
<body onkeypress="javascript:fnKeyPress();">
    <form id="form1" runat="server">

        <script type="text/javascript">
  
        var hoverColor = "#00000b"; //DIV Color when mouse is hover the DIV
        var defaultColor = "black"; //DIV default color
        var selectColor = "#000000"; // DIV color when its selected.
        var selectedDIV = "";        //ID of the DIV user has currently selected(it will be 1,2,3 or 4)                
        var objActiveX; //Object of Clipboard ActiveX control.
        
        //Success flags ,whenever it turns to true,it indicates corresponding image is uploaded to the server.
        //And when all 4 flags are TRUE we will actually post the form to the server.
        var success1 = false; 
        
        
        // Flag to indicate uploading is being started,so if in middle user tries to paste image or remove it,we can stop doing that.
        var flagUploadingStarted = false;
        // Variable to get the Current URL and attach httpUtil Page to be passed in ActiveX for sending httpRequest.
        var strURL;
        // Variable holding the Post strings for URL like Random number and type.-
        var postVar;        
        </script>

        <script language="javascript">
        window.onload = function() {            
            
           //Detect ActiveX component using try . . . catch block.
            try {                                        
                objActiveX = document.getElementById("ClipboardActiveX");                    
                
            } catch(ex) {
                alert("Cannot initialize the ActiveX control. Please contact your administrator regarding this error.");                    
            }
            
            // Initializing URL and Post Variables.
            strURL = window.location.toString();
            strURL = strURL.substring(0, strURL.lastIndexOf("/"));
            strURL = strURL + "/HttpUtil1.aspx";
            postVar = "id=1&type=p";
        }
        </script>

        <div>
            <object id="ClipboardActiveX" classid="CLSID:D472AFDE-DA5E-43BA-9A5F-4F21882AAE4A"
                codebase="ClipboardActiveX.dll">
            </object>
            <br />
            &nbsp;</div>

        <script type="text/javascript">
        //Function to highlight the DIV.
            function Highlight(id) 
            {                
                document.getElementById("div" + id).style.border = "solid 2px " + hoverColor;
            }
        //Function to remove the highlight from DIV.
            function removeHighlight(id)
            {                         
                if(selectedDIV != id)       
                    document.getElementById("div" + id).style.border = "solid 1px " + defaultColor;
            }
        //Function to Change the border for the grid which is selected,and re-set for others.
            function selectDiv(divID)
            {
                selectedDIV = divID;                
                document.getElementById("div1").style.border="solid 1px" + defaultColor;                
                document.getElementById("div" + divID).style.border = "solid 3px" + selectColor;
            }
        //Function to handle Paste Image click event for all Images.
        function pasteonclick(id)
            {        
                if(flagUploadingStarted == true)
                    return;
                    
                selectDiv(id);
                fnCall();
            }
        //Function be called when user presses CTRL + V.
        function fnKeyPress(sender, args) {            
            if(window.event.keyCode == 22)
                fnCall();                                                
            else if(window.event.keyCode == 24 && selectedDIV != "")
            {                                                                
                deleteonclick(selectedDIV);
            }
        }
        
    function pasteonclick(id)
    {        
        if(flagUploadingStarted == true)
            return;
            
        selectDiv(id);
        fnCall();
    }

    function deleteonclick(id)
    {
        if(flagUploadingStarted == true)
            return;
        switch(id)
        {
            case '1':
                    document.getElementById("img1").src = "";
                    document.getElementById("img1").style.display = "none";
                    document.getElementById("img1").value = "";
                    success1 = false;
                    break;            
        }
        selectDiv(id);
    }
        </script>

        <script type="text/javascript">
                                                   
            // Main Function to be called when user presses CTRL + V to paste the image into selected DIV.
                     function fnCall()
            {                                                                                                                                                                                                                                      
                try
                {                                                            
                    // Getting the Physical path on which,the images will be stored on client machine.
                    var PhysicalPathForTempImage = "c:\\Amit\\";
                    
                    // Getting ActiveX
                    //var objActiveX = document.getElementById("ClipboardActiveX");    
                    
                    //Newly created images will be saved at below path which is passed.
                    
                    var strFilePath = objActiveX.getCopiedImage(PhysicalPathForTempImage); 

                    // If Image file is not copied.
                    if (strFilePath.indexOf("ERR1") > -1)
                    {
                        alert("The file you have attempted to paste is not in a form that gTicket can store. It should be file with the extension '.jpg','.bmp', or '.gif'. Please contact your system administrator for help in uploading this file, as it may need to be converted to an appropriate format");
                        //document.getElementById("imgProgress").style.display = "none";
                        return false;
                    }
                    // If user has copied the contents which are not in Image format like text etc.
                    else if (strFilePath.indexOf("ERR2") > -1)
                    {
                        alert("The contents you have attempted to paste is not in a form that gTicket can store. It should be in format which can be saved in file with the extension '.jpg','.bmp', or '.gif'. Please contact your system administrator for help in uploading this file, as it may need to be converted to an appropriate format");
                        //document.getElementById("imgProgress").style.display = "none";
                        return false;   
                    }
                    else if (strFilePath.indexOf("ERR3") > -1)
                    {
                        alert("Failure occured in generating Image file from clipboard.Please try again after some time or if error continues contact your administrator quoiting this error.")
                        //document.getElementById("imgProgress").style.display = "none";
                        return false;
                    }
                    else if (strFilePath.indexOf("ERR4") > -1)
                    {
                        alert("System failed for creating target directory path provided in configuration file.Either create directory yourself or contact administrator to help you in creating / changing the directory path")
                        //document.getElementById("imgProgress").style.display = "none";
                        return false;
                    }
                    else
                    {
                        // The case if user has not selected any DIV and tried to paste the image.
                        if(selectedDIV == "")
                        {
                            alert("Please first select any DIV to paste an Image");
                            //document.getElementById("imgProgress").style.display = "none";
                        }
                        else
                        {
                            
                            //Image is displayed with selected source.
                            document.getElementById("img" + selectedDIV).style.display = "block";
                            document.getElementById("img" + selectedDIV).src = strFilePath;
                            
                            //Getting Image File Name.                        
                            //var strFileName = "";
                            //strFileName = strFilePath.substring(strFilePath.lastIndexOf("\\") + 1,strFilePath.length);
                            
                            //Storing the image File name in corresponding hidden Image variable.
                            switch(selectedDIV)
                            {
                                case "1":
                                            document.getElementById("hdnImageFileName1").value = strFilePath;
                                            break;
                            }                                                                    
                        }
                    }   
                }
                catch(ex)
                {
                    
                    var strError = ex.message;
                    // This Error may occur if user has not created the Temp Image Directory mentioned in Configuration File.
                    if(strError.indexOf("GDI+") > -1)
                    {
                        alert("The physical path you have provided in Configuration file,is not found to store temporary image files.Contact your administrator quoting this error.");                                                                
                        return false;
                    }                
                }         
            }                                                    
        </script>

        <script type="text/javascript">
        //---------------------------------------------------IMAGE 1 UPLOAD--------------------------------------------------------------
            function uploadImage1(strFileName)
            {                        
                var response;
                try{        
                    response = objActiveX.UploadFiles(strFileName,strURL,postVar);
                    if(response == "")
                    {
                        success1 = true;
                        spImage1Saved.style.visibility = "visible";
                        alert("Image uploaded successfully...");
                                                return true;
                    }
                    else
                    {
                        alert("Image 1 Uploading failed....See the response received....");
                        alert(response);
                        return false;
                    }    
                   }
                catch(ex)
                {
                    alert("Image 1 Uploading failed....See the response received....");
                    alert(response);
                }
            }
            /*
                Added : Functions to upload all available images to the server.
                By : Amit Champaneri
                On : 3th April 2008
            */
            function uplImages()
            {                                                
                    flagUploadingStarted = true;
                    
                    // Uploading Image 1 if its present.
                    if(document.getElementById("hdnImageFileName1").value != "")
                    {            
                        uploadImage1(document.getElementById("hdnImageFileName1").value);
                    }
            }
        </script>

        <table border="0" cellpadding="2" cellspacing="3" style="width: 50%; height: 50%;
            background-color: papayawhip;">
            <tr>
                <td style="height: 22px" align="center">
                    <img id="imgPaste1" src="Images/imgPaste.gif" class="LinkImage" title="Click here to Paste any copied Image"
                        onclick="javascript:pasteonclick('1');" />&nbsp;
                    <img id="imgDel1" src="Images/imgDelete.gif" class="LinkImage" title="Click here to Remove this Image"
                        onclick="javascript:deleteonclick('1');" />
                    <span id="spImage1Saved" class="DefaultLabelBold" style="visibility: hidden;">Image Uploaded...</span>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <div id="div1" class="ImageDIV" onclick="selectDiv('1');" onmouseover="Highlight('1');"
                        onmouseout="removeHighlight('1');" title="Select this DIV & Press CTRL+V to paste any copied Image.">
                        <img id="img1" style="display: none;" />
                        <asp:HiddenField runat="server" ID="hdnImageFileName1" />
                    </div>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <a href="javascript:uplImages();" style="font-family: Courior New">Upload This Image
                        To Server</a>
                </td>
            </tr>
            <tr>
                <td style="width: 100px">
                </td>
            </tr>
        </table>        
    </form>
</body>
</html>






View Postrgfirefly24, on 25 January 2013 - 11:28 AM, said:

 uploadImage1(document.getElementById("<%=hdnImageFileName1.ClientID%>").value)




Also for us to really help you you're going to need to post the full code so we can look it over.


I already tried this one, but still no luck :nervous: And, for the refference I posted the code that im currently working on.
Was This Post Helpful? 0
  • +
  • -

#9 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,673
  • Joined: 24-August 11

Re: Object Required Error.

Posted 28 January 2013 - 08:16 AM

Ahh, good point rgfirefly24. OP, you'll need to set ClientIDMode="static" on the control(s) that you're trying to access with the getElementById() call. So change this guy: <asp:HiddenField runat="server" ID="hdnImageFileName1" /> into this:

<asp:HiddenField 
    runat="server" 
    ID="hdnImageFileName1" 
    ClientIDMode="static" />



That will prevent WebForms from creating what I've always called the fully qualified control name, ie formName.divName.hdnImageFileName1 or whatever...

EDIT: fixed inline code tag

This post has been edited by h4nnib4l: 28 January 2013 - 08:17 AM

Was This Post Helpful? 0
  • +
  • -

#10 smurpetx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-January 13

Re: Object Required Error.

Posted 29 January 2013 - 05:40 PM

View Posth4nnib4l, on 28 January 2013 - 08:16 AM, said:

<asp:HiddenField 
    runat="server" 
    ID="hdnImageFileName1" 
    ClientIDMode="static" />



Thanks for the response h4nnib4l, But when i try adding ClientIDMode="static" still not getting image upload in the web server. Always got an error says, Object Required.
  function uplImages()
            {                                               
                    flagUploadingStarted = true;
                     
                    // Uploading Image 1 if its present.
                    if(document.getElementById("<%=hdnImageFileName1.ClientID%>").value != "") // Error occurs here, "Object Required"
                    {           
                        uploadImage1(document.getElementById("<%=hdnImageFileName1.ClientId%>").value);
                    }
            }



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1