p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Professional (http://p2p.wrox.com/forumdisplay.php?f=57)
-   -   Javscript works well in aspx page but fails... (http://p2p.wrox.com/showthread.php?t=43963)

vivek_inos June 14th, 2006 02:00 AM

Javscript works well in aspx page but fails...
 
Hello Everyone,

I am using Javascript which is called on click of image from c# code...
this script works fine in aspx page but i use this same code in ascx.cs custom control this script fails to detect an object such as div and image...this is the script....when i com[ared the view source of both aspx page and custom control. The Script in page was in head section and postback script was found. Where in Custom Control view source the javascript was in body section and no post back script was found.... Any Help or Idea will be appreciated

<SCRIPT language="javascript">

 function Toggle( commId, imageId )
  {

    var div = this.document.getElementById(commId);
    var GetImg = this.document.getElementById(imageId);
     alert (commId+" and "+imageId)
displays corresponding value
    alert (div+" and "+GetImg)
fails to display detects object and displays null
    if (document.all[commId].style.display == 'none')
    {
     document.all[commId].style.display = 'block';
     document.all[imageId].src = '../Images/expand.gif';
    }
    else
    {
     document.all[commId].style.display = 'none';
     document.all[imageId].src = '../Images/collapse.gif';
    }
    }
</SCRIPT>




Best Regards,
Vivek.

jbenson001 June 15th, 2006 12:29 PM

If you place this code in your user control, it is looking for the dive and GetImg objects in the user control, not the page.


vivek_inos June 18th, 2006 11:26 PM

thanks a lot,
i had found the solution its woriking fine as u told i had done that i added the control name as prefix to my grid which contains this objects..this helps my page to detect the div an GetImage as an object...



Best Regards,
Vivek.


All times are GMT -4. The time now is 01:23 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.