Sunday, September 29, 2013

7 great free office suites for PCs, Macs, iOS and Android


Check out these free office software packages

http://www.itworld.com/data-center/374420/who-needs-microsoft-office-7-great-free-office-suites-pcs-macs-ios-and-android?source=ITWNLE_nlt_enterprise_apps_2013-09-25

cheers

samitha




Friday, August 23, 2013

Web essentials 2012

Web essentials provides efficient way of performing common development tasks. This includes

Support for TypeScript
JavaScript/Css minification
Vendor dpecific property generation
Zen coding

and many more

Download from
http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6

Cheers
Samitha
 

Wednesday, August 21, 2013

The required anti-forgery cookie "__RequestVerificationToken" is not present

When developing Asp.Net MVC applications you might end up getting the error "The required anti-forgery cookie "__RequestVerificationToken" is not present"

This errors occurs if you have used the ValidateAntiForgeryToken for a controller or an action, and you have not  specified @Html.AntiForgeryToken() inside the form in your view.

cheers
Samitha

Monday, August 5, 2013

Asp.Net Customized Javascript Messages

There are basically three types of messages supported in JavaScript
  • Alert
           e.g  alert(‘Hello’);
  • Confirm
           e,g.  Confirm(‘Are You sure?’);
  •  Promt
          e.g. prompt("Please enter name:","Your name") ;

If you want to get the result of the dialogs (i.e. whether user clicked yes on Confirmation) you can use a variable to hold the user input as displayed below.
var result =Confirm(‘Are You sure?’);
if(result==’true’)
{
 //logic for Yes
}
else
{
 //logic for No
}

If you want additional styling features to be provided, javascript alone will not provide you the exact solution. Here come jQuery messages for your rescue.
There are plenty of jqueryUI messages available. I will list down few here for your references.


In addition to the above you can use javascript’s showModalDialog to open your customized alert, conformation etc.  I’ll explain the steps to create a customized Confirmation dialog and implement it.

1). Create ConfirmDialog.aspx. Customize the design as per your requirement
ConfirmDialog.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConfirmDialog.aspx.cs" Inherits="ConfirmDialog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Warning</title>
      
     <script language="javascript" type="text/javascript">
        window.returnValue = '';
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>
                <td class="popupbg">
                    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
                        <tr>
                            <td class="PopUpcontentbg">
                    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
                    <tr >
                    <td align="center" colspan="2" class="fieldTextBold" >
                   <h1> Warning </h1>
                    </td>
                    </tr>
                        <tr>
                            <td colspan="2"  valign="top">
                              <%=message%> </td>
                           
                        </tr>
                        
                        <tr>
                            <td>
                            </td>
                            <td  align="center">
        <asp:Button ID="btnOk" runat="server" OnClick="btnOk_Click" Text="Ok" />
        &nbsp;<asp:Button ID="btnCancle" runat="server" OnClick="btnCancle_Click" Text="Cancel" /></td>
                        </tr>
                    </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

The window.returnValue is used to store the button clicked by the user.  When calling the confirmation  dialog, you can pass a customized text to be displayed in the <%=message%> field.

ConfirmDialog.aspx.cs
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ConfirmDialog : System.Web.UI.Page
{
    protected string message = String.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        message = String.Format("{0}", Request.QueryString["message"]);
    }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        StringBuilder postBackScript = new StringBuilder();
        postBackScript.Append(" <script language=JavaScript> ");
        postBackScript.Append(String.Format(" window.returnValue = '{0}';", "Yes"));
        postBackScript.Append(" self.close(); ");
        postBackScript.Append(" </script>");
        Page.RegisterStartupScript("OkDialog", postBackScript.ToString());
    }
    protected void btnCancle_Click(object sender, EventArgs e)
    {
        StringBuilder postBackScript = new StringBuilder();
        postBackScript.Append(" <script language=JavaScript> ");
        postBackScript.Append(String.Format(" window.returnValue = '{0}';", "No"));
        postBackScript.Append(" self.close(); ");
        postBackScript.Append(" </script>");
        postBackScript.Append(" </script>");
        Page.RegisterStartupScript("OkDialog ", postBackScript.ToString());
    }
}
Here I have appended “Yes” as the return value for OK click and “No” for Cancel click.
2). Create Dialogboxhostframe.. This can be used to host different messages according to the requirement.
Dialogboxhostframe.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dialogboxhostframe.aspx.cs" Inherits=" dialogboxhostframe" Title="Assess" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
                <HEAD>
                                <TITLE>Scheduling</TITLE>
                                <META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
                </HEAD>
                <frameset rows="0,*">
                                <frame name="header" src="" scrolling="no" noresize>
                                <frame name="main" src='<%=src%>'>
                </frameset>
</HTML>

dialogboxhostframe.aspx.cs

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
    public partial class dialogboxhostframe : System.Web.UI.Page
    {
        protected string src = String.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {

                src = String.Format("{0}", Request.QueryString["src”]);
        }
    }
3). Call the window inside your script
var response =window.showModalDialog('dialogboxhostframe.aspx?src=ConfirmDialog.aspx?message=Are you sure to continue saving the record.'  , window, 'dialogWidth: 480px; dialogHeight: 158px; resizable: No; status: No; help: No; unadorned: Yes;');

//check the user response

if (response == 'Yes')
{
//logic for Yes
}
else
{
   //logic for No

}

Cheers
Samitha

Tuesday, July 9, 2013

SQL Server getdate in YYYY-MM-DD without time

If you ever wanted to get a date field without time? This is a common question that have been asked and there are several ways to get the desired result.

There are two options but you should select the best one to match your requirement

1) Get date without time part

 SELECT CONVERT(VARCHAR(12), GETDATE(), 23)

This will give the following output

2013-07-10

2) Get date with time part represented as zeros

SELECT CONVERT(datetime,CONVERT(char(10), GetDate(),126))
 
This one converts the result back to date time with the following output 
 
2013-07-10 00:00:00.000
 
Cheers
Samitha 
 

Thursday, June 27, 2013

Asp.net Gridview Adjust Row Height

When working with the Asp.net Gridview it is a common that we set a fixed height to the rows of the grid. But I came across a situation where height of the Gridview changes even if RowStyle and
AlternatingRowStyle is specified.

The solution seems to be bit tricky but it worked for me. As Boriss Pavlovs have suggested in the following post you will need to set the row height on page prerender event

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (dgEvent.Rows.Count > 0)
                dgEvent.Height = new Unit(dgEvent.RowStyle.Height.Value * dgEvent.Rows.Count);
        }

http://stackoverflow.com/questions/13762220/how-to-set-fixed-width-and-height-for-grid-row-which-is-dynamically-generating-i

Cheers
Samitha

ASP.Net Clendar Hide WeekEnd

Asp.Net Calender control gives facility to hide the day cells by using the following code.

 e.Cell.Visible = !e.Day.IsWeekend;

Even though you can hide the day cell, Calender header will be still visible and it will show the Saturday and Sunday headings.

I have come across one post that would give some starting point to resolve this issues.

http://stackoverflow.com/questions/554111/how-can-i-hide-weekends-when-using-the-asp-net-calendar-control

As described in this post you will have to override the Calender control's render method to achieve the desired behavior. But this method did not work for me as it expects a XML compatible string.

In the same post as zacharydl have suggested I was able to achive the result using jQuery with a slight modification to the code. You will have to call the javascript function during the post back event to avoid showing the weekends when we change the selected month.

<script language="javascript">

 HideWeekEnd();
 
   
    function HideWeekEnd ()
    {
        $('._title').parent().attr('colspan', '7'); 
        $('.evenCal:nth-last-child(1) , .evenCal:nth-last-child(2) ', $('#ScheduleParentWeb_cpHolder_calSchedule')).hide(); // remove last two headings
        $('._weekendday').hide(); // remove all the cells marked weekends
    }

 Sys.Application.add_init(appl_init);

        function appl_init() {
            var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
            pgRegMgr.add_endRequest(HideWeekEnd);// calls the  HideWeekEnd funtion on postback
        }

    </script>

<asp:Calendar runat="server" ID="Calendar1">
    <TitleStyle CssClass="_title" />
    <DayHeaderStyle CssClass="evenCal" />
    <WeekendDayStyle CssClass="_weekendday" />
</asp:Calendar>

Finally add the css classes to a stylesheet.

Cheers
Samitha