是否可以在用户控件中使用 VS 2008 Javascript Intellisense?

发布于 2024-08-11 01:01:34 字数 2497 浏览 7 评论 0原文

一段时间以来,我一直在努力反对这个问题。我似乎无法让智能感知在 ascx 用户控件中工作,但它在普通的旧 aspx 中工作得很好。

这是一个示例 aspx 页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestScriptLoader._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptManager" ScriptMode="Debug" runat="server" >
        <Scripts>
            <asp:ScriptReference Path="http://ajax.microsoft.com/ajax/beta/0910/Start.js" ScriptMode="Inherit" />
        </Scripts>
    </asp:ScriptManager>

    </form>
    <script type="text/javascript">

    </script>
</body>
</html>

一旦我更新了 javascript intellisense (CTR+SHIFT+J),我就会在脚本标记中获得 MicrosoftAjax 的智能感知。

在 ascx 文件中

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="TestScriptLoader.Test" %>

<asp:ScriptManagerProxy ID="scriptManagerProxy" runat="server">
    <Scripts>
        <asp:ScriptReference Path="http://ajax.microsoft.com/ajax/beta/0910/Start.js" ScriptMode="Inherit" />
    </Scripts>
</asp:ScriptManagerProxy>

<script type="text/javascript">

</script>

我没有得到这样的快乐。

我唯一能想到的就是在一个单独的 JS 文件中为用户控件进行所有编码,但是我在特定用户控件中想要的功能与我将为它们编写的 javascript 存在一对一的映射,并且用户控件只会在页面中出现一次。基本上,如果不是绝对必要的话,我不想走这条路。

编辑

我还需要能够向这些控件添加服务引用,并具有可用的智能感知。

编辑

令我震惊的是,我遇到的问题是我在用户控件内使用 scriptmanagerproxy。用户控件无法知道它要与哪个 ScriptManager 关联,因此这就是 javascript 智能感知未更新的原因。

我可以通过将 scriptmanagerproxy 更改为 scriptmanager 控件来验证这一点,并且智能感知适用于脚本和服务引用。

编辑

我还认为我可以将 粘贴到页面中,用鳄鱼夹包裹:

<% if(false) { %>
    <asp:ScriptManager ID="fakeScriptManager" runat="server"/>
<% } %>


<asp:ScriptManagerProxy ID="scriptManagerProxy" runat="server">
    <Services>
        <asp:ServiceReference Path="~/path/to/your.svc" />
    </Services>
</asp:ScriptManagerProxy>

这似乎有效,但是 <; % if(false) %> 不会阻止构建控件...

有关如何实现此目的的任何想法吗?

I have been banging my head against this for a little while now. I just can't seem to get intellisense to work in a ascx user control, but it works fine in a plain old aspx.

Here is a sample aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestScriptLoader._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptManager" ScriptMode="Debug" runat="server" >
        <Scripts>
            <asp:ScriptReference Path="http://ajax.microsoft.com/ajax/beta/0910/Start.js" ScriptMode="Inherit" />
        </Scripts>
    </asp:ScriptManager>

    </form>
    <script type="text/javascript">

    </script>
</body>
</html>

I get intellisense for MicrosoftAjax in the script tag there, once I've updated javascript intellisense (CTR+SHIFT+J).

In the ascx file

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="TestScriptLoader.Test" %>

<asp:ScriptManagerProxy ID="scriptManagerProxy" runat="server">
    <Scripts>
        <asp:ScriptReference Path="http://ajax.microsoft.com/ajax/beta/0910/Start.js" ScriptMode="Inherit" />
    </Scripts>
</asp:ScriptManagerProxy>

<script type="text/javascript">

</script>

I get no such joy.

The only thing I can think of is to do all the coding for the user controls in a seperate JS file, but there is a one to one mapping for the functionality that I want in specific usercontrols to the javascript I will write for them, and the user control will only appear once in a page. Basically I don't want to go down this path if not absolutely neccesary.

EDIT

I also need to be able to add service references to these controls, and have intellisense available.

EDIT

It just struck me that the problem I'm up against is that I'm using a scriptmanagerproxy inside a usercontrol. The usercontrol has no way of knowing which ScriptManager it is to associate with, so that is why the javascript intellisense is not being updated.

I can verify this by changing the scriptmanagerproxy to a scriptmanager control, and intellisense works for both the script and service references.

EDIT

I also thought I could just stick an <asp:ScriptManager> into the page, wrapped in alligator clips:

<% if(false) { %>
    <asp:ScriptManager ID="fakeScriptManager" runat="server"/>
<% } %>


<asp:ScriptManagerProxy ID="scriptManagerProxy" runat="server">
    <Services>
        <asp:ServiceReference Path="~/path/to/your.svc" />
    </Services>
</asp:ScriptManagerProxy>

That appeared to work, but the <% if(false) %> does not prevent the control from being built...

Any ideas on how to get this to happen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终陌 2024-08-18 01:01:34

尝试将其添加到您的 ascx 顶部的某个位置(使用您实际的 jquery 文件位置)

<% if (false) { %><script type="text/javascript" src="../../Scripts/jquery-

1.3.2.min.js"><% } %>

感谢本博客文章的作者 Jouni Heikniemi:
http://www.heikniemi.net /硬编码/2009/08/jquery-intellisense-on-asp-net-mvc/

try adding this somewhere at the top of your ascx (use your actual jquery file location)

<% if (false) { %><script type="text/javascript" src="../../Scripts/jquery-

1.3.2.min.js"><% } %>

Credit goes to Jouni Heikniemi, the author of this blog post:
http://www.heikniemi.net/hardcoded/2009/08/jquery-intellisense-on-asp-net-mvc/

弄潮 2024-08-18 01:01:34

由于这个问题已经死了,我将在这里给出答案。

不,这是不可能的。原因是 Visual Studio 无法知道 scripmanagerproxy 应该引用哪个脚本管理器控件,因此它不引用任何脚本管理器。因此,编辑控件时智能感知不可用。

As this question has gone dead, I'm going to put an answer in here.

No. It is not possible. The reason is that there is no way for Visual Studio to know which scriptmanager control the scripmanagerproxy is supposed to be referencing, so it doesn't reference any script manager. Therefore the intellisense is unavailable whilst editing the control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文