C# 在javascript函数中使用asp.net的图像组件

C# 在javascript函数中使用asp.net的图像组件,c#,javascript,asp.net,image,C#,Javascript,Asp.net,Image,我找到了一个获取并设置图像维度的javascript。 通过引用此链接,我在我的asp.net网站中编写了如下代码: <img runat="server" id="MyImage" onload="if( this.width > this.height ){ this.width = 400; this.height = 600} else {this.width = 600; this.height=400}" /> 试试这个 Javascript: <

我找到了一个获取并设置图像维度的
javascript

通过引用此链接,我在我的
asp.net
网站中编写了如下代码:

<img runat="server" id="MyImage" onload="if( this.width >  
this.height ){ this.width = 400; this.height = 600} else {this.width = 600;   
this.height=400}" />
试试这个

Javascript:

<script type="text/javascript">
   function setDimension(me) {
  var th= document.getElementById(me);
   if( th.width >  
th.height ){ th.width = 400; th.height = 600} else {th.width = 600;   
th.height=400}
   }
</script>

如果我的
javascript
代码错误,请告诉我正确的代码:),谢谢!
<script type="text/javascript">
   function setDimension(me) {
  var th= document.getElementById(me);
   if( th.width >  
th.height ){ th.width = 400; th.height = 600} else {th.width = 600;   
th.height=400}
   }
</script>
<img runat="server" id="MyImage"  />
 MyImage.Attributes["onload"] = "setDimension(this.id)";