Create a custom autocomplete control in ASP.NET MVC

How to create a custom HTML control in ASP.NET MVC?

using System;
using System.Web.Mvc;

namespace MvcApplication1.Helpers
     public static class LabelExtensions
          public static string Label(this HtmlHelper helper, string target, string text)
               return String.Format("", target, text);

Refer link:

Auto complete custom control: Download


Nth Highest Salary

Create table #tblEmployee (Id int, [Name] varchar(100), City varchar(100), Salary decimal (10,3))
Insert into #tblEmployee values(1, 'Prakash Rathod', 'Gandhinagar', 100000)
Insert into #tblEmployee values(2, 'Salman Khan', 'Mumbai', 100000)
Insert into #tblEmployee values(3, 'Aamir Khan', 'Mumbai', 90000)
Insert into #tblEmployee values(4, 'Katrina Kaif', 'Mumbai', 80000)
Insert into #tblEmployee values(5, 'Rashmi Bansal', 'Indor', 95500)
Insert into #tblEmployee values(6, 'Jinen Kothari', 'Ahmedabad', 60000)
Insert into #tblEmployee values(7, 'Deepika Patel', 'Gandhinagar', 60000)
Insert into #tblEmployee values(8, 'Ranbir Singh', 'Gandhinagar', 36000)
Insert into #tblEmployee values(9, 'Mohini Trivedi', 'Ahmedabad', 25000)
Insert into #tblEmployee values(10, 'Jalpa Patel', 'Surat', 100000)
Insert into #tblEmployee values(11, 'Kruti Patel', 'Surat', 100000)
Insert into #tblEmployee values(12, 'Viral Zala', 'Surat', 100000)
Insert into #tblEmployee values(13, 'Dipbha Parmar', 'Surat', 100000)
Insert into #tblEmployee values(14, 'Jagubha Chotu', 'Gandhinagar', 100000)
Insert into #tblEmployee values(15, 'Kailashba Rathod', 'Surat', 100000)
select * from #tblEmployee

--2nd hightest salary
--SELECT top 1 Salary FROM #tblEmployee
--WHERE Salary < (select max(salary) from #tblEmployee ) ;With Result As ( select salary, DENSE_RANK() over (order by salary desc) as RowNumber from #tblEmployee ) select salary from result where RowNumber=1 drop table #tblEmployee

Generate x509 certificate in pem, cer and pfx and export public key

Generate x509 cerntifcate

c:\Demo>openssl req -x509 -days 365 -newkey rsa:2048 -keyout my-key.pem -out -my-cert.pem

Generating a RSA private key
writing new private key to ‘my-key.pem’
Enter PEM pass phrase:
Verifying – Enter PEM pass phrase:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:Gujarat
Locality Name (eg, city) []:Gandhinagar
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Your Company Name
Organizational Unit Name (eg, section) []:Development
Common Name (e.g. server FQDN or YOUR name) []
Email Address []:[email protected]

Generate .PFX file

c:\Demo>openssl pkcs12 -export -in -my-cert.pem -inkey my-key.pem -out my-xero.pfx
Enter pass phrase for my-key.pem:
Enter Export Password:
Verifying - Enter Export Password:

Generate .cer certificate

c:\Demo>openssl pkcs12 -export -in -my-cert.pem -inkey my-key.pem -out my-xero.cer
Enter pass phrase for my-key.pem:
Enter Export Password:
Verifying - Enter Export Password:

Export public key

c:\Demo>openssl pkcs12 -in my-xero.pfx -clcerts -nokeys -out myxeropublic.cer
Enter Import Password:


Send an image (stored as base64 string) inline in email

Byte[] bitmapData = Convert.FromBase64String(FixBase64ForImage("Base64 string"));
System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData);
var imageToInline = new LinkedResource(streamBitmap, MediaTypeNames.Image.Jpeg);
imageToInline.ContentId = "Pic1";
AlternateView avHtml = AlternateView.CreateAlternateViewFromString(mailMessage.Body, null, MediaTypeNames.Text.Html);

public static string FixBase64ForImage(string Image)
System.Text.StringBuilder sbText = new System.Text.StringBuilder(Image, Image.Length);
sbText.Replace("\r\n", string.Empty); sbText.Replace(" ", string.Empty);
return sbText.ToString();

Put/Delete http verb not working server

Please add following code in web.cofig file.

			<remove name="WebDAVModule"/>
			<remove name="FormsAuthentication" />
			<remove name="ApplicationInsightsWebTracking" />
			<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
			<remove name="WebDAV" />
			<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
			<remove name="OPTIONSVerbHandler" />
			<remove name="TRACEVerbHandler" />
			<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

If not solve then please follow link.

Honesty and humanity is not only demesne of people who has status in society

The day 6th September 2016, I and my friend met at tea stall near G-2 circle for breakfast around 9.00 am. Usually, we meet there not daily. As always, we do fun there by teasing uncle (the shopkeeper) and left this place around 10:00 am.

My friend was doing job in Ahmedabad and we live in Gandhinagar. He always park his motorcycle near GH-2 Circle, cross the road to pick up bus/car for Ahmedabad. It was his daily routine. But that day, he could not crossed the road. When he was crossing the road, he got an accident with an auto-rickshaw. Ajay (my friend) covered his face by his hand, however, the speed was high so an auto-driver could not control, the front-mirror of auto broke Ajay’s nose and cut right hand palm. He was unconscious for few minutes.

A girl who was traveling in auto, called 108 and someone call me from my friend’s mobile because in call list, last dial number was mine. I was reach at an accident place in 5 minutes and talked to a girl and others. Also, call to 108, van reached after 10 minutes after my call. Shifted to Civil hospital, Gandhinagar.

Government servant, always follow the rules even though a Man is dying. The same story happened what we usually see in movies. Doctors did not ready to do treatment until not ready to do police case, an auto drive came with us as human being but he was afraid by police case. Mr. Chauhan begged me to do not do police case. Mr. Chauhan words were “I am not runaway as others. I came with you in hospital. I have no money. I am poor. Please do not do police case.” (“સાહેબ હું ભાગી ના ગયો બાકી બધા તો ભાગી જાય છે. મારી પાસે રૂપિયા નથી મારા પર પોલીસ કેશના કરો. હું ગરીબ માનસ છુ.”) He told me other things too but dislike to describe here. I convinced him, don’t worry, we will not do police but in front of doctor please ready to do police case so doctor start treatment. He agreed, doctor start treatment by confirming us, we will do a police case. A policeman reach after 2 hours in hospital. I talked with him, it was an accident, and no one is accused. So please do not do police case against auto-driver. Ajay was also gave same statement as he dislike to do police case to poor auto-driver. We, all know now a days, there is not an easy to run family. A policeman was a good person. He confirmed twice with us not to do police case and told us a great decision taken by you guys. An auto-driver shake his hand and told us, can he leave, his family in tension and waiting for him. We told, yes please go. Policeman sitting with us for few minutes and left.

A man (auto-driver) is poor, not strong family/society background, however, he did not run away from his responsibility. He taught me that honesty and humanity is not demesne of rich people or who has status in the society.

Dynamically add rows and html controls in table using jQuery

How to add rows dynamically in HTML table with textbox and textarea controls. Example: Download

<title>Table Dynamic Row Add Delete Demo</title>
<script src=""
<table id="tbl1">
<input type="text" id="txtFamil_01" name="txtFamily_01" />
<input type="text" id="txtAddress_01" name="txtAddress_01" />
<textarea id="txtFamil_02" name="txtFamily_02"></textarea>
<textarea id="txtAddress_02" name="txtAddress_02"></textarea>
<br />
<button type="button" id="btnAddNewRow">Add New Row</button>
<button type="button" id="btnSave" name="btnSave">Save</button>
<script type="text/javascript">
$(document).ready(function () {
$("#btnAddNewRow").on("click", function () {

var $newRows = $get_lastID();



$get_lastID = function () {
var $id = $(‘#tbl1 tbody tr:last-child td:first-child textarea’).attr(“name”);
$lastChar = parseInt($id.substr($id.length – 2), 10);
$lastChar = $lastChar + 1;
var $newRows=””;
$newRow1 = “<tr> \
<td><input type=’text’ name=’txtFamily_0″+ $lastChar + “‘ /></td> \
<td><input type=’text’ name=’txtAddress_0” + $lastChar + “‘ /></td> \ </tr>”

$newRow2 = “<tr> \
<td><textarea type=’text’ name=’txtFamily_0″+ ($lastChar + 1) + “‘></textarea></td> \
<td><textarea type=’text’ name=’txtAddress_0” + ($lastChar + 1) + “‘></textarea></td> \ </tr>”

$newRows = $newRow1+$newRow2;

return $newRows;

$(“#btnSave”).on(“click”, function () {
$(“#tbl1 tbody tr”).each(function (i, tr) {

var famil1, famil2, address1, address2;

if (i % 2 === 0) { /* textbox find here*/
famil1 = $(this).find(‘td’).eq(0).find(‘input’).val();
famil2 = $(this).find(‘td’).eq(1).find(‘input’).val();
alert(famil1 + ” ” + famil2);
else { /* textarea find here */

address1 = $(this).find(‘td’).eq(0).find(‘textarea’).val();
address2 = $(this).find(‘td’).eq(1).find(‘textarea’).val();
alert(address1 + ” ” + address2);




CSS style problem with MVC rendered checkboxes using MVC helper

I have faced the issue with CSS for checkboxes in mvc. Below is mvc code.

 @Html.CheckBoxFor(model => model.GroupClosed)
  <label for="GroupClosed" class="block">
                            Group Closed

It will render as below:

 <div class="checkbox clip-check check-primary">
                        <span class="control-label" style="color:white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                        <input id="GroupClosed" name="GroupClosed" type="checkbox" value="true"><input name="GroupClosed" type="hidden" value="false">
                        <label for="GroupClosed" class="block">
                            Group Closed

Before modify the css file as below.

.clip-check input[type="checkbox"]:checked + label:before,
  border-width: 10px;

After modify:

.clip-check input[type="checkbox"]:checked + label:before,
.clip-check  input[type="checkbox"]:checked + input[type="hidden"] + label::before {
  border-width: 10px;

Note that the bold line contains the input[type=”hidden”] which identifies the hidden checkbox and solve the issue. I have added this line and make changes according to css has been written in css file. Happy 🙂

7 points will taking care of your life

On 12 Feb 2017, I met Vishwas Jambu and Nikhileswarananda in a conference at Anand the Milk City. I like most Vishwas’ speech. He shared his thoughts which can make everyone’s life better that’s my belief. His thought perfectly match with mine that is the reason I would like to share it to everyone.

  • Focus on major things not minor things in life. For example, you want to go to watch the movie with a friend not girl friend or boy friend, ticket is booked. Your dad is rejected to give a car. You have bike. In that case movie is important thing not a car and reach at time to theater. 🙂
  • Run towards to fear. One of my friend get the job but there is a condition if his performance won’t good company will terminate in probation period. Probation period time limit is three months. He has no other job. However, he feels fear to accept this job. In that case, I think he should accept the challenge by over ruled to fear.
  • Be first, be fast and be fantastic. Today’s day to day life is very fast. In that if you are not think different, not earn well and not develop your personality. The world will reject you from every where. So think different, high and do well so the world gives you respect.
  • Art of distractions: For example, when you do serious task in your office/home or any place and your phone is ringing. It is distracting you from your work. You can keep silent your phone for that much time so it will not distracting you.
  • Intention
  • Give 60 minutes to your life to do exercise, reading and keep silence to better health.
  • Vertical alignment (Decide Priorities) is really needed in everybodies life.
      1. Health
      1. God/Guru (Spiritual Activities)
      1. Job/Business/Profession – income source
      1. Family
      1. Hobby

    Hope you like this blog. Thank you for reading 🙂