mobile ads

Featured Posts Coolbthemes

Please give your comments on posts.

Monday 1 September 2014

Datepicker - jQuery UI

link use in header section
------------------------
   
    <link rel="stylesheet" href="../../Styles/jquery-ui.css" />
     <link rel="stylesheet" href="../../Styles/runnable.css" />
     <script  type="text/javascript" src="../../Scripts/jquery-1.9.1.js"></script>
     <script  type="text/javascript" src="../../Scripts/jquery-ui.js"></script>
     <script  type="text/javascript" src="../../Scripts/script.js"></script>


script.js
---------

$(document).ready(
 


 /* This is the function that will get executed after the DOM is fully loaded */


  function () {
      $("#txtDate").datepicker({
      dateFormat: 'dd/mm/yy',
      changeMonth: true,//this option for allowing user to select month
      changeYear: true //this option for allowing user to select from year range
    });

);



<asp:TextBox ID="txtDate" runat="server"  Width="100px" ></asp:TextBox>

Tuesday 3 December 2013

Difference between Stored Procedures and Function in SQL

Stored Procedure 
A Stored Procedure is a program (or procedure) which is physically stored within a database. The advantage of a stored procedure is that when it is run, in response to a user request, it is run directly by the database engine, which usually runs on a separate database server. As such, it has direct access to the data it needs to manipulate and only needs to send its results back to the user, doing away with the overhead of communicating large amounts of data back and forth.
User-defined Function
A user-defined function is a routine that encapsulates useful logic for use in other queries. While views are limited to a single SELECT statement, user-defined functions can have multiple SELECT statements and provide more powerful logic than is possible with views.
Differences 
*. SP can return zero or n values whereas function can return one value which is mandatory. 
*. SP can have input/output parameters for it whereas functions can have only input parameters.
*. SP allows select as well as DML statement in it whereas function allows only select statement in it. 
*. Functions can be called from procedure whereas procedures cannot be called from function. 
*. Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function. 
*. We can go for transaction management in procedure whereas we can't go in function. 
*. SP can not be utilized in a select statement whereas function can be embedded in a select statement.
 

Friday 29 November 2013

Constructors

A constructor is a method in the class which gets executed when its object is created. Whenever a class or struct is created, its constructor is called. Even if we don't write the constructor code, default constructor will be created and called first when object is instantiated and sets the default values to members of claas. A class or struct may have multiple constructors that take different arguments.
 Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.Constructors have the same name as Class
Default constructor will no take parameters and will be invoked when instance is created.
We can prevent the class instantiation by declaring the constructor as private
class sample
{
      private sample()
     {
      }
}
Classes can define the constructors with parameter also and must be called by "new" keyword.
class sample
{
   public int y;
   public sample (int i)
   {
        y=i;
    }
}
constructor with parameters.
sample s= new sample(10);
A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only, and does not take access modifiers or have parameters.It is called automatically before the first instance is created or any static members are referenced.
It is called automatically to initialize the class before the first instance is created or any static members are referenced. The user has no control on when the static constructor is executed.
class SimpleClass
{
    // Static variable that must be initialized at run time.
    static readonly long baseline;
    // Static constructor is called at most one time, before any
    // instance constructor is invoked or member is accessed.
    static SimpleClass()
    {
        baseline = DateTime.Now.Ticks;
    }
}
A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.
Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.
If a static constructor throws an exception, the runtime will not invoke it a second time, and the type will remain uninitialized for the lifetime of the application domain in which your program is running.
It is mandatory to have the constructor in the class and that too should be accessible for the object i.e., it should have a proper access modifier. Say, for example, we have only private constructor(s) in the class and if we are interested in instantiating the class, i.e., want to create an object of
 the class, then having only private constructor will not be sufficient and in fact it will raise an error. So, proper access modifies should be provided to the constructors.

Monday 25 November 2013

Sending SMS from ASP.NET

Write a method in class file

public static void CreateRequestTOSENDSMS()
        {
            string url = "SMS gateway url, which will be provided by SMS people";//      HttpContext.Current.Request.Url.AbsoluteUri.ToString().Replace("AutoLogin", "Login");
            CookieContainer myCookieContainer = new CookieContainer();
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.CookieContainer = myCookieContainer;
            request.Method = "GET";
            request.KeepAlive = false;
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            System.IO.Stream responseStream = response.GetResponseStream();
            System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
            string srcString = reader.ReadToEnd();
             // Concat the string data which will be submit
            string formatString ="username={0}&pass={1}&senderid={2}&mtype=txt&tempid={3}&f1={4}&f2={5}&f3={6}&dest_mobileno={7}&response=Y";
            string postString = string.Format(formatString, "demo12", "demo123", "DEMOVL", "1018", "1234", "5673", "tyyty");
            byte[] postData = Encoding.ASCII.GetBytes(postString);

            // Set the request parameters
            request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "POST";
            request.Referer = url;
            request.KeepAlive = false;
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; CIBA)";
            request.ContentType = "application/x-www-form-urlencoded";
            request.CookieContainer = myCookieContainer;
            System.Net.Cookie ck = new System.Net.Cookie("SMS", "Value of SMS cookie");
            ck.Domain = request.RequestUri.Host;
            request.CookieContainer.Add(ck);
            request.CookieContainer.Add(response.Cookies);
            // Submit the request data
            System.IO.Stream outputStream = request.GetRequestStream();
            request.AllowAutoRedirect = true;
            outputStream.Write(postData, 0, postData.Length);
            outputStream.Close();
            // Get the return data
            response = request.GetResponse() as HttpWebResponse;
            responseStream = response.GetResponseStream();
            reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
            srcString = reader.ReadToEnd();
            }

The parameters "url", "formatstring" may vary from one SMS provider to another. Add these namespaces.
using System.Text;
using System.IO;
using System.Net;

Why we use Static Keyword?

The static keyword defines, that the class or property or method we declare as static does not require a previous instance of an object. In the other hand, a static method for example cannot use any instance method / instance property of the own object.

Also static defined things will be optimized by the compiler, for example that a static object is only written once in the memory and everything accesses to the same object. When we use static keyword it means there is no need to create an instance of object . Static class including a static method can called by class name. Static class can have only static methods.