iframe的错误,当RUNAT ="服务器"

编程入门 行业动态 更新时间:2024-10-24 06:25:51
本文介绍了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;

本文发布于:2023-06-08 03:55:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/576168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   服务器   iframe   QUOT   RUNAT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!