Welcome to my blog.

Post on this blog are my experience which I like to share. This blog is completely about sharing my experience and solving others query. So my humble request would be share you queries to me, who knows... maybe I can come up with a solution...
It is good know :-)

Use my contact details below to get directly in touch with me.
Gmail: nadarmuthukumar1987@gmail.com
Yahoo: nadarmuthukumar@yahoo.co.in

Apart from above people can share their queries on programming related stuff also. As me myself a programmer ;-)

Build Succeeded but Publish Failed

Recently I faced an issue where my website is getting build successfully, means NO error NO warning NO MESSAGE, but if I try to publish it fails.

To find solution for this you need to see your output window.
You can open the output window by pressing Ctl + w, O.

In the output window you can check at which stage does the publish website operation fail.

Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

Pan Card Validation in C#

Add below code to your head section of page under script tag.
function chkPANLen(sender, args)
        {
            var PANno = document.getElementById("").value;
            var pan = /^([A-Z a-z]{5})+([0-9]{4})+([A-Z a-z]{1})$/;
            if (!(PANno.match(pan)))
            {
                args.IsValid = false ;
                return;
            }
            args.IsValid = true ;
        }
Below is the code to validate your control
Pan No. :
                   








Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

serial number column in gridview


   
      
         
            <%# Container.DataItemIndex + 1 %>                                    
         
      
   

Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

Clear all controls in Asp.net

public static void ClearAllControls(Control PageObject)
        {
            foreach (Control ctrControl in PageObject.Controls)
            {
                if (object.ReferenceEquals(ctrControl.GetType(), typeof(TextBox)))
                    ((TextBox)ctrControl).Text = string.Empty;

                if (object.ReferenceEquals(ctrControl.GetType(), typeof(DropDownList)))
                    ((DropDownList)ctrControl).SelectedIndex = -1;

                ClearAllControls(ctrControl);
            }
        }
Call Controlprocedure using below code
ClearAllControls(this);
Note in the above code I have only involved TextBox and DropDownList Controls, likewise you can use your own.
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

no implicit conversion between null to int

I faced this issue twice now.

When I tried to use below code
DateTime? foo;
foo = string.IsNullOrEmpty(txtDate.Text) ? null : Convert.ToDateTime(txtDate.Text);
I get error as,
Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'System.DateTime'

Solution for the problem is below
DateTime? foo;
foo = string.IsNullOrEmpty(txtDate.Text) ? (DateTime?)null : Convert.ToDateTime(txtDate.Text);



Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

MonthPicker

At the end of this article you will be capable of creating your own month year picker.

While creating reports we normally give from and to date filter, for which we use our normal DateTimePicker. But recently I got a requirement where I want to give "From Month Year" to "To Month Year" filter for a report. This can be achieved using DateTimePicker with some modification on its Javascript. But on some case I failed and decided to create my own usercontrol.

Technology used
Dot Net 3.5 Framework, Ajax.

Month Picker
 Follow below steps to create your Month Year Picker.
Step 1. Create a User Control
  1. Right Click on the project and click on "Add New Item"
  2. Select Web User Control and name it as "MonthYearPicker.ascx" and click Add.
  3. Now place below code into designer part of your user control.

    
        
        
        
        
            
                loading...
            
        
        
            
            
            
            
            
        
    
 

4.    And Place the below code to Code Behind of User Control 
private string _TextBoxCss;
    public string TextBoxCss
    {
        get { return _TextBoxCss; }
        set { _TextBoxCss = value; }
    }

    private string _SelectButtonCss;
    public string SelectButtonCss
    {
        get { return _SelectButtonCss; }
        set { _SelectButtonCss = value; }
    }

    private string _SetButtonCss;
    public string SetButtonCss
    {
        get { return _SetButtonCss; }
        set { _SetButtonCss = value; }
    }

    private string _PanelCss;
    public string PanelCss
    {
        get { return _PanelCss; }
        set { _PanelCss = value; }
    }

    private int _MinYear;
    public int MinYear
    {
        get { return _MinYear; }
        set { _MinYear = value; }
    }

    private int _MaxYear;
    public int MaxYear
    {
        get { return _MaxYear; }
        set { _MaxYear = value; }
    }

    private int _MinMonth;
    public int MinMonth
    {
        get { return _MinMonth; }
        set { _MinMonth = value; }
    }

    private int _MaxMonth;
    public int MaxMonth
    {
        get { return _MaxMonth; }
        set { _MaxMonth = value; }
    }

    private string _Value;
    public string Value
    {
        get
        {
            _Value = GetSelectMonthYear();
            return _Value;
        }
        set { _Value = value; }
    }

    protected void Page_Init(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtValue.CssClass = _TextBoxCss;
            btnSelect.CssClass = _SelectButtonCss;
            btnSet.CssClass = _SetButtonCss;
            pnlDate.CssClass = _PanelCss;

            ddlYear.Items.Clear();
            _MinYear = _MinYear == 0 ? DateTime.MinValue.Year : _MinYear;
            _MaxYear = _MaxYear == 0 ? DateTime.MaxValue.Year : _MaxYear;
            for (int i = _MinYear; i <= _MaxYear; i++)
                ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));

            ddlMonth.Items.Clear();
            _MinMonth = _MinMonth == 0 ? DateTime.MinValue.Month : _MinMonth;
            _MaxMonth = _MaxMonth == 0 ? DateTime.MaxValue.Month : _MaxMonth;
            for (int i = _MinMonth; i <= _MaxMonth; i++)
                ddlMonth.Items.Add(new ListItem(GetMonth(i), i.ToString()));


        }
    }

    private string GetSelectMonthYear()
    {
        string _ReturnValue = string.Empty;
        string _Month = string.Empty;

        if (!string.IsNullOrEmpty(txtValue.Text))
        {
            string[] _strValue = txtValue.Text.Split(' ');

            switch (Convert.ToString(_strValue[0]).ToLower())
            {
                case "jan":
                    _Month = "01";
                    break;
                case "feb":
                    _Month = "02";
                    break;
                case "mar":
                    _Month = "03";
                    break;
                case "apr":
                    _Month = "04";
                    break;
                case "may":
                    _Month = "05";
                    break;
                case "jun":
                    _Month = "06";
                    break;
                case "jul":
                    _Month = "07";
                    break;
                case "aug":
                    _Month = "08";
                    break;
                case "sep":
                    _Month = "09";
                    break;
                case "oct":
                    _Month = "10";
                    break;
                case "nov":
                    _Month = "11";
                    break;
                case "dec":
                    _Month = "12";
                    break;
                default:
                    break;
            }
            if (!(string.IsNullOrEmpty(_Month) & string.IsNullOrEmpty(Convert.ToString(_strValue[1]))))
            {
                _ReturnValue = _Month + "," + Convert.ToString(_strValue[1]);
            }

        }
        return _ReturnValue;
    }

    private string GetMonth(int Month)
    {
        string _ReturnValue = string.Empty;
        switch (Month)
        {
            case 1:
                _ReturnValue = "Jan";
                break;
            case 2:
                _ReturnValue = "Feb";
                break;
            case 3:
                _ReturnValue = "Mar";
                break;
            case 4:
                _ReturnValue = "Apr";
                break;
            case 5:
                _ReturnValue = "May";
                break;
            case 6:
                _ReturnValue = "Jun";
                break;
            case 7:
                _ReturnValue = "Jul";
                break;
            case 8:
                _ReturnValue = "Aug";
                break;
            case 9:
                _ReturnValue = "Sep";
                break;
            case 10:
                _ReturnValue = "Oct";
                break;
            case 11:
                _ReturnValue = "Nov";
                break;
            case 12:
                _ReturnValue = "Dec";
                break;
            default:
                break;
        }
        return _ReturnValue;
    }

    protected void btnSelect_Click(object sender, EventArgs e)
    {
        pnlDate.Visible = !pnlDate.Visible;
        if (pnlDate.Visible)
        {
            ddlMonth.SelectedValue = DateTime.Now.Month.ToString();
            ddlYear.SelectedValue = DateTime.Now.Year.ToString();
        }
    }

    protected void btnSet_Click(object sender, EventArgs e)
    {
        txtValue.Text = ddlMonth.SelectedItem.Text + " " + ddlYear.SelectedValue;
        pnlDate.Visible = false;
    } 
Step 2. Create a Page where you want to place this control
  1. Right Click on the project and click on "Add New Item"
  2. Select Web Form and name it as "Default1.aspx" and click Add.
  3. Register you created User Control using below code above.
<%@ Register Src="~/UserControl/MonthYearPicker.ascx" TagName="MonthYearPicker" TagPrefix="myp" %>
4.    Now place below code into designer part of your Page.


    
    


    

Month Year


Show Value
5.    And Place the below code to Code Behind of Page.
protected void btnShow_Click(object sender, EventArgs e) 
    {
        Response.Write(mypMonthYear.Value);
    } 
That's it you are don't with your own Month Year Picker.

Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

Double clicking the aspx file In visual studio 2010 open internet explorer / mozilla

Double clicking the aspx file In visual studio 2010 open internet explorer / mozilla
A co-worker of mine  is experiencing an issue in Visual Studio 2010 where if he double clicks a page in the project explorer, it opens the page in internet explorer rather than open the file in visual studio.

Now to open the file in Visual Studio, he has to "right click" the aspx file and then select "View Designer".
The same thing happens if he right click and select "open".
so, I tried myself around with VS2010, and  I figured it out.
here is what u can do to over come this problem
1. In the solution explorer right click on .aspx file and click on "open with" option.
2. A dialogue box with open with title would come up, select "web form editor" in this box.
3. In the right hand side click button "Set as default"
4. click "Ok" and try again double clicking the .aspx file and now it should open in visual studio source view

Actually, you can define default editor for your files in that way (visual studio, dreamviewer or any third party tool)
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

Remove special characters from String

public static string RemoveSpecialCharacters(string str)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        for (int i = 0; i < str.Length; i++)
            if ((str[i] >= '0' && str[i] <= '9') || (str[i] >= 'A' && str[i] <= 'z' || (str[i] == '.' || str[i] == '_')))
                sb.Append(str[i]);
        return sb.ToString();
    }
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

Twitter Delicious Facebook Digg Stumbleupon Favorites More