我在 <head> </head>中定义了: 
<script language="javascript" type="text/javascript"> 
var MaxWidth=70; 
var MaxHeight=70; 
var defaultPreSrc="img_df70.gif"; 
var maxbytes=49; 
function DownImage(ImgD) 

    var image=new Image();  
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){  
var rate = (MaxWidth/image.width  < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height; 
if(rate  <= 1){ 
ImgD.width = image.width*rate; 
ImgD.height =image.height*rate; 
}else{ 
ImgD.width = image.width; 
ImgD.height =image.height; 

    } 

     </script> 然后在下面调用: 
<body> 
     <form id="form1" runat="server"> 
         <div> 
<asp:Image ID="Image1" runat="server"  OnLoad="DownImage(this)"/> 
         </div> 
     </form> 
</body> 
为什么总提示我: 
错误“ASP.UpLoad_aspx”并不包含“DownImage”的定义

解决方案 »

  1.   

    Image是服务器控件 换成后台注册脚本试试
      

  2.   

    DownImage那是客户端的js函数,而OnLoad是服务器端的,这样编译通不过
    ==>
    <%@ Page Language="C#"%>
    <script runat="server">
    protected void Page_Load(object sender,EventArgs e)
    {
       Image1.Attributes.Add("onload", "DownImage(this)");
    }
    </script>
    <script language="javascript" type="text/javascript">  
    var MaxWidth=70;  
    var MaxHeight=70;  
    var defaultPreSrc="img_df70.gif";  
    var maxbytes=49;  
    function DownImage(ImgD)  
    {  
        var image=new Image();   
        image.src=ImgD.src;  
        if(image.width>0 && image.height>0){   
    var rate = (MaxWidth/image.width   < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height;  
    if(rate   <= 1){  
    ImgD.width = image.width*rate;  
    ImgD.height =image.height*rate;  
    }else{  
    ImgD.width = image.width;  
    ImgD.height =image.height;  
    }  
        }  
    }  
          </script>  
    <body>  
          <form id="form1" runat="server">  
              <div>  
    <asp:Image ID="Image1" runat="server"/>  
              </div>  
          </form>  
    </body>
      

  3.   

    <script language="javascript" type="text/javascript">  
    var MaxWidth=70;  
    var MaxHeight=70;  
    var defaultPreSrc="img_df70.gif";  
    var maxbytes=49;  
    function DownImage(ImgD)  
    {  
        var image=new Image();   
        image.src=ImgD.src;  
        if(image.width>0 && image.height>0){   
    var rate = (MaxWidth/image.width   < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height;  
    if(rate   <= 1){  
    ImgD.width = image.width*rate;  
    ImgD.height =image.height*rate;  
    }else{  
    ImgD.width = image.width;  
    ImgD.height =image.height;  
    }  
        }  
    }
    function doload(){
      doload = DownImage(document.getElementById("Image1"));
    }
    window.onload=function(){
      document.getElementById("Image1").onload = doload;
    }
    </script>   
    <body>  
          <form id="form1" runat="server">  
              <div>  
    <asp:Image ID="Image1" runat="server" />  
              </div>  
          </form>  
    </body>