Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top