Tuesday, April 2, 2019

How to validate mobile number, email in jquery?

Definition :-

This tutorial will show you how to validate an email address and mobile number using jquery. This method has a few advantages over validating an email address using jquery, as the validation process takes place within the browser, meaning no server request or reload is necessary. 

Below is the jquery mobile, Email validation regular expression, mobile validation jquery regular expression which is for checking 10 digit number and first number should not be 0 and email validation jquery regular expressional which for checking global email format.

var mob = /^[1-9]{1}[0-9]{9}$/;
var eml = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

if (eml.test($.trim($("#<%=txtEmail.ClientID %>").val())) == false) {
    alert("Please enter valid email address.");
    $("#<%=txtEmail.ClientID %>").focus();
    return false;
 }


if (mob.test($.trim($("#<%=txtMob.ClientID %>").val())) == false) {
    alert("Please enter valid mobile number.");
    $("#<%=txtMob.ClientID %>").focus();
    return false;
}

Note that this is merely a simple email validation function.


Thank You,Arjun Walmiki

$document.ready() vs window.onload()

Defination:-

we often use window.onload() in javascript and $document.ready() in jquery and assume that both are same just jquery library wrap up javascript window.onload() and introduce $document.ready() but no there is much difference between them below is the explanation -


window.onload() (<body onload="func();" >) -

The load event fires when all the content on your page fully loaded including the DOM (document object model) content, asynchronous javascript, frames and images, you can also use body onload= both are same just window.onload = func(){} and <body onload="func();"> are different ways of using the same event.


$(window).load(function () {
         alert("window load complete");
});

window.onload = function () {
         alert("window load complete");
}

$document.ready() -

Jquery $document.ready function event executes a bit earlier than window.onload and called once the DOM(Document object model) is loaded on your page. DOM means all the html tags/script I.e.(anchor tag, table, div tag, paragraph tag etc..). It will not wait for the images, frames to get fully load. It means that it is the earliest stage in page load process.


$(document).ready(function () {
          alert("document is ready.");

});


The main difference is that $document.ready() event gets called as soon as your DOM is loaded. It does not wait for the contents to get loaded fully. For example, there are very heavy images on any web page and takes time to load. If you have used window.onload then it will wait until all your images are loaded fully, hence it slows down the execution. On the other side, $document.ready() does not wait for elements to get loaded.

$document.ready() , window.onload() inside update panel (partial postback) in asp.net

Since we know, in asp.net update panel gets partially postback (use xmlhttprequest object) to the server. Hence if you are using the $document.ready() or window.onload methods in your web page then you should be very careful to use these methods.

$document.ready() is not called in every partial postback. $document.ready() is called only one time i.e. during first time of page loading. if you want to get call back of every partial postback then you have to use pageLoad()method which is the part of scriptmanager generated script means if you want to use pageLoad() method then you need to use asp.net scriptmanager in the page.





Thank you,Arjun Walmiki



Friday, March 29, 2019

How to use SAP.NET Connector 2.0


Introduction
SAP is an inalienable system for large enterprise firms. We have to connect to this system if we need some data that belongs to SAP. The platforms can be Visual Studio 2008, Visual Studio 2005, Eclipse, or any other development tool.
But, there is a problem when connecting to SAP with Visual Studio 2008. The problem is SAP does not have a connector for Visual Studio 2005 and Visual Studio 2008. Up to Visual Studio .NET 2003 platform, there were no problems about connections to SAP.
As I mentioned in my other articles, the reason there is no connector for Visual Studio 2005 and Visual Studio 2008 is primarily marketing strategies. Let's not think why SAP did not make available an add-on for Visual Studio 2008, but think how can we solve this problem with available technologies.
Prerequisite Technologies
  • Visual Studio .NET 2003
  • Visual Studio 2008
  • SAP.NET Connector 2.0
  • Any SAP Application Server

Using the Code

As I mentioned above, we will first use Visual Studio .NET 2003. Our purpose is to connect to SAP with Visual Studio 2003. While operating, we will create a class library project. Then, we will give a reference to this application to Visual Studio 2008. Thus, the problem about connection to SAP with Visual Studio 2008 will be solved. Meanwhile, this solution is recommended by SAP.
Let's start creating a class library project first.

After creating the class library project, we will need to create a SAP Connector Proxy item as shown below.

Because we will make a connection to SAP, we have to look at the SAP Servers under the Server Explorer section. We will use one of the BAPIs of SAP’s user information. This is the general view of the BOR objects.



 We will use the ‘GetDetail’ method of the USER object. Drag and drop this method onto the SAPProxy1.sapwsdl file. Later on, there is no need for another class in our project. I am deleting the Class1.cs file.

We have now completed the operations in the Visual Studio .NET 2003 side. You should now build your project. The output ‘SAPUserDetailComponent.dll’ will be a required file while connecting to SAP in Visual Studio 2008.
Now, we will create a Windows project under Visual Studio 2008.

Before adding the DLL file of the previous project, we should add two more DLLs to our project. First, copy ‘SAPUserDetailComponent.dll’ to your project folder. Then, go to “..\Program Files\SAP\SAP .NET Connector 2.0″ and copy “SAP.Connector.dll” and “SAP.Connector.Rfc.dll” to your project folder.

We should pay attention to another point. The SAP Proxy is based on the SOAP protocol. So, we need to add the “System.Web.Services” DLL to our references.

I have only added simple controls into Form1. The logic is simple, a SAP username will be taken, and the profiles authorization of this user will be printed into a table to show. Form1 will look as shown below.

First, I inform the Visual Studio builder about the usage of the SAPUserDetailComponent assembly file:

using SAPUserDetailComponent;


Then, I write the code for the GetProfiles button’s Click event.
SAPProxy1 proxy = new SAPProxy1();
The SAPProxy1 class is referenced in our SAPUserDetail component reference.
BAPIADDR3 address = new BAPIADDR3();
BAPIUSCOMP companyName = new BAPIUSCOMP();
BAPIDEFAUL defaults = new BAPIDEFAUL();
BAPILOGOND logonData = new BAPILOGOND();
BAPISNCU snc = new BAPISNCU();
BAPIAGRTable activeGroups = new BAPIAGRTable();
BAPICOMREMTable addcomrem = new BAPICOMREMTable();
BAPIADFAXTable addfax = new BAPIADFAXTable();
BAPIADPAGTable addpag = new BAPIADPAGTable();
BAPIADPRTTable addprt = new BAPIADPRTTable();
BAPIADRFCTable addrfc = new BAPIADRFCTable();
BAPIADRMLTable addrml = new BAPIADRMLTable();
BAPIADSMTPTable addsmtp = new BAPIADSMTPTable();
BAPIADSSFTable addssf = new BAPIADSSFTable();
BAPIADTELTable addtel = new BAPIADTELTable();
BAPIADTLXTable addtlx = new BAPIADTLXTable();
BAPIADTTXTable addttx = new BAPIADTTXTable();
BAPIADURITable adduri = new BAPIADURITable();
BAPIADX400Table addx400 = new BAPIADX400Table();
BAPIPARAMTable parameter = new BAPIPARAMTable();
BAPIPROFTable profiles = new BAPIPROFTable();
BAPIRET2Table return0 = new BAPIRET2Table();
The above variables will be used while calling the SAP function.
SAP.Connector.Destination destination = new SAP.Connector.Destination();

We need to create a destination object to connect SAP. Later on, we will set the properties of thisdestination object as I have shown below.
destination.AppServerHost = YOUR HOST NAME OR IP
destination.Client = YOUR CLIENT NUMBER
destination.Password = USER'S PASSWORD
destination.SystemNumber = SYSTEM NUMBER
destination.Username = USER'S NAME


Our destination object will be a parameter for the SAPConnection class.

SAP.Connector.SAPConnection connection =
   new SAP.Connector.SAPConnection(destination);

And, our connection object will be assigned to the proxy object.

proxy.Connection = connection;

Now, we open the connection.

proxy.Connection.Open();

Call the SAP function:

proxy.Bapi_User_Get_Detail(tbUsername.Text.Trim(), out address, out companyName,
   out defaults, out logonData, out snc, ref activeGroups,
   ref addcomrem, ref addfax, ref addpag, ref addprt, ref addrfc,
   ref addrml, ref addsmtp, ref addssf, ref addtel, ref addtlx,
   ref addttx, ref adduri, ref addx400,
   ref parameter, ref profiles, ref return0);

Then, close the connection.

proxy.Connection.Close();

And, I will convert the result table of this function to an ADO table as I have shown below:

DataTable dt = profiles.ToADODataTable();
The last operation is we give the data table as a source for the grid view.

dgProfiles.DataSource = dt;

The result screen will be:


Thank you 

Arjun walmiki