1

シンプルな 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?)
4

1 に答える 1

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"
    />
于 2013-03-28T06:21:53.460 に答える