Wednesday, May 4, 2016

Jquery for check float numbers on keypress event

Script

 <script type="text/javascript">  
     $(document).ready(function () {  
 $('.isFloat').keypress(function(event) {  
  if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {  
   event.preventDefault();  
  }  
 });  
  });  
 </script>  

 <asp:TextBox ID="txtTotlaMark" runat="server" pattern="^[0-9 .]{1,}$" class="isFloat" MaxLength="6" required></asp:TextBox>  

Javascript function to check numbers on keypress event

Sctipt

 <script type="text/javascript">  
  function isNumber(evt) {  
       evt = (evt) ? evt : window.event;  
       var charCode = (evt.which) ? evt.which : evt.keyCode;  
       if (charCode > 31 && (charCode < 48 || charCode > 57)) {  
         return false;  
       }  
       return true;  
     }  
   </script>  

 <asp:TextBox ID="txtMobile" pattern="^[0-9+ ]{1,}$" runat="server" CssClass="form-control1" MaxLength="15" onkeypress="return isNumber(event);"  required></asp:TextBox>  

Saturday, April 23, 2016

Maintain Panel/Div Scroll Position in UpdatePanel On Postback ASP.NET


  <form id="form1" runat="server">  
  <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" />  
   <script type="text/javascript">  
     // It is important to place this JavaScript code after Ajax ScriptManager / Toolkit Script  
     var xPos, yPos;  
     var prm = Sys.WebForms.PageRequestManager.getInstance();  
     function BeginRequestHandler(sender, args) {  
       if ($get('<%=Panel1.ClientID%>') != null) {  
        // Get X and Y positions of scrollbar before the partial postback  
        xPos = $get('<%=Panel1.ClientID%>').scrollLeft;  
       yPos = $get('<%=Panel1.ClientID%>').scrollTop;  
     }  
   }  
   function EndRequestHandler(sender, args) {  
     if ($get('<%=Panel1.ClientID%>') != null) {  
        // Set X and Y positions back to the scrollbar  
        // after partial postback  
        $get('<%=Panel1.ClientID%>').scrollLeft = xPos;  
        $get('<%=Panel1.ClientID%>').scrollTop = yPos;  
      }  
    }  
    prm.add_beginRequest(BeginRequestHandler);  
    prm.add_endRequest(EndRequestHandler);  
  </script>  
  <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
   <ContentTemplate>  
    <asp:Panel ID="Panel1" runat="server" Height="300px">  
     <%--Data--%>  
    </asp:Panel>  
   </ContentTemplate>  
  </asp:UpdatePanel>  
 </form>  

Tuesday, April 19, 2016

[Solved] Ajax async postback end does not work Script Error : Uncaught Sys.ScriptLoadFailedException: Sys.ScriptLoadFailedException: The script failed to load. Check for: Inaccessible path. Script errors. (IE) Enable 'Display a notification about every script error' under advanced settings. Missing call to Sys.Application.notifyScriptLoaded().

Solution For ajax async postback end does not work


 <script type="text/javascript">  
      function pageLoad(sender, args) {  
        //$(document).ready(function () {  
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginReq);  
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endReq);  
        Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit  
        if (navigator.userAgent.indexOf('WebKit/') > -1) {  
          Sys.Browser.agent = Sys.Browser.WebKit;  
          Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);  
          Sys.Browser.name = 'WebKit';  
        }  
        var xPos, yPos;  
        function beginReq(sender, args) {  
          //  $find(ModalPopup).show();  
        }  
        function endReq(sender, args) {  
          //  $find(ModalPopup).hide();  
        }  
        //});  
      }  
 </script>  

Use this script inside the page. :)