script call:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default3.aspx. cs" inherits = "default3" %> </P> <p> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> </P> <p> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead runat = "server"> <br/> <title> No title page </title> <br/> <MCE: script Type = "text/JavaScript"> <! -- <Br/> function useradd () <br/>{</P> <p> var name = $ get ("txtname "). value; </P> <p> var Pwd = $ get ("txtpwd "). value; </P> <p> userservice. useradd (name, PWD, useraddcallback); </P> <p >}< br/> // call Method for rollback <br/> function useraddcallback (RES) </P> <p >{</P> <p> alert (RES); </P> <p >}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <Form ID = "form1" runat = "server"> <br/> <Div> <br/> <asp: scriptmanager id = "scriptmanager1" runat = "server"> <br/> <services> </P> <p> <asp: servicereference Path = "userservice. asmx "/> </P> <p> </services> </P> <p> </ASP: scriptmanager> <br/> </div> <br/> <H2> Ajax call XML Web Service Example 1 </H2> </P> <p> <Div style =" border: 1px solid black; width: 50%; padding: 10px; "> </P> <p> <Table class =" style1 "> </P> <p> <tr> </P> <p> <TD> </P> <p> User Name: </P> <p> </TD> </P> <p> <input id = "txtname" type = "text" /> </P> <p> </TD> </P> <p> </tr> </P> <p> <tr> </P> <p> <TD> </P> <p> password: </P> <p> </TD> </P> <p> <input id = "txtpwd" type = "password" /> </P> <p> </TD> </P> <p> </tr> </P> <p> <tr> </P> <p> <TD> </P> <p> </TD> </P> <p> <input id = "button2" type = "button" value = "Submit" onclick = "useradd () "/> </P> <p> </TD> </P> <p> </tr> </P> <p> </table> </P> <p> </div> </P> <p> </form> <br/> </body> <br/> </ptml>
Call by adding a web reference:
Call the WebService in the Local Solution
Add a new project> Web Service (WebService. asmx)
Add (int A, int B) in WebService. CS)
Code:
[Webmethod]
Public int add (int A, int B ){
Return A + B;
}
Save
Called in webpage (default. aspx)
Add a web reference first-> Web service in this solution-> Add a WebService. asmx reference (reference name; testwebservice)
Add textbox1, textbox2, label1, and button1 in default. aspx.
Add the call code to the trigger event of button1:
Testwebservice. WebService test = new testwebservice ();
Int A = convert. toint32 (textbox1.text );
Int B = convert. toint32 (textbox2.text );
Int C;
C = test. Add (A, B );
Label1.text = C. tostring ();