Hi,
I am invoking one webservice method using ajax post call. when test with int type, it invokes web service method correctly. But when I tried with hidden value which is string type, it gives internal server error.
//first way --> testing with int type. this invokes the method " getseeestionval.
<script type="text/javascript">
function getval() {
alert('hi');
var hidval = document.getElementById('<%=bid.ClientID%>').value;
alert(hidval);
$.ajax({
type:"POST",
url:"../WebService5.asmx/getseeestionval",
data:"{'theValue':'1'}",
dataType:"json",
contentType:"application/json; charset=utf-8",
success:function (data) {
OnSuccess(data.d);
},
error:function (xhr, status, error) {
OnFailure(error);
}
});
}
function OnSuccess(dateTime) {
if (dateTime) {
document.getElementById("currentDate").innerHTML = dateTime;
}
}
function OnFailure(error) {
alert(error);
}
</script>
aspx page:
calling javascript function when focus on text box
<asp:TextBox ID="txtid" runtat="server" onfocus="getval();">
WebService5.asmx.cs page
[WebMethod(EnableSession = true)]
public string getseeestionval(int theValue)
{
return "s";
}
//second way --> testing with string type I mean passing hidden value which is string type. this does not invoke
NOTE : I am getting value in hidden value. I tested in alert function. I am getting hidden value.
the method " getseeestionval. It throws internal server error.
<script type="text/javascript">
function getval() {
var hidval = document.getElementById('<%=bid.ClientID%>').value;
alert(hidval);
$.ajax({
type:"POST",
url:"../WebService5.asmx/getseeestionval",
data:"{'theValue':'"+hidval+"'}",
dataType:"json",
contentType:"application/json; charset=utf-8",
success:function (data) {
OnSuccess(data.d);
},
error:function (xhr, status, error) {
OnFailure(error);
}
});
}
function OnSuccess(dateTime) {
if (dateTime) {
document.getElementById("currentDate").innerHTML = dateTime;
}
}
function OnFailure(error) {
alert(error);
}
</script>
aspx page:
calling javascript function when focus on text box
<asp:TextBox ID="txtid" runtat="server" onfocus="getval();">
WebService5.asmx.cs page
[
WebMethod(EnableSession = true)]
public string getseeestionval(string theValue)
{
return "s";
}
how to solve this problem.