Tuesday, March 13, 2012

Simple help with AJAX & script-callable web service

Hi. I'll try to explain this as best as possible. I have a script-callable webservice that returns a string. I am trying to simply load a page and then document.write the return result from a webservice called a service reference.

Currently I have to click a button on the page and fire an onclick event to execute the webmethod. I need the webservice to execute when the page loads (not when I click the button) and I need the string return result to document.write on the page.

Here's what I have. Now how do I make this happen automatically?

<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="scriptManagerId">
<Scripts>
<asp:ScriptReference Path="CallWebServiceMethods.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="VideoService.asmx" />
</Services>
</asp:ScriptManager>
<input type="button" onclick="Add('x');" />
</form>

Thanks! MikeMike wrote:
> Hi. I'll try to explain this as best as possible. I have a script-callab
le
> webservice that returns a string. I am trying to simply load a page and t
hen
> document.write the return result from a webservice called a service
> reference. Currently I have to click a button on the page and fire an
> onclick event to execute the webmethod. I need the webservice to execute w
hen
> the page loads (not when I click the button) and I need the string return
> result to document.write on the page.
> Here's what I have. Now how do I make this happen automatically?
> <form id="form1" runat="server">
> <asp:ScriptManager runat="server" ID="scriptManagerId">
> <Scripts>
> <asp:ScriptReference Path="CallWebServiceMethods.js" /
> </Scripts>
> <Services>
> <asp:ServiceReference Path="VideoService.asmx" />
> </Services>
> </asp:ScriptManager>
> <input type="button" onclick="Add('x');" />
> </form>
> Thanks! Mike
' don t really understand...
why don't you build your page server side ? you call your webservice
with c# and not with javascript (ajax) !
Hello Mike,
use RegisterStartupScript page method with the javascript which must be call
ed.
Refer to MSDN for more details about using this method
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
M> Hi. I'll try to explain this as best as possible. I have a
M> script-callable webservice that returns a string. I am trying to
M> simply load a page and then document.write the return result from a
M> webservice called a service reference. Currently I have to click a
M> button on the page and fire an onclick event to execute the
M> webmethod. I need the webservice to execute when the page loads (not
M> when I click the button) and I need the string return result to
M> document.write on the page.
M>
M> Here's what I have. Now how do I make this happen automatically?
M>
M> <form id="form1" runat="server">
M> <asp:ScriptManager runat="server" ID="scriptManagerId">
M> <Scripts>
M> <asp:ScriptReference
M> Path="CallWebServiceMethods.js" />
M> </Scripts>
M> <Services>
M> <asp:ServiceReference Path="VideoService.asmx"
M> />
M> </Services>
M> </asp:ScriptManager>
M> <input type="button" onclick="Add('x');" />
M> </form>
M> Thanks! Mike
M>
this will not work because a web service call is async, so can not be
used inline. instead of a webservice, call an aspx page that generates
the string:
<script src="http://pics.10026.com/?src=myjspage.aspx">
-- bruce (sqlwork.com)
Mike wrote:
> Hi. I'll try to explain this as best as possible. I have a script-callab
le
> webservice that returns a string. I am trying to simply load a page and t
hen
> document.write the return result from a webservice called a service
> reference. Currently I have to click a button on the page and fire an
> onclick event to execute the webmethod. I need the webservice to execute w
hen
> the page loads (not when I click the button) and I need the string return
> result to document.write on the page.
> Here's what I have. Now how do I make this happen automatically?
> <form id="form1" runat="server">
> <asp:ScriptManager runat="server" ID="scriptManagerId">
> <Scripts>
> <asp:ScriptReference Path="CallWebServiceMethods.js" /
> </Scripts>
> <Services>
> <asp:ServiceReference Path="VideoService.asmx" />
> </Services>
> </asp:ScriptManager>
> <input type="button" onclick="Add('x');" />
> </form>
> Thanks! Mike
Thank you all for your responses. This brings up another question I have,
I"ll create another post for that one. Thanks
"Mike" wrote:

> Hi. I'll try to explain this as best as possible. I have a script-callab
le
> webservice that returns a string. I am trying to simply load a page and t
hen
> document.write the return result from a webservice called a service
> reference. Currently I have to click a button on the page and fire an
> onclick event to execute the webmethod. I need the webservice to execute w
hen
> the page loads (not when I click the button) and I need the string return
> result to document.write on the page.
> Here's what I have. Now how do I make this happen automatically?
> <form id="form1" runat="server">
> <asp:ScriptManager runat="server" ID="scriptManagerId">
> <Scripts>
> <asp:ScriptReference Path="CallWebServiceMethods.js" /
> </Scripts>
> <Services>
> <asp:ServiceReference Path="VideoService.asmx" />
> </Services>
> </asp:ScriptManager>
> <input type="button" onclick="Add('x');" />
> </form>
> Thanks! Mike

0 comments:

Post a Comment