Friday, July 22, 2011

ValidateRequest 4.0 in visual studio 2010

Hi,
We need to set
ValidateRequest="false"
and modify web config file settings are given below:
<httpRuntime requestValidationMode="2.0"/>
    </system.web>

Thanks
Mahesh K. Sharma

Sunday, July 17, 2011

get difference between two dates

Hi
I need to calculate difference between two days and result required
1) Difference  in year month & day.
2) First day is included as working day. means from 1st Jan to 31 Jan is 1 Month not 30 Days.

So I implemented logic:

A : Get the difference b/w both date.
B: Add difference in base date.
B 1) base date: year 0001, month : as from date's month: day as from date's day
B 2) if from date is leap year than base date: year 0004, month : as from date's month: day as from date's day
C: check if from_date's  month is greater than to date than subtract 1 year from from_date & add 12 months.
D: check if from_date's day  is greater than to date than subtract 1 month  from from_date & add days of current month of to_date.
snips of code is:

DateTime dd = this.fromDate.AddDays(-1);//Becuase we including first day in calculation
            DateTime dd2 = this.toDate;
            TimeSpan ts = dd2.Subtract(dd);
         
            DateTime dd3 = new DateTime();
            int yearsubtrutin = 1;
            if ((this.fromDate.Year % 4) == 0)
            {
                dd3 = new DateTime(0004, this.fromDate.Month, this.fromDate.Day);
                 yearsubtrutin = 4;
            }
            else
            {
                dd3 = new DateTime(0001, this.fromDate.Month, this.fromDate.Day);
                 yearsubtrutin = 1;
            }
            dd = this.fromDate;
            dd3 = dd3.Add(ts);
            this.year = dd3.Year - yearsubtrutin;
            this.month = dd3.Month - this.fromDate.Month;
            if (this.month < 0)
            {
                this.year = this.year - 1;
                this.month = this.month + 12;
            }

            this.day = dd3.Day - this.fromDate.Day;
            if (this.day < 0)
            {
                this.day = this.day + Getdays(this.toDate.Month, yearsubtrutin);
                   
                this.month = this.month - 1;
             
            }
            //

        }

        public int Getdays(int monthNumber, int isleap)
        {
            if (false)
                return 29;
            else
            {
                switch (monthNumber)
                {
                    case 1:
                        return 31;
                        break;
                    case 2:
                        if (isleap == 4)
                            return 29;
                        else
                            return 28;
                        break;
                    case 3:
                        return 31;
                        break;
                    case 4:
                        return 30;
                        break;
                    case 5:
                        return 31;
                        break;
                    case 6:
                        return 30;
                        break;
                    case 7:
                        return 31;
                        break;
                    case 8:
                        return 31;
                        break;
                    case 9:
                        return 30;
                        break;
                    case 10:
                        return 31;
                        break;
                    case 11:
                        return 30;
                        break;
                    case 12:
                        return 31;
                        break;
                    default:
                        break;
                }
            }
            return 0;
        }

Thank
Mahesh



Monday, July 11, 2011

split view state into multiple fields



split view state into multiple fields:

IIS can be set for max hidddn field data view state in case of this when browser submit the page
to iis than it gives error. So we need to split the data in to multiple view state
it can be set in web config file like we set the 100 KB of each view sate if it is bigger than it will split in to new view state



<pages maxPageStateFieldLength="100"></pages>
</system.web>


Thursday, July 7, 2011

How to disable right click on web page with jquery; how to disable right click in javascript; how to disable right click in asp.net

We have to bind contextmenu and return false from this.
This function also handel right click on images of web page.
 <script language="javascript" type="text/javascript">
    $(document).bind("contextmenu",function(e){    
      return false;
     });
    </script>


Thanks
Mahesh