Is it possible to add a new ServiceReference
instance to the ScriptManager
on the Page
during an asynchronous postback so that subsequently I can use the referenced web service through client side script?
I'm trying to do this inside a UserControl
that sits inside a Repeater
, that's why adding the ScriptReference programmatically during Page_Load
does not work here.
EDIT 2: This is the code I call from my UserControl
which does not do what I expect (adding the ServiceReference to the ScriptManager during the async postback):
private void RegisterWebservice(Type webserviceType)
{
var scm = ScriptManager.GetCurrent(Page);
if (scm == null)
throw new InvalidOperationException("ScriptManager needed on the Page!");
scm.Services.Add(new ServiceReference("~/" + webserviceType.Name + ".asmx"));
}
My goal is for my my UserControl to be as unobtrusive to the surrounding application as possible; otherwise I would have to statically define the ServiceReference
in a ScriptManagerProxy
on the containing Page
, which is not what I want.
EDIT:
I must have been tired when I wrote this post... because I meant to write ServiceReference
not ScriptReference
. Updated the text above accordingly.
Now I have:
<asp:ScriptManagerProxy runat="server" ID="scmProxy">
<Services>
<asp:ServiceReference Path="~/UsefulnessWebService.asmx" />
</Services>
</asp:ScriptManagerProxy>
but I want to register the webservice in the CodeBehind.