[英]jQuery document.ready + Asp.Net ContentPlaceholder cause Visual Studio intellisence problems
I want to execute JavaScript when document is ready without much syntax overhead. 我想在文档准备就绪时执行JavaScript,而没有太多语法开销。 The idea is to use
Site.Master
and ContentPlaceholder
: 这个想法是使用
Site.Master
和ContentPlaceholder
:
<script type="text/javascript">
$(document).ready(function () {
<asp:ContentPlaceHolder ID="OnReadyScript" runat="server" />
});
</script>
and in inherited pages just write plain code: 在继承的页面中,只需编写简单的代码:
<asp:Content ID="Content3" ContentPlaceHolderID="OnReadyScript" runat="server">
$("#Login").focus();
</asp:Content>
It works fine but Visual Studio complains and gives warnings. 它工作正常,但Visual Studio抱怨并给出警告。
Warning in master page is Expected expression
at the line <asp:ContentPlaceHolder
. 在母版页中的警告是
<asp:ContentPlaceHolder
行中的Expected expression
。
In inherited pages warning is Could not find 'OnReadyScript' in the current master page or pages.
在继承的页面中,警告是
Could not find 'OnReadyScript' in the current master page or pages.
I tried using Writer.Write
in master page to render script
tag and wrapping code: 我尝试在母版页中使用
Writer.Write
来呈现script
标记和包装代码:
<% Writer.Write(@"<script type=""text/javascript"">$(document).ready(function () {"); %>
<asp:ContentPlaceHolder ID="OnReadyScrit" runat="server" />
<% Writer.Write(@"});"); %>
but page rendering terminates after opening script tag is rendered. 但是页面呈现在打开脚本标签呈现后终止。 Html basically ends with
HTML基本上以
<script type="text/javascript">
How can I make it work? 我该如何运作?
This is a bug in Visual Studio's syntax highlighting. 这是Visual Studio语法突出显示中的错误。
Try 尝试
<%= @"<script type=""text/javascript"">$(document).ready(function () {" %>
<asp:ContentPlaceHolder ID="OnReadyScript" runat="server" />
<%= @"});" %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.