Tuesday 5 March 2019

How to hide a div or inputs element depending on Model value in mvc

///////////////// html page


            </tr><td>

                @if (@item.UserStatus == 1)
                {
                    <a href="#"><i class="glyphicon glyphicon-edit"></i></a>
                }
            </td></tr>




Monday 4 March 2019

Invalid postback or callback argument. Event validation is enabled using



Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation



//////////////Solution >>

ScriptManager may not find the control when binding is done in Page_Load instead bining the data to control (like dataset) in Page_PreRender will solve the issue.


An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

/////////////// Solution

It's due to the application render under the "Integrated Mode" witch is directly related to the IIS service.




Solution-
Step 1. Right Click on the Solution Explorer of the application
Step 2. Go to Properties of F4
Step 3. Change the PIPELINE setting "Integrated to Classic Mode"

Solution>> Right Click>> Property (F4) >> Managed Pipeline Mode >> Classic



Sunday 3 March 2019

Convert DataTable into Generic List Collection



//////////// Using NameSpace

using System.Reflection;

//////////////////// Class

public class Employee 
   public int EmpId{ getset; } 
   public string EmpName { getset;} 

}

public  void fill_data()
        DataTable dt = new DataTable();
        List<Employee> lstMembership = Convert_ToList<Employee>(dt);

}



/////////////          DBHelper

 public static List<T> Convert_ToList<T>(DataTable dt)
        {
            List<T> data = new List<T>();
            foreach (DataRow row in dt.Rows)
            {
                T item = Get_Items<T>(row);
                data.Add(item);
            }
            return data;
        }

        private static T Get_Items<T>(DataRow dr)
        {
            Type temp = typeof(T);
            T obj = Activator.CreateInstance<T>();

            foreach (DataColumn column in dr.Table.Columns)
            {
                foreach (PropertyInfo pInfo in temp.GetProperties())
                {
                    if (pInfo.Name == column.ColumnName)
                        pInfo.SetValue(obj, dr[column.ColumnName], null);
                    else
                        continue;
                }
            }
            return obj;
        }


/////////////////////// Using Linq


public static List<T> ConvertToList<T>(DataTable dt)
    {
        var columnNames = dt.Columns.Cast<DataColumn>()
                          .Select(c => c.ColumnName.ToLower()).ToList();
        var properties = typeof(T).GetProperties();
        return dt.AsEnumerable().Select(row =>
        {
            var objT = Activator.CreateInstance<T>();
            foreach (var pro in properties)
            {
                if (columnNames.Contains(pro.Name.ToLower()))
                {
                    try
                    {
                        pro.SetValue(objT, row[pro.Name]);
                    }
                    catch (Exception ex) { }
                }
            }
            return objT;
        }).ToList();
    }  

Switch button using pure css with custom text

////////////////////// css



.switch-btn {
  positionrelative;
  displayinline-block;
  width90px;
  height34px;
}

.switch-btn .switch input {display:none;}

.switch-btn .slider {
  positionabsolute;
  cursorpointer;
  top0;
  left0;
  right0;
  bottom0;
  background-color#ca2222;
  -webkit-transition.4s;
  transition.4s;
}

.switch-btn .slider:before {
  positionabsolute;
  content"";
  height26px;
  width26px;
  left4px;
  bottom4px;
  background-colorwhite;
  -webkit-transition.4s;
  transition.4s;
}

.switch-btn input:checked + .slider {
  background-color#2ab934;
}

.switch-btn input:focus + .slider {
  box-shadow0 0 1px #2196F3;
}

.switch-btn input:checked + .slider:before {
  -webkit-transformtranslateX(55px);
  -ms-transformtranslateX(55px);
  transformtranslateX(55px);
}

/*------ ADDED CSS ---------*/
.switch-btn .on
{
  displaynone;
}

.switch-btn .on.off
{
  colorwhite;
  positionabsolute;
  transformtranslate(-50%,-50%);
  top50%;
  left50%;
  font-size10px;
  font-familyVerdana, sans-serif;
}

.switch-btn input:checked+ .slider .on
{displayblock;}

.switch-btn input:checked + .slider .off
{displaynone;}

.switch-btn .slider.round {
  border-radius34px;
}

..switch-btn slider.round:before {
  border-radius50%;}

///////////////////////// html


<label class="switch-btn">
    <!--HTML -->
  <input type="checkbox" id="Chk_toggle">
   <div class="slider round">
      <!--Custom text -->
        <span class="on">ON</span>
        <span class="off">OFF</span>
    </div>
</label>



/////////////////   Result




Switch button using pure css

//////////////////////// css



.switch-btn {
  positionrelative;
  displayinline-block;
  width90px;
  height34px;
}

.switch-btn .switch input {display:none;}

.switch-btn .slider {
  positionabsolute;
  cursorpointer;
  top0;
  left0;
  right0;
  bottom0;
  background-color#ca2222;
  -webkit-transition.4s;
  transition.4s;
   border-radius34px;
}

.switch-btn .slider:before {
  positionabsolute;
  content"";
  height26px;
  width26px;
  left4px;
  bottom4px;
  background-colorwhite;
  -webkit-transition.4s;
  transition.4s;
  border-radius50%;
}

.switch-btn input:checked + .slider {
  background-color#2ab934;
}

.switch-btn input:focus + .slider {
  box-shadow0 0 1px #2196F3;
}

.switch-btn input:checked + .slider:before {
  -webkit-transformtranslateX(26px);
  -ms-transformtranslateX(26px);
  transformtranslateX(55px);
}

.switch-btn .slider:after
{
 content:'OFF';
 colorwhite;
 displayblock;
 positionabsolute;
 transformtranslate(-50%,-50%);
 top50%;
 left50%;
 font-size10px;
 font-familyVerdana, sans-serif;
}

.switch-btn input:checked + .slider:after
{ 
  content:'ON';
}

////////////////////////html


<label class="switch-btn">
                <input type="checkbox" id="Chk_toggle">
                <div class="slider round">
                </div>
            </label>





//////////// Result









Switch button using pure css outer custom text

/////////////////////////css

  .switch-btn
        {
            positionrelative;
            displayinline-block;
                margin-left50px;
                width88px;
            height20px;
        }
       
        .switch-btn .switch input
        {
            displaynone;
        }
       
        .switch-btn .slider
        {
            positionabsolute;
            cursorpointer;
            top0;
            left0;
            right0;
            bottom0;
            background-color#ca2222;
            -webkit-transition.4s;
            transition.4s;
        }
       
        .switch-btn .slider:before
        {
            positionabsolute;
            content"";
            height28px;
            width28px;
            left1px;
            bottom-4px;
            background-colorwhite;
            -webkit-transition.4s;
            transition.4s;
            bordersolid 0.5px #ddd;
        }
       
        .switch-btn input:checked + .slider
        {
            background-color#2ab934;
        }
       
        .switch-btn input:focus + .slider
        {
            box-shadow0 0 1px #2196F3;
        }
       
        .switch-btn input:checked + .slider:before
        {
            -webkit-transformtranslateX(55px);
            -ms-transformtranslateX(55px);
            transformtranslateX(55px);
        }
       
        /*------ ADDED CSS ---------*/
       
       
        .switch-btn .on.off
        {
            color#000;
            positionabsolute;
            transformtranslate(-50%,-50%);
            top50%;
            left50%;
                font-size0.9rem;
            font-familyVerdana, sans-serif;
        }
        .switch-btn .on
        {
            /*display: none;*/
            color:#ddd;
            left-1.2rem;
        }
         .switch-btn .off
        {
            left6rem;
            width1px;
            color:#000;
        }
        .switch-btn input:checked + .slider .on
        {
          /*  display: block;*/
          color:#000;
        }
       
        .switch-btn input:checked + .slider .off
        {
            color:#ddd;
          /*  display: none;*/
        }
       
        /*--------- END --------*/
       
        /* Rounded sliders */
        .switch-btn .slider.round
        {
            border-radius34px;
        }
       
        .switch-btn .slider.round:before
        {
            border-radius50%;
        }



/////////////////////////html


<label class="switch-btn ">
        <input type="checkbox" id="togBtn">
        <div class="slider round">
            <span class="on">On</span> <span class="off">Off</span>
        </div>

    </label>



/////////////////Result


       


Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...