Simple help with AJAX & script-callable web service

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
 
M

Michael Nemtsev [MVP]

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>
 
S

Steph

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) !
 
B

bruce barker

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)
 
M

Mike

Thank you all for your responses. This brings up another question I have,
I"ll create another post for that one. Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top