gpt4 book ai didi

asp.net - runat ="server"时出现 iframe 错误

转载 作者:行者123 更新时间:2023-12-04 21:58:53 27 4
gpt4 key购买 nike

我的一个网页中有一个 iframe,带有 runat="server"以及分配给 onload 事件的 javascript 函数。当页面呈现时,它给出了一个错误"CS1012: Too many characters in character literal"当我删除 runat="server"属性时,它可以完美运行,但我需要 iframe 来 runat="server"。我怎样才能解决这个问题?

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

最佳答案

当您使用 runat="server"- 'onload' 开始被解析为 Html 服务器控件的 C# 事件,如 Button.Click。您应该设置一个名称 C# 事件处理方法 在您的控件/页面(不是 JAVASCRIPT)的类中。此代码将起作用:

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

关于asp.net - runat ="server"时出现 iframe 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854573/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com