2013-03-28 91 views
1

我打电话简单javscript方法,定义,不知道为什么这个错误发生CS1061:“ASP.station_pages_stationfield_aspx”不包含“resizeIframe”

<iframe height="100px;" onload="resizeIframe(this)" runat="server" id="frameDayLeft" 
        scrolling="no" style="border: none; width: 250px" frameborder="0"></iframe> 

,这里是细节错误:

Compiler Error Message: CS1061: 'ASP.station_pages_stationfield_aspx' does not contain a definition for 'resizeIframe' and no extension method 'resizeIframe' accepting a first argument of type 'ASP.station_pages_stationfield_aspx' could be found (are you missing a using directive or an assembly reference?) 

回答

2

其归因于runat="server"

它没有在客户端找到函数[Javascript函数],但它试图在服务器端[在.cs页面上]找到它。

这就是为什么错误来了。

试着在代码隐藏这件事>>

frameDayLeft.Attributes.Add("onload", " resizeIframe(this)"); 

不喜欢这个>>

<script runat="server"> 
    void contentFrame_onLoadServer(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
      contentFrame.Attributes.Add("onLoad", "contentFrame_onLoadClient();"); 
    } 
</script> 
<script type="text/javascript"> 
    function contentFrame_onLoadClient() { 
     resizeFrame(document.getElementById('<%=contentFrame.ClientID %>')); 
    } 
    function resizeFrame(element) { 
     alert(element); // do your logic here 
    } 
</script> 
<iframe 
    runat="server" 
    id='contentFrame' 
    name='contentFrame' 
    width="500" 
    onload="contentFrame_onLoadServer" 
    /> 
+0

谢谢你,你知道我可以调用javscript方法上的iframe – 2013-03-28 06:28:07

+0

frameDayLeft.Attributes的onload事件.Add(“onload”,“resizeIframe(this)”); – Freelancer 2013-03-28 06:29:12

+0

@VijaySinghRana通过我编辑的代码 – Freelancer 2013-03-28 06:40:43