I am trying to call an aspx.cs function using an external javascript when a button is clicked on.
Here is the aspx
<head runat="server">
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%= ResolveUrl ("~/Scripts/lookup.js") %>"></script>
</head>
<body>
<section class="webdesigntuts-workshop">
<asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' />
<form id="form1" runat="server">
<asp:TextBox type="search" name="search" id="sform" placeholder="What are you looking for?" runat="server" />
<asp:TextBox type="search" name="hdnText" id="hdnText" runat="server" />
<button id="Button1" runat="server" onclientclick="lookup();return false;">Search</button>
</form>
</section>
</body>
Here is my javascript lookup.js which is placed in the Scripts folder.
function Signup() {
var query = document.getElementById('<%=sform.ClientID %>').value;
PageMethods.lookupfromjs_Click(query);
function onSucess(result) {
alert(result);
}
function onError(result) {
alert('Cannot process your request at the moment, please try later.');
}
}
here is the aspx.cs function.
protected void lookupfromjs_Click(String query)
{
if (!String.IsNullOrEmpty(query))
{
hdnText.Text = "query= " + query + " look up number " + lookup_no++;
// sform.Text= "You are looking up the term " + query;
}
}
There are no errors as such in VS or in browser. But my breakpoints in browser dont seem to kick in. The java script is loaded correctly by the browser. However on button click nothing seems to happen.
Any help would be appreciated.
[System.Web.Services.WebMethod]. Did you already try this?