Wednesday, 2 October 2013

Calling server side method after specific time interval in Javascript

<script type="text/javascript">
   var timer;
   function chk_me()
   {

       clearTimeout(timer);
       timer = setTimeout(function validate()
       {
           var name = document.getElementById('<%=txtname.ClientID %>').value;
           var address = document.getElementById('<%=txtaddress.ClientID %>').value;
           PageMethods.ProcessIT(name, address, onSucess, onError);
           function onSucess(result) {
               alert(result);
           }
           function onError(result) {
               alert('Something wrong.');
           }
       }, 1000);
   }
</script>



<form id='form1' runat='server'>
    <asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' />

 <div>
        <p>Say bye-bey to Postbacks.</p>

       
        <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtaddress" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="btnCreateAccount" runat="server" Text="Signup" OnClientClick="HandleIT(); return false;" />
    </div>
    Timer <asp:TextBox ID="txt_1" runat="server"
        onkeyup="chk_me()"></asp:TextBox>
</form>

No comments:

Post a Comment