adsense

Thursday, December 19, 2013

Change Asp.net Ajax tab page header from javascipt

This is not as straightforward as you might have thought. To access the tab pages use get_tabs()[indexOfTab] as shown below.

$find('ctl00_cphMainContent_tc1').get_tabs()[0]) ; // tab 0
$find('ctl00_cphMainContent_tc1').get_tabs()[1]) ; // tab 1

To set the tab header use the _header of the tab
 $find('ctl00_cphMainContent_tc1').get_tabs()[0]._header.innerHTML='Tab 0';
 $find('ctl00_cphMainContent_tc1').get_tabs()[1]._header.innerHTML='Tab 1';

Cheers
Samitha

Saturday, December 7, 2013

asp.net 4.0 mobile development

With the release of asp.net 4.0 and MVC 3.0 there has been a major changes in the mobile development. Following whitepaper discusses in detail how you would develop mobile web pages with asp.net 4.0 and MVC 3.0 .

http://www.asp.net/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application

cheers
Samitha

Saturday, November 16, 2013

Checkboxlist checkbox items acess from javascript

If you want to iterate through Checkboxlist  check box items it not as straightforward as you might have thought.

The trick is to access the check box items rendered as labels as shown below

 var chkBoxList = document.getElementById('<%=chkList.ClientID%>');

                var checkboxes = chkBoxList .getElementsByTagName('input');

                for (var i = 0; i < checkboxes .length; i++) {
                    var checkItem = checkboxes [i];

                    var label = checkItem .parentNode.getElementsByTagName('label');
                     //checked item
                      if (checkItem .checked) {
                           ...
                        }
                       //access checkItem text
                        label[0].innerHTML='';
                    }

                }

cheers
Samitha

Saturday, October 19, 2013

Visual Studio 2013 Reased


Microsoft Announces offical release of  Visual Studio 2013 and offerd key features including

  • Better Productivity 
  • Windows 8.1 App Development
  • Debugging improvements and more...
 
More Info and downoload
http://www.microsoft.com/visualstudio/eng/visual-studio-2013#story-2013

cheers
Samitha

Friday, October 18, 2013

Normalize.css

This makes browsers render all elements more consistently and in line with modern standards.

Check out following link for more information

https://github.com/necolas/normalize.css/

cheers
Samitha

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

Sunday, June 23, 2013

javascript date comparison

A simple way to compara two date objects is to use the getTime() as shown below.

var d1 = new Date(2013, 6, 1);
var d2 = new Date(2013, 10, 1);
 
if (d1.getTime() > d2.getTime())
true;
else
false ;

cheers
Samitha

Tuesday, May 28, 2013

jQuery Easy UI

If you have ever dream of using a jquery grid and other tools , have a look at following url which provides bunch of jQuery supported controls. Worth a try..


http://www.jeasyui.com/demo/main/index.php

Cheers
Samitha

Thursday, May 9, 2013

Pass two arguments to DataNavigateUrlFormatString

Hyperlink Column in a Gridview can be easily accomadated to accept two or more arguments as displayed below.

 <asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” >
<Columns>

<asp:HyperLinkField DataNavigateUrlFields=”ProducrID,Company” DataNavigateUrlFormatString=”ProductDetails.aspx?ProducrID={0}&Company={1}” Text=”View Student” />
<asp:BoundField DataField=”Description” HeaderText=”Description"  />
</Columns>
</asp:GridView>   

Cheers
Samitha

Tuesday, April 23, 2013

use Session variable in an HttpHandler

In order to use session variables inside an  HttpHandler implement the IRequiresSessionState(System.Web.SessionState namespace) interface

E.g.
 public class AutoSuggest : IHttpHandler, IRequiresSessionState
{
   public void ProcessRequest(HttpContext context)
  {
      context.Session["session_name"] ="xyz";
   }
}

Cheers
Samitha.

Sunday, March 31, 2013

Spring.NET

Take a look at Javas's spring version for .net. This is an open source framework that that assists building enterprise applicaitons.

http://www.springframework.net/

Cheers
Samitha

Thursday, March 28, 2013

Ajax.NET Professional (AjaxPro) Starter Kit

Ajax.NET Professional  is a Ajax Framework for the Microsoft .NET Framework which you can use with any .NET languages to invoke any .NET method from the client-side.
 Download the AjaxPro from http://www.ajaxpro.info/

Cheers
Samitha 

Saturday, March 9, 2013

An Ajax toolbar for crystal reports

As I have blogged in one of my previous post, crystal reports tool bars have a strange behavior  when used inside an update panel. The solution for this can be achieved by using a customized toolbar for CrystalReportViewer. Following blog provides such implementation using an example and it worked for me

http://www.rahulsingla.com/blog/2010/03/an-ajax-toolbar-for-asp-net-crystal-reports

Friday, February 15, 2013

Asp.net DropDownList with Custom Paging

When we developing with Asp.net DropDownList, one of the most common issue faced is when there are too many records filled in the control, the control goes up as you select the DropDownList. This is the default behavior of the DropDownList and one of the solution for this is to have DropDownList with Custom Paging. I found this article explaining how to implement a Asp.net DropDownList with Custom Paging.

Cheers

Samitha

Monday, January 14, 2013

Developing a SQL Server Backup Strategy

As a DBA it is important that you have developed a proper backup strategy. Following article describes concepts to consider when developing a backup strategy.

http://www.databasejournal.com/features/mssql/developing-a-sql-server-backup-strategy.html

Cheers
samitha

Monday, January 7, 2013

Unable to read the project file 'project.' The Web Application Project proj1 is configured to use IIS

If you ever com up with the error "Unable to read the project file 'project.' The Web Application Project proj1 is configured to use IIS"  edit the .csproj with notepad and change this line :

<WebProjectProperties>
          <UseIIS>True</UseIIS>

To :
<WebProjectProperties>
          <UseIIS>False</UseIIS>

Cheers
Samitha

Thursday, January 3, 2013

SQL Server convert string to datetime

If you have used any of the fields in a table as a varchar to store date when querying the table will not return the expected result.
E.g
SELECT * from ISSUES where CREATED_DATE
  between '08/16/2012' AND '01/27/2013
Here CREATED_DATE field has been defined as string. To resolve this you;ll have to use SQL's convert funciton as follows
SELECT * from ISSUES where CONVERT(datetime,CREATED_DATE,120)
  between '08/16/2012' AND '01/27/2013'

For more date time formatting options check link below
http://msdn.microsoft.com/en-us/library/ms187928.aspx

Cheers
Samitha