iframe的错误,当RUNAT ="服务器" [英] iframe error when runat="server"

查看:357
本文介绍了iframe的错误,当RUNAT ="服务器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页一个用 =服务器并分配到onload事件的JavaScript函数一个iframe中。
当页面呈现它给出了一个错误的

CS1012:在字符文字太多字符

当我删除=服务器属性,它完美的作品,但我需要的iframe来=服务器。
我怎样才能解决这个问题?

 < IFRAME ID ='contentFrame的名字='contentFrame
   =服务器WIDTH =500
   的onload =resizeFrame(的document.getElementById('contentFrame'))>
 < / IFRAME>


解决方案

当您使用的 =服务器的 - 'onload事件开始被解析为HTML服务器控件的C#事件,如按钮。点击。您应设置在类的控制/页(JavaScript不)的 C#事件处理方法的名称。这code将工作:

 <脚本=服务器>
    无效contentFrame_onLoadServer(对象发件人,EventArgs的发送)
    {
        如果(!的IsPostBack)
            contentFrame.Attributes.Add(的onLoad,contentFrame_onLoadClient(););
    }
< / SCRIPT>
<脚本类型=文/ JavaScript的>
    功能contentFrame_onLoadClient(){
        resizeFrame(的document.getElementById('<%= contentFrame.ClientID%GT;'));
    }
    功能resizeFrame(元素){
        警报(元); //做你的逻辑在这里
    }
< / SCRIPT>
< IFRAME
    =服务器
    ID ='contentFrame
    名称= contentFrame
    WIDTH =500
    的onload =contentFrame_onLoadServer
    />

I have a iframe in one of my web pages with runat="server" and a javascript function assigned to the onload event.
When the page renders it gives an error as
"CS1012: Too many characters in character literal"
When I remove the runat="server" attribute it works perfectly but I need the iframe to runat="server".
How can I fix this?

<iframe id='contentFrame' name='contentFrame' 
   runat="server" width="500"
   onload="resizeFrame(document.getElementById('contentFrame'))">
 </iframe>

解决方案

When you use runat="server" - 'onload' starts being parsed as C# Event of Html Server Control, like Button.Click. You should set a name of C# event handler method in the class of your control/page (NOT JAVASCRIPT). This code will work:

<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"
    />

这篇关于iframe的错误,当RUNAT =&QUOT;服务器&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆