身体RUNAT ="服务器"导致编译错误

编程入门 行业动态 更新时间:2024-10-25 08:15:26
本文介绍了身体RUNAT ="服务器"导致编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在母版页我有以下标记

<body id="body" runat="server">

我已经设置 =服务器因为我需要能够访问body元素在code-落后。

I have set runat="server" because I need to be able to access the body element in code-behind.

我现在想一个JavaScript函数调用添加到身体的onload 事件,像这样:

I would now like to add a JavaScript function call to the body onload event, like this:

<body id="body" runat="server" onload="someJavaScriptFunction();">

然而,这是给我的一个编译错误,用一条消息无法解析符号someJavaScriptFunction();。如果我运行该应用程序我得到一个错误,告诉我​​

However, this is giving my a compile error, with a message of "Cannot resolve symbol someJavaScriptFunction();". If I run the application I get an error telling me

Compiler Error Message: CS1026: ) expected

这是怎么回事? 的onload 是一个客户端事件,那么,为什么这个ASP.NET的编译器护理?

What is going on here? onload is a client-side event, so why does the ASP.NET compiler care about this?

推荐答案

您需要在code的后面添加此;

You need to add this in the code behind;

protected void Page_Load(object sender, EventArgs e) { body.Attributes.Add("onload", "someJavaScriptFunction();"); }

添加 =服务器标签使得它的服务器标签,哪怕是不明确prefixed者之一(如&LT; ASP:面板/&GT; )。在服务器上的标签,任何 onXXXX 事件处理程序处理服务器端事件,而不是客户端事件(除了当客户显式调用出来,如用的OnClientClick对于按钮)。

Adding runat="server" to a tag makes it a server tag, even if it isn't one of the explicitly prefixed ones (e.g. <asp:Panel />). On server tags, any onXXXX event handlers handle the server-side events, not the client-side events (except for when "client" is explicitly called out, such as with OnClientClick for buttons).

更多推荐

身体RUNAT =&QUOT;服务器&QUOT;导致编译错误

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

发布评论

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

>www.elefans.com

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