2
I’m calling a Pagemethod in a Javascript function, but it goes straight to the end not entering my function C#. Follow the code below:
<script type="text/javascript">
function enviar() {
if (document.getElementById('<% =CPF.ClientID %>').value == "") {
alert("Informe o documento do devedor!");
document.getElementById('<% =CPF.ClientID %>').focus();
return false;
}
PageMethods.VerificaCaixa(cartID, onSucess);
function onSucess(result) {
if (result != "") {
str = result.split("|||");
if (trim(str[0]) != "A") {
alert("Caixa fechado, favor abra o caixa e repita a operação!");
location.href = "/Caixa/Abrir/frmAbrCaixa.aspx";
}
}
}
}
</script>
<form name="frm" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
</asp:ScriptManager>
<table width="95%" border="0" align="center">
<tr>
<td class="tblNormal" align="right">CPF/CNPJ:</td>
<td class="tblNormal" valign="middle" align="left">
<asp:TextBox ID="CPF" runat="server" onblur='return valida();' MaxLength="14" Width="130px">
</td>
</tr>
<tr>
<td class="tblNormal" colspan="2" align="center">
<asp:Button ID="btnEnviar" runat="server" Text="Enviar" CssClass="btn btn-default" OnClick="btnEnviar_Click" OnClientClick="enviar();" />
</td>
</tr>
</table>
</form>
[WebMethod]
[ScriptMethod]
public static string VerificaCaixa(string cart)
{
CPesquisa pesquisa = new CPesquisa();
string parametros = "";
parametros = pesquisa.VerificaCaixa(cart);
return parametros;
}
add the code of your methods and what error you are having, so we will be able to help you :)
– Brunno
Even if I create the code with a deliberate error to try to simulate your mistake, my code will be different than yours. Post your code friend so we can view.
– durtto