Simple help with AJAX & script-callable web service

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

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! Mike
 
Hello Mike,

use RegisterStartupScript page method with the javascript which must be called.
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>
 
Mike said:
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! 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) !
 
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="myjspage.aspx">


-- bruce (sqlwork.com)
 
Thank you all for your responses. This brings up another question I have,
I"ll create another post for that one. Thanks
 
Back
Top