views:

1010

answers:

1

Hi,

I've created a Web Service that I need to use in my .ascx page. I can't just add this:

<asp:ScriptManager ID="OWUScripts" runat="server">
    <Services>
        <asp:ServiceReference Path="~/OWUDashboard.asmx" />
    </Services>
</asp:ScriptManager>

Because then I have multiple ScriptManagers on the page. So I did a little research and found out that I need to add this to the Page_Load event...

Dim myScriptManager As ScriptManager = ScriptManager.GetCurrent(Me.Page)

Dim objServiceReference As ServiceReference = New ServiceReference()
objServiceReference.Path = "~/MyService.asmx"
myScriptManager .Services.Add(objServiceReference)

But I can't access the Page_Load event since there's already one pre-set (with it being a skin and all) So I threw the code between <script runat="server"></script>

However it's giving me an error saying "Declaration Expected"... I took out a few lines and it seemed to be saying it couldn't find Me.Page (Or it was coming up null)

Any insight as to what I'm doing wrong?

Can I access Me.Page from <script runat="server"> like I am or should I be doing it a different way?

+4  A: 

Fur such cases there is a ScriptManagerProxy class that you can use to add references declaratively. The proxy class is used whenever there is already defined ScriptManger in a "parent" page. You work with the ScriptManagerProxy the same way as with the regular ScriptManager. More information regarding the proxy class can be found here.

Example markup:

<asp:ScriptManagerProxy runat="server" ID="Manager">
<Scripts>
    <asp:ScriptReference Path="~/JScript.js" />
</Scripts>
</asp:ScriptManagerProxy>
Genady Sergeev