如何调用函数后面的代码 [英] how to call the code behind function
问题描述
嗨所有
我需要调用模糊事件函数后面的代码调用mobilevalidate函数并正常工作。但是我需要调用函数CheckDateTime后面的代码。请帮助我
hi all
i need to call the code behind the function on blur event the mobilevalidate function is called and working fine.but i need to call the code behind function CheckDateTime. pls help me
<script type="text/javascript">
function mobilevalidate() {
if (document.getElementById('<%= txtcallerid.ClientID%>').value != "") {
if (document.getElementById('<%= txtcallerid.ClientID%>').value.match(/^\d+$/))
//i need to call the code behind function <pre lang="xml">CheckDateTime
return true;
else
alert("Please Enter Valid Caller Id");
document.getElementById('<%= txtcallerid.ClientID%>').value = "";
document.getElementById('<%= txtcallerid.ClientID%>').focus();
}
alert("Please Enter Caller Id");
return false;
}
my.cs文件
my.cs file
[System.Web.Services.WebMethod]
public static string CheckDateTime(string args)
{
ddlload();
}
推荐答案
/))
//我需要调用函数后面的代码< pre lang = xml > CheckDateTime
返回true;
else
alert(& quot; Please Enter Valid Caller Id& quot;);
document.getElementById(&#39;& lt;%= txtcallerid.ClientID%& gt;&#39;)。value =& quot;& quot ;;
document.getElementById(&#39;& lt;%= txtcallerid.ClientID%& gt;&#39;)。focus();
}
alert(& quot; Please Enter Caller Id& quot;);
返回false;
}
/)) //i need to call the code behind function <pre lang="xml">CheckDateTime return true; else alert("Please Enter Valid Caller Id"); document.getElementById('<%= txtcallerid.ClientID%>').value = ""; document.getElementById('<%= txtcallerid.ClientID%>').focus(); } alert("Please Enter Caller Id"); return false; }
my.cs文件
my.cs file
[System.Web.Services.WebMethod]
public static string CheckDateTime(string args)
{
ddlload();
}
首先,您需要从页面中引用ScriptManager控件。
First you need to take reference of ScriptManager control from your page.
<asp:scriptmanager id="scriptmanager" runat="server"></asp:scriptmanager>
如果已经那里到你的主页然后没有必要。然后从您的mobilevalidate方法中,您可以调用服务器端方法CheckDateTime,如下所示
If it is already there to your masterpage then no need. Then from your mobilevalidate method you can call server side method CheckDateTime like as follows
PageMethods.CheckDateTime("yourargument");
您还可以使用jquery调用该服务器端方法或其他客户端库像原型。如果您在线搜索,那么您会发现许多代码示例。
You can also called that serverside method using jquery or other client side library like prototype. If you search online then you will find many codesample.
这篇关于如何调用函数后面的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!