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: https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/views/creating-custom-html-helpers-cs

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) []:www.yourcompany.com
Email Address []:your@emailaddress.com

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:

Reference: https://www.youtube.com/watch?v=3EBXAtyB6ys

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);
avHtml.LinkedResources.Add(imageToInline);
mailMessage.AlternateViews.Add(avHtml);

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.


<system.webServer>
		<modules>
			<remove name="WebDAVModule"/>
			<remove name="FormsAuthentication" />
			<remove name="ApplicationInsightsWebTracking" />
			<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
		</modules>
		<handlers>
			<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" />
		</handlers>

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.

રક્ષા બંધન

એક પવિત્ર દિવસ, એક પવિત્ર સબંધ. આ દિવસે બહેન ભાઈની રક્ષા માટે પ્રાથના કરે અને ભાઈ બહેનને ભેટ અને આ જીવન રક્ષા કરવાનું, બહેનની સારી ખરાબ બધી તકલીફમાં સાથ આપવાનું વચન આપે. ભારત દેશ, રઘુ વંશનો દેશ છે એટલે કે “રઘુ કુલ રીત સદા ચલી આવી, પ્રાણ જાય પણ વચન ના જાય”. ભાઈએ બહેન ને આપેલું વચન આખી જિંદગી યાદ રાખી ને નિભાવે.

એકે સુતરના તાંતણે બંધાયેલો આ “પ્રેમ” છે અને આ “પ્રેમ” એવો કે ભાઈ-બહેન નું દિલ ખુશીઓં થી ભરી દે છે.

બાળપણમાં આ દિવસે મિત્રો વચ્ચે સરખામણી થાય, કોના હાથમાં સૌથી વધારે રાખડી છે, કોને સૌથી વધારે બહેન છે. જેના હાથ માં સૌથી વધારે રાખડી હોય, એ બધા મિત્રો વચ્ચે પોતાનો કોલર ઉંચો કરીને ચાલે. આડા દિવસ એ બહેન ને એક રમકડું પણ ના અડવા દેતો હોય એ ભાઈ આ દિવસ એ બહેન મનગમતી વસ્તુ આપવામાં અચકાઈ નહિ. આ નિસ્વાર્થ પ્રેમ છે ભાઈ બહેન વચ્ચેનો.

પણ આ જ બાળક જયારે યવાનીના ઉંબરે પગ મુકે છે, બહેન કરતા અને મિત્રમાં (Girl Friend) વધારે રસ પડે છે ને અને મિત્રો વચ્ચે સરખામણી કોલેજ Canteen માં કરે કોને કેટલા Friendship Belt હાથ પર બાંધ્યા છે. હા, મિત્રો ભૂલી ના જતા ૨૦૧૭માં, “Friendship Day” ના બીજા જ દિવસે રક્ષાબંધન છે.

મારી આ વાત વાંચીને, બધાને પોતાના કોલેજના દિવસો યાદ આવી ગયા હશે અને જે અત્યારે કોલેજ કાળમાં હશે એને ડર લાગવા લાગ્યો હશે કે કોલેજ ની કોઈ છોકરી Friendship Belt ના બદલે રાખડી તો નઈ બાંધી જાય ને.

છોકરો મોટો થઇ એટલે બાપનો મિત્ર બની જાય. બાપએ એની સાથે એક મિત્ર બનીને વાત કરવી. મિત્ર બની ને સલાહ આપવી તો જ દીકરો સાંભળે. બાકી હવાજ નો દીકરો કોઈના બાપનું ના સાંભળે.

એવી જ રીતે મારા મિત્રો છોકરી મોટી થાય એટલે એને નાની બહેન ની જેમ નહિ પણ એક મિત્ર તરીકે સાંભળવી, એક મિત્ર તરીકે અની ઈચ્છા, આકાંશા, મહત્વાકાંક્ષા સાંભળવી અને એને માન આપવું, જ્યાં એ ખોટી હોય ત્યાં એને એક મિત્ર બનીને સમજાવી. ખાસ તો આપડા રુડીચુસ્ત વિચારો માંથી એને મુક્તિ આપવી, દુનિયામાં કશું કરી બતાવવા માટે એને ભણવા,પહેરવા અને ફરવા ની છૂટ આપવી.

કેટલાક યુવાનો આ પોસ્ટ વાંચી ને વિચારમાં પડશે, બહેન ને મિત્ર અને મિત્રને બહેન કેમ કરી ને મનાય. મારા મિત્રો, પત્ની/પ્રેમિકા એક જ હોય બાકી બધી બહેન અને મિત્ર જ હોય એટલે વધારે વિચાર કરશો નહિ. “Happy Rakhi Day and Happy Friendship Day”

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

<html>
<head>
<title>Table Dynamic Row Add Delete Demo</title>
<script src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
</head>
<body>
<div>
<table id="tbl1">
<thead>
<tr>
<th>
Family
</th>
<th>
Address
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" id="txtFamil_01" name="txtFamily_01" />
</td>
<td>
<input type="text" id="txtAddress_01" name="txtAddress_01" />
</td>
</tr>
<tr>
<td>
<textarea id="txtFamil_02" name="txtFamily_02"></textarea>
</td>
<td>
<textarea id="txtAddress_02" name="txtAddress_02"></textarea>
</td>
</tr>
</tbody>
</table>
<br />
<button type="button" id="btnAddNewRow">Add New Row</button>
<button type="button" id="btnSave" name="btnSave">Save</button>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#btnAddNewRow").on("click", function () {

var $newRows = $get_lastID();

$(“#tbl1>tbody”).append($newRows);

});

$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);

}

});

});
});
</script>
</body>
</html>

CSS style problem with MVC rendered checkboxes using MVC helper

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


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

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
                        </label>
                    </div>                     

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 🙂