Hi Guys!
I'm trying to call a js function on the "Onclientclick" event of an asp:button control.
Everything works fine!
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function datepicker_onchange() {
var name = document.getElementById('datepicker').value;
PageMethods.loadStandings(name, OnSuccess, OnError);
}
function OnSuccess(response) {
alert(response);
}
function OnError(error) {
alert("Error!");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptManager" runat="server" EnablePageMethods="true" ScriptMode="Release" LoadScriptsBeforeUI="true"></asp:ScriptManager>
<div>
<asp:TextBox id="datepicker" runat="server"></asp:TextBox>
<asp:Button id="btnJS" runat="server" OnClientClick="datepicker_onchange();return false;" />
</div>
</form>
</body>
</html>
This way, if I click on the button a popup shows what I wrote on the textbox.
But if i try to do it automatically on the "OntextChanged" event of the textbox (this way)...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Javascript.aspx.cs" Inherits="WebPages_Javascript" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function datepicker_onchange() {
var name = document.getElementById('datepicker').value;
PageMethods.loadStandings(name, OnSuccess, OnError);
}
function OnSuccess(response) {
alert(response);
}
function OnError(error) {
alert("Error!");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptManager" runat="server" EnablePageMethods="true" ScriptMode="Release" LoadScriptsBeforeUI="true"></asp:ScriptManager>
<div>
<asp:TextBox id="datepicker" runat="server"></asp:TextBox>
<asp:TextBox id="btnJS" runat="server" OnTextChanged="datepicker_onchange();return false;" />
</div>
</form>
</body>
</html>
... VS compiler throws a couple of errors..
Error 1 ) expected C:\inetpub\wwwroot\WebPages\Javascript.aspx 27
Error 2 Invalid expression term ')' C:\inetpub\wwwroot\WebPages\Javascript.aspx 27
this is the codebehind method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
public partial class WebPages_Javascript : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string loadStandings(string str)
{
string fullName = "Hello " + str;
return fullName;
}
}
I guess.. Are there different parameters expected by the different events of the asp controls??
Thx for your help! :-)