Wednesday, March 21, 2012

Compilation Error

Hi everyone,

I receive the following compilation error when I try to preview my project (made in Web Developer and programming using mainly C#) in my web browser, "Compiler Error Message:CS0246: The type or namespace name 'WebMethod' could not be found (are you missing a using directive or an assembly reference?)"

Am I suppose to declare WebMethod or something? Please help!

Thanks heaps,

Britt.

Could you provide the source code for your page? I think I might know what it is.

Kind regards

Scotty


No worries. Here it is:

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<scripttype="text/javascript">

function pageLoad ()

{

var img=$get ("Image1");

img.style.visibility="hidden";

PageMethods.GetSlides (OnSuccess,OnError,OnTimeOut);

}

function OnSuccess (result)

{

slideshow.set_Slides (result);

slideshow.set_Delay (2000);

slideshow.Play ();

}

function OnError (result)

{

alert(result.get_message () );

}

function OnTimeOut (result)

{

alert (result);

}

</script>

<title>Slideshow Try out</title>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"EnablePageMethods="True">

<Scripts>

<asp:ScriptReferencePath="~/JScript.js"/>

</Scripts>

</asp:ScriptManager>

<div>

<br/>

<br/>

<tablestyle="width: 440px; height: 331px">

<tr>

<tdstyle="height: 51px">

<img></img><br/>

<br/>

<imgsrc=""/></td>

</tr>

<tr>

<td>

<inputid="btnLast"style="width: 34px"type="button"value="<<"onclick="slideshow.ShowLast ()"/>

<inputid="btnPrevious"style="width: 32px"type="button"value="<"onclick="slideshow.ShowPrevious ()"/>

<inputid="btnPause"style="width: 33px"type="button"value="||"onclick="slideshow.Pause ()"/>

<inputid="btnPlay"style="width: 31px"type="button"value="?"onclick="slideshow.Play ()"/>

<inputid="btnNext"style="width: 29px"type="button"value=">"onclick="slideshow.ShowNext ()"/>

<inputid="btnFirst"style="width: 32px"type="button"value=">>"onclick="slideshow.ShowFirst ()"/></td>

</tr>

</table>

</div>

</form>

</body>

</html>


Hi,aussienerd

You forget the bold code as follow:

<asp:ScriptManager runat="server" ID="scriptManagerId">
<Scripts>
<asp:ScriptReference Path="CallWebServiceMethods.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>

</asp:ScriptManager>

Check this link for answer and more help:

  • Exposing Web Services to Client Script

    Provides examples of creating and exposing Web services.

    Calling Web Services from Client Script

    Provides examples of calling Web service methods from the browser by using JavaScript.

  • No comments:

    Post a Comment