Monday, 3 February 2014

Sql server change column data types and rename column

I have used below statement successful for rename column and change column data type in sql server

Its working

EXEC  sp_rename 'PurchaseOrder.bisOrderNow' , 'vcOrdeNow'

ALTE TABLE PurchaseOrder ALTER  COLUMN  vcOrdeNow VARCHAR(60)

"PurchaseOrder" is Table name.

Friday, 31 January 2014

Bind dropdown with json response

 function BindHrs() {

        $.ajax({
            type: "POST",
            url: "Webservices/manage-orders.asmx/BindHrs",
            data: "{'lOutletId':'" + '<%= OutletId %>' + "', 'pOrderdate':'" + $('#<%= hfSelectDate.ClientID %>').val() + "','sOrderType':'" + $('#<%= ddlOrderType.ClientID %>').val() + "'}",
            contentType: "application/json",
            dataType: "json",
            success: function (msg) {              
                var evals = msg.d.split(',');              
                for (var i = 0; i < evals.length; i++) {
                    var myArray = evals[i].split('-');

                    $("#<%= ddlHrs.ClientID %>").append($("<option></option>").val(myArray[1]).html(myArray[0]));
                }
            },
            failure: function (msg) {
                alert('Sorry no record found');
            }

        });
    }


 [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    [WebMethod]
    public string BindHrs(string lOutletId, string pOrderdate, string sOrderType)
      {
          System.Text.StringBuilder builder = new System.Text.StringBuilder();
          string Weekday = Convert.ToString(Convert.ToDateTime(pOrderdate).DayOfWeek);
          List<Outlet.OutletOperatingHour> outOptHr = Outlet.OutletOperatingHour.PopulateData(Convert.ToInt64(lOutletId), sOrderType, Weekday.Substring(0, 3));//(Outlet.WeekDays)Enum.Parse(typeof(Outlet.WeekDays), Weekday.Substring(0,3))
          string opens = Convert.ToString(outOptHr.Min(m => m.sOpenTime));
          string close = Convert.ToString(outOptHr.Max(m => m.sCloseTime));
          DataTable dtTime = Outlet.TimeValues();
          List<String> strKey = new List<String>();
          var dt = dtTime.AsEnumerable().Select(row => new { Text = Methods.Convert24HrsTo12HrsFormat(row.Field<string>("Value")), Value = row.Field<string>("Value") }).Where(p => Convert.ToInt32(p.Value) >= Convert.ToInt32(opens) && Convert.ToInt32(p.Value) <= Convert.ToInt32(close));
       
          foreach (var st in dt)
          {            
              builder.Append(""+st.Text +"-"+st.Value+"");
              builder.Append(",");
          }
          return builder.ToString().TrimEnd(',');

      }

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>