我在我的网页一个用 =服务器并分配到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;
发布评论