Wednesday, 27 November 2013

Enable full text search

Exec this command for enable full text search, working with SQL Server 2008 and above version.

exec sp_fulltext_database enable

Tuesday, 19 November 2013

Resize text area

Auto resize text area according to text

Example 1:
window.setTimeout( function() {
    $("#<%= lblOrderNotesVw3.ClientID %>").height( $("#<%= lblOrderNotesVw3.ClientID %>")[0].scrollHeight ); }, 1);

"lblOrderNotesVw3" is my control id

you can also use

Example 2:
window.setTimeout( function() {
    $("textarea").height( $("textarea")[0].scrollHeight ); }, 1);

working with all text area  available on form. You can also use "each" loop

Example 3:
$(document).ready( function( ) {
    $("textarea").each( function( i, el ) {
        $(el).height( el.scrollHeight );
    ​});
});

Example 4:
If you want to use jquery plugin then 

<script src="Scripts/jquery.autosize.min.js" type="text/javascript"></script>
<script language="javascript">
        $(function () {
            $('#txt').autosize();
            //$('#txt').autosize({ append: "\n" });
        });
    </script>

 <form id="form1" runat="server">
    <div>
    <textarea id="txt"></textarea>
    </div>
 </form>

Thursday, 24 October 2013

jquery popup example

you can use new alias , for example

  var j = jQuery.noConflict();
  j("#btnOpen").click(function(){
    j(".locationPopupWrapper").show();  
  });

html section

<div class="locationPopupWrapper" style="display:none;">
<div class="locationPopup">
<h1>Show culture language<span><a href="#">x</a></span></h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
<td width="20%" align="center">1</td>
<td width="58%">India</td>
<td width="22%"><a href="#">English & Hindi</a></td>
 </tr>  
</table>
</div>
</div>
<input type="button" id="btnOpen" value="Model popup box" />

style section

body{margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;}
.locationPopupWrapper {background-color:rgba(0,0,0,0.5);position:absolute;height:100%;width:100%;}
.locationPopupWrapper .locationPopup{border:5px solid #cccccc;background-color:#FFFFFF;width:320px;height:280px;position:absolute;left:50%;top:50%;margin: -140px 0 0 -160px;font-size:12px;}
.locationPopupWrapper h1{font-size:20px;margin:0;padding:10px 0 10px 15px;}
.locationPopupWrapper h1 span{float:right;}
.locationPopupWrapper h1 span a {background-color:#808080;padding:10px 15px;color:#FFFFFF;text-decoration:none;}
.locationPopupWrapper .txtGray{color:#999999;font-size:12px;}
.locationPopupWrapper a{color:#005caf;font-size:12px;text-decoration:none;}

.locationPopupWrapper td{font-size:12px;padding:7px 0;}

Sunday, 11 August 2013

Call server side method client side in ASP.Net using jquery


jQuery allows you to call Server Side ASP.net methods from client side without any PostBack. Actually it is an AJAX call to the server but it allows us to call the method or function defined server side.

Client side methode

<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type = "text/javascript">
function fn_GetUserName() {
    $.ajax({
        type: "POST",
        url: "CS.aspx/GetUserName",
        data: '{name: "' + $("#<%=txtUserName.ClientID%>").val() + '" }',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function(response) {
            alert(response.d);
        }
    });
}
function OnSuccess(response) {
    alert(response.d);
}
</script>

Above the fn_GetUserName method makes an AJAX call which accepts the text box value  and returns a string value.
html code “cs.aspx”
<div>
Your Name :
<asp:TextBox ID="txtUsrNm" runat="server"></asp:TextBox>
<input id="btnClick" type="button" value="Show Current Time"
    onclick = "fn_GetUserName()" />
</div>

Server Side Methods
C#
[System.Web.Services.WebMethod]
public static string GetUserName(string name)
{
    return name;
}

Friday, 9 August 2013

Jquery Avoiding Conflicts with Other Libraries

Default jquery uses $ as a shortcut for jquery. Thus if you are using another javascript library that uses $ variable, you can run into conflicts with jquery.  In that condition you avoid jquery conflicts , put jquery. noConflict () after  it is loaded on to the page and before attempt to use jquery on the page.

JqueryNo-Conflict Mode

When you put jQuery into no-conflict mode, you have the option of assigning a new variable name to replace the $ alias. for example
<script>
   var $j = jQuery.noConflict();
   $j(document).ready(function() {
      $j( "div" ).hide();
  });
</script>
  

In this example  I am using $. You'll still be able to use the full function name jQuery as well as the new alias $j in the rest of your application. The new alias can be named anything you'd like: jq, $J, awesomeQuery, etc.
If you want to use  $ and don't care about using the other library's $ method, then another approach you might try: simply add the $ as an argument passed to your jQuery( document ).ready() function. This is most frequently used in the case where you still want the benefits of really concise jQuery code, but don't want to cause conflicts with other libraries. 


<script>
jQuery.noConflict();
jQuery( document ).ready(function( $ ) {
    $( "div" ).hide();
});
window.onload = function(){
    var mainDiv = $( "main" );
}
</script>

Including jQuery Before Other Libraries

If you include jQuery before other libraries, you may use jQuery when you do some work with jQuery, but the $ will have the meaning defined in the other library. There is no need to relinquish the $ alias by calling jQuery.noConflict().


<script src="<!—your jquery libraries -->"></script>
<script src="—your javascript libraries --"></script>
<script>
jQuery( document ).ready(function() {
    jQuery( "div" ).hide();
}); 
// Use the $ variable as defined in javascript libraries
window.onload = function() {
    var mainDiv = $( "main" );
}; 
</script> 

Summary Reference of the jQuery Function 

Create jquery alias with noConfilict()

<script>
var $jq = jQuery.noConflict();
 </script>

Immediately Invoked jquery Function Expression

<script> 
jQuery.noConflict(); 
(function( $ ) {
    // Your jQuery code here, using the $
})( jQuery ); 
</script>

Use the Argument jQuery(document).ready() Function

<script>
jQuery(document).ready(function( $ ) {
    // Your jQuery code here, using $ to refer to jQuery.
$('.mydiv').show();
});
</script>

Thursday, 13 June 2013

SQL Server CLR store procedure

There are several steps involved.
  1. Create the CLR Dll for the SQL function to use, and copy it to SQL Binn
  2. Register the CLR Dll in SQL server
  3. Create a normal SQL function that uses the CLR Dll

The 1st part is straight forward enough, the following code gives an example


using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void StoredProcedure1()
{
SqlPipe sp;
sp = SqlContext.Pipe;
String strCurrentTime = "Current System DateTime is: " + System.DateTime.Now.ToString();
sp.Send(strCurrentTime);
}

}

I copied the SqlServerCLRProject.Dll to the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn directory of the SQL server machine.

I also copied the Dll generated (SqlServerCLRProject.Dll) to the C:\ drive on the SQL server machine, as it makes the Dll registration code that needs to be run for SQL a bit easier.
So we’ve copied to \binn and C:\ so far, so now we need to register the Dll with SQL server. So lets look at that

Allow CLR types in the SQL server installation. Which is either done using the following SQL

EXEC dbo.sp_configure ‘clr enabled’,1 RECONFIGURE WITH
Once this is done we can register the CLR Dll with SQL, as follows

create assembly SqlServerCLRProject from ‘c:SqlServerCLRProject.dll’ WITH PERMISSION_SET = SAFE
Now that we've done that, all that left to do is create a normal SQL server store procedure that uses the CLR Dll. Which is simply done as follows

CREATE PROCEDURE CLRTestSP
WITH EXECUTE AS CALLER AS EXTERNAL NAME [SqlServerCLRProject].[StoredProcedures].[StoredProcedure1]

finally execute store procedure

EXEC CLRTestSP  

Register assembly in sql server
1. Copy dll in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn directory
2. create assembly assemblyname from ‘local folder path’ WITH PERMISSION_SET = SAFE
Or
Open sql server → Database → Programmability → Assemblies → New Assemblies → Browse assemblies path → press ok button
3. Enable CLR
4.
CREATE PROCEDURE CLRTestSP
WITH EXECUTE AS CALLER AS EXTERNAL NAME [SqlServerCLRProject].[StoredProcedures].[StoredProcedure1]

SqlServerCLRProject” is Assembly name.
StoredProcedures” class name
StoredProcedure1” methode name



Sql server Error
SQL SERVER – Fix : Error : Incorrect syntax near . You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the stored procedur “sp_dbcmptlevel”

Change the database compatibility level using following command.

For SQL Server 2005:
EXEC sp_dbcmptlevel 'TestDB', 90

For SQL Server 2008:
EXEC sp_dbcmptlevel 'TestDB', 100

TestDB” Database Name


Wednesday, 5 June 2013

Enabling CLR Integration

The common language runtime (CLR) integration feature is off by default in Microsoft SQL Server, and must be enabled in order to use objects that are implemented using CLR integration. To enable CLR integration, use the clr enabled option of the sp_configure stored procedure as shown:


sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO


You can disable CLR integration by setting the clr enabled option to 0. When you disable CLR integration, SQL Server stops executing all CLR routines and unloads all application domains.  

Common Language Runtime (CLR)

The Common Language Runtime (CLR) is programming that manages the execution of programs written in any of several supported languages, allowing them to share common object-oriented class es written in any of the languages. The Common Language Runtime is somewhat comparable to the Java Virtual Machine that Sun Microsystems furnishes for running programs compiled from the Java language. Microsoft refers to its Common Language Runtime as a "managed execution environment." A program compiled for the CLR does not need a language-specific execution environment and can easily be moved to and run on any system with Windows 2000 or Windows XP .




Programmers writing in any of Visual Basic , Visual C++ , or C# compile their programs into an intermediate form of code called Common Intermediate Language ( CIL ) in a portable execution ( PE ) file that can then be managed and executed by the Common Language Runtime. The programmer and the environment specify descriptive information about the program when it is compiled and the information is stored with the compiled program as metadata . Metadata, stored in the compiled program, tells the CLR what language was used, its version, and what class libraries will be needed by the program. The Common Language Runtime allows an instance of a class written in one language to call a method of a class written in another language. It also provides garbage collecting (returning unneeded memory to the computer), exception handling, and debugging services.