adsense

Friday, July 30, 2021

asp.net linkbutton open in a new window

 Asp.Net linkbutton can be made to work the same way as a normal hyperlink does. All we have to do is to attach a onClick attribute as displayed below.

 

 string strURL = "";
string strWinTitle = "";
string strWinProperty = "";


strURL =  "https://www.google.com/";
stTitle = "New Window";
strProperty = "toolbar=no,menubar=no,location=no";


linkBtn.Attributes.Add("onClick", "javascript:window.open('" + strURL + "','" + stTitle + "','" + strProperty + "');return false;")


Cheers,

Samitha

Saturday, June 26, 2021

SQL Server read XML attribute

Suppose you have a XML value stored in a table


<?xml version="1.0" encoding="utf-8"?>
<rootElement>
  <param name="p1" value="v1" />
  <param name="p2" value="v2" />
  ...
</rootElement>

 

We can get the value of the p1 parameter as follows


SELECT
  columnNAame.value('(/rootElement/param[@name="p1"]/@value)[1]', 'varchar(50)')
FROM  
  tableName

Notice that the correct datatype should be chosen within the query. If we have a integer value we have to use int as the datatype. In addition if long text is stored for the value proper data length needs to be given.

Cheers

Samitha

Sunday, June 13, 2021

Chrome complains about a missing source map

Recently I have added a Javascript library and found that  Chrome devtools keeps complaining about a missing source map

Initially I have referenced the .js fil as follows

<script src="https://cdn.jsdelivr.net/npm/@linways/table-to-excel@1.0.4/dist/tableToExcel.js"></script>

 The resolution was to replace the .js file with .min.js as follows

 <script src="https://cdn.jsdelivr.net/npm/@linways/table-to-excel@1.0.4/dist/tableToExcel.min.js"></script>

 

Cheers

Samitha

 


Sunday, May 30, 2021

ASP.NET MVC delete multiple records

 When it comes to deleting multiple records in ASP.NET MVC, you have two options,

 1. Connected mode

using (CourseContext db = new CourseContext())
    {
 
        List<Course> courses = db.Courses.Take(5).ToList();

        try
        { 

           db.Courses.RemoveRange(courses);
            db.SaveChanges();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
  

2. Disconnected mode

ListCourse> courses = new List<Course>();
courses.Add(new Course { CourseID = 1 });
courses.Add(new Course{ CourseID = 2 });
 
using (CourseContext db = new CourseContext())
    {
  
        try
        {

            db.Entry(Course).State= System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
 
    }


Cheers,

Samitha

Saturday, May 15, 2021

readonly checkbox

 We can use javascript to make a checkbox read only(not disabled) as shown below


<input type="checkbox" checked onkeydown="return false;" onclick="return false;" />

if you want to disable check using keyboard modify above as follows.


<input type="checkbox" checked onclick="return false;" onkeydown="e = e || window.event; if(e.keyCode !== 9) return false;"/>


Cheer

Samitha

Sunday, May 2, 2021

Add icons to links using jquery

If you want to add icons besides your hyperlinks, jQuery can be used to do it as shown below

1. Define Syles

a.pdf { 
    background: url(images/pdf.png) no-repeat left center;
    padding-left: 20px;
    line-height: 16px; /* used to center the image with text */
}
 
a.txt { 
    background: url(images/txt.png) no-repeat left center;
    padding-left: 20px;
    line-height: 16px;
}

a.email {
    background: url(images/email.png) no-repeat left center;
    padding-left: 20px;
    line-height: 16px;
}

2. Add the style using jQuery DOM ready or pageLoad

$(function() {
 
    $("a[href$='.pdf']").addClass("pdf");
 
    $("a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").addClass("txt");
 
    $("a[href^='mailto:']").addClass("email");
 

});

Cheers,

Samitha

Saturday, April 17, 2021

select all elements of a class, except one element

If we want to do some action on selected list of elements except one element in the list we can use jQuery as shown below.

 $(".parentElement:not(#childId)").actionName();

If you want to skip multiple elements

 $(".parentElement:not(#childId1,#childId2)").actionName();

Or you can use not()

$(".parentElement").not("#childId1").actionName();


Cheers,

Samitha