簡體   English   中英

CS1061:“ ASP.station_pages_stationfield_aspx”不包含“ resizeIframe”的定義

[英]CS1061: 'ASP.station_pages_stationfield_aspx' does not contain a definition for 'resizeIframe'

我正在調用簡單的JavaScript方法,但不知道為什么會發生此錯誤

 <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?)

其原因是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"
    />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM