Wednesday, May 30, 2012

IE7 Hack For Jquery .attr

I have been working with this issue for two days, and i googled so much and i cant resolve this. but finally i got one thread that the IE rendering it as simply object

$("input").each(function() { $(this).addClass($(this).attr("type")) });  

This was the actual code, but when the page is loaded in ie7 the browser suddenly got stuck and went to not responding, finally i found the error code in my javascript file and i replaced it with

    $("input").each(function() { $(this).addClass($(this).attr("type") || $(Object).attr("type")) });

i ve found that the similar issue was reported earlier in jquery bugtracker

Bug 1 
Bug 2 
bug 3 


Typing and Editing Responsiveness in Visual Studio 2011

Since responsiveness is all about whether or not VS is keeping up with the incoming message stream, it is fairly straightforward engineering work to figure out how long any given message takes to process. During Visual Studio 2010 SP1, we added some hooks into the product so we could tell when processing a single message took too long. We released an extension called PerfWatson that recognized unresponsiveness and generated anonymous reports that we collected and aggregated. You can read this earlier blog post about how we used PerfWatson data during Visual Studio 11. One of the most interesting things to know about PerfWatson for today’s post is that it collects a mini heap dump which allows us to figure out what Visual Studio code is running at a particular point during the delay.
PerfWatson has been an extremely valuable tool for understanding VS hangs, but the threshold we set for it and the dump files it collects are designed for general application responsiveness, not for interactions that must be immediate such as typing a character and seeing it appear on the screen. Collecting a dump is fast, but it’s not fast enough to repeat on a per-keystroke basis. We therefore built a more fine-grained measurement system we call Immediate Delay Tracker (IDT).
Read More 

Limiting keystroke in web application

if (e.keyCode != 8 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40 && e.which != 8 && e.which != 37 && e.which != 38 && e.which != 39 && e.which != 40) {
      return true;
}
else {
      return false;
}

Javascript for a timer textbox

This is a timer text box, which we can enter only time and we have a drop down list which we can select am pm option.

 java script code is below


<script type="text/javascript">
    //<!--
    Sys.Application.add_load(BindEvents);

    function BindEvents() {
        $(document).ready(function() {
            var controlDisable = '<%=Disable %>';
            var txtTime = $('#<%=txtTime.ClientID %>');
            var ddlAmPm = $('#<%=ddlAmPm.ClientID %>');
            if ((typeof txtTime != 'undefined') && (txtTime.val()) && (txtTime.val().length) && txtTime && txtTime.val().length > 0 && txtTime.val().substring(0, 2) == '00') {
                ddlAmPm.attr("selectedIndex", 0);
                ddlAmPm.attr("disabled", "true");
            }
            else {
                ddlAmPm.removeAttr('disabled');
            }
            txtTime.keyup(function(e) {
                if (e.keyCode != 8 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40 && e.which != 8 && e.which != 37 && e.which != 38 && e.which != 39 && e.which != 40) {
                    var timeText = txtTime.val();
                    if (timeText.length >= 2) {
                        var hour = timeText.substring(0, 2);
                        var min = timeText.substring(3, 5);
                        if (hour > 12) {
                            hour = 12;
                        }
                        else {
                            if (hour < 0) {
                                hour = 00;
                            }
                        }
                        if (min < 0) {
                            min = 00;
                        }
                        else {
                            if (min > 59)
                                min = 59;
                        }
                        if (timeText.substring(1, 2) != ":") {
                            txtTime.val('');
                            txtTime.val(hour + ':' + min);
                        }
                    }
                    if (hour == '00') {
                        ddlAmPm.attr("selectedIndex", 0);
                        ddlAmPm.attr("disabled", "true");
                    }
                    else {
                        ddlAmPm.removeAttr('disabled');
                    }
                }
            });

            txtTime.focusout(function(e) {               
                if (txtTime.val() == '') {
                    txtTime.val("00" + ':' + "00");
                }
            });
            if (controlDisable == "True") {
                txtTime.attr("disabled", "true");
                ddlAmPm.attr("disabled", "true");
            }
            else {
                txtTime.attr("enabled", "true");
                ddlAmPm.attr("enabled", "true");
            }
        });
    }

    function GetInstantTime() {
        var ddlAmPm = $('#<%=ddlAmPm.ClientID %>');
        var txtTime = $('#<%=txtTime.ClientID %>');
        var timeText = txtTime.val();
        var time=timeText + " " + ddlAmPm.val();
        return time;
    }
    //-->
</script>

HTML is given below


<table>
    <tr>
        <td runat="server" visible="false" id="tdLabelText">
            <asp:Label ID="lblTimeText" runat="server" CssClass="globalTextBold"/>
        </td>
        <td valign="top">
            <des:IntegerTextBox ID="txtTime" runat="server" Width="45px" CssClass="inputText" MaxLength="5"></des:IntegerTextBox>
        </td>
        <td valign="top">
            <asp:DropDownList ID="ddlAmPm" runat="server" Width="50px" CssClass="inputText">              
            </asp:DropDownList>
        </td>
    </tr>
</table>

Code behind is given below


 /// <summary>
    /// This class defines the methods for managing Time Picker control
    /// </summary>
    public partial class TimePickerControl : ControlBase
    {
        #region Constants

        /// <summary>
        /// Constant string for Zero.
        /// </summary>
        private const string ZERO = "0";

        /// <summary>
        /// Constant string for ZeroZero.
        /// </summary>
        private const string ZEROZERO = "00";

        /// <summary>
        /// Constant int for Twelve.
        /// </summary>
        private const int TWELVE = 12;

        /// <summary>
        /// Constant int for Sero.
        /// </summary>
        private const int SERO = 0;

        /// <summary>
        /// Constant int for One.
        /// </summary>
        private const int ONE = 1;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the time.
        /// </summary>
        /// <value>The time.</value>
        public string Time
        {
            get
            {
                if (!string.IsNullOrEmpty(txtTime.Text))
                {
                    return txtTime.Text + " " + ddlAmPm.SelectedItem.Text;
                }
                else
                {
                    return string.Empty;
                }
            }

            set
            {
                this.SetTime(value);
            }
        }

        /// <summary>
        /// Sets a value indicating whether [read only].
        /// </summary>
        /// <value><c>true</c> if [read only]; otherwise, <c>false</c>.</value>
        public bool ReadOnly
        {
            set
            {
                txtTime.ReadOnly = value;
                ddlAmPm.Enabled = !value;
            }
        }

        public string LabelText
        {
            set
            {
                lblTimeText.Text = value;
                if (lblTimeText.Text != string.Empty)
                {
                    tdLabelText.Visible = true;
                }
                else
                {
                    tdLabelText.Visible = false;
                }
            }
        }

        /// <summary>
        /// Sets a value indicating whether this <see cref="TimePickerControl"/> is enable.
        /// </summary>
        /// <value><c>true</c> if enable; otherwise, <c>false</c>.</value>
        public bool Disable
        {
            get;
            set;
        }

        public string TimeTextClientID
        {
            get
            {
                return this.txtTime.ClientID;
            }
        }

        public string DropdownClientID
        {

            get
            {
                return this.ddlAmPm.ClientID;
            }
        }

        #endregion

        #region Page methods

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindTimePeriod();
            }
        }

        #endregion

        #region Private methods

        /// <summary>
        /// Sets the Tme and AmPm properties of the user control.
        /// </summary>
        /// <param name="time">The time.</param>
        private void SetTime(string time)
        {
            if (!string.IsNullOrEmpty(time))
            {
                DateTime dateTime = Convert.ToDateTime(time);
                string hour = dateTime.Hour.ToString();
                string minute = dateTime.Minute.ToString();

                if (Convert.ToInt32(hour) > TWELVE)
                {
                    int timeHour = Convert.ToInt32(hour);
                    timeHour = timeHour - TWELVE;
                    if (timeHour == SERO)
                    {
                        timeHour = TWELVE;
                    }

                    hour = timeHour.ToString();
                    ddlAmPm.SelectedIndex = ONE;
                }
                else
                {
                    ddlAmPm.SelectedIndex = SERO;
                }

                if (hour == ZERO)
                {
                    hour = ZEROZERO;
                }

                if (hour.Length == ONE)
                {
                    hour = ZERO + hour;
                }

                if (minute.Length == ONE)
                {
                    minute = ZERO + minute;
                }

                txtTime.Text = hour + ":" + minute;
            }
            else
            {
                txtTime.Text = string.Empty;
            }
        }

        /// <summary>
        /// Binds the time period.
        /// </summary>
        private void BindTimePeriod()
        {
            this.ddlAmPm.DataSource = Utils.GetEnumTranslationsList(typeof(Constants.AmPm));
            this.ddlAmPm.DataTextField = "Text";
            this.ddlAmPm.DataValueField = "Value";
            this.ddlAmPm.DataBind();         
        }
        #endregion
    }

Code for exporting data into excel

 This is the code for exporting data into excel.

int rowID = 2;
            Excel.Application xlApp;
            Excel._Workbook workBook;
            Excel._Worksheet workSheet;
            object misValu = System.Reflection.Missing.Value;

            xlApp = new Excel.Application();
            workBook = xlApp.Workbooks.Add(misValu);
            workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(1);
            workSheet.Name = "Church List";

            workSheet.Cells[1, 1] = "Church ID";
            workSheet.Cells[1, 2] = "Church Name";
            workSheet.Cells[1, 3] = "Centre Name";
            workSheet.Cells[1, 4] = "Church Address";
            workSheet.Cells[1, 5] = "Panchayath";
            workSheet.Cells[1, 6] = "Village";
            workSheet.Cells[1, 7] = "Secretary";
            workSheet.Cells[1, 8] = "Phone";
            workSheet.Cells[1, 9] = "Email";
            workSheet.Cells[1, 10] = "Year Formulated";
            workSheet.Cells[1, 11] = "Number Of Members";
            workSheet.Cells[1, 12] = "Have Building";
            workSheet.Cells[1, 13] = "Have Parsonage";
            workSheet.Cells[1, 14] = "Have Cemetry";

            Excel.Range cell = xlApp.ActiveCell;
            cell.EntireRow.Font.Bold = true;
            cell.EntireRow.Cells.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Beige);

            churchs.ForEach(c =>
            {
                CentreDetails centre = dataBase.CentreDetailsCollection.GetCentreByID(c.CentreID);
                workSheet.Cells[rowID, 1] = c.ChurchID.ToString();
                workSheet.Cells[rowID, 2] = c.ChurchName;
                workSheet.Cells[rowID, 3] = centre != null ? centre.CentreName : " - ";
                workSheet.Cells[rowID, 4] = c.ChurchAddress.Place + ", " + c.ChurchAddress.District + ", " + c.ChurchAddress.State + ", " + c.ChurchAddress.Country + ", " + c.ChurchAddress.Pin;
                workSheet.Cells[rowID, 5] = c.Panchayath;
                workSheet.Cells[rowID, 6] = c.Village;
                workSheet.Cells[rowID, 7] = c.Secretory;
                workSheet.Cells[rowID, 8] = c.Phone.ToString();
                workSheet.Cells[rowID, 9] = c.Email;
                workSheet.Cells[rowID, 10] = c.YearFormulated.ToShortDateString();
                workSheet.Cells[rowID, 11] = c.NumberOfMembers.ToString();
                workSheet.Cells[rowID, 12] = c.OwnBuilding ? "Yes" : "No";
                workSheet.Cells[rowID, 13] = c.HaveParsonage ? "yes" : "No";
                workSheet.Cells[rowID, 14] = c.HaveCemetry ? "Yes" : "No";
                rowID++;
            });
            try
            {

                SaveFileDialog s = new SaveFileDialog();
                s.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                s.Filter = "xls|*.xls";

                DialogResult result = s.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string name = s.FileName;
                    workBook.SaveAs(name, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                }
                else
                {
                  
                }
            }
            catch
            {
                MessageBox.Show("File is not accessible", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            xlApp.Quit();

Improved Tool For Javascript in Visual Studio 2011


The first thing you’ll notice when doing JavaScript development in Visual Studio 11 is IntelliSense. After using it, you might forget that you’re working in a dynamic language! The JavaScript editor has been completely rewritten on top of the same Chakra runtime that ships in IE10, which means that IntelliSense is more responsive, accurate and scalable than ever before.
The engine was designed to accommodate the development of both web and Metro style apps, so that regardless which platform you’re targeting, you’ll get the same rich IntelliSense experience. You can see examples of this in the table below. 
  Host API
  Sample Screenshot
  WinRT
  WinJS
  JavaScript  (ES5)
  DOM
  HTML5


Read more

Web API Help page using API Explorer


The main goal of this class is to produce a collection of ApiDescription. It does so by statically inspecting the routes and the available actions inside your controllers. Each ApiDescription describes an API that is available on your service. As you can see from the simplified class diagram below, the ApiDescription contains basic information such as the HttpMethod, the RelativePath, the Documentation, etc. But it also points to anActionDescriptor which is part of the core Web API component that knows everything about an action. You can use it to access a lot more information such as the action name, the return type, the custom attributes, etc. Similarly, you can access the ParameterDescriptor for the expected parameters.


Read more

HTML 5 File Uploader In MVC3


HTML5 makes it possible to develop more powerful and more user friendly web applications than we could do ever before. One of the interesting new features is support for drag and drop of files. In the past, if your application needed to provide the possibility to upload files you had to use a file selection chooser. Although this works without issues in all browsers, it is far from user friendly. In native applications, users can interact with files by using drag and drop which is much more intuitive. Luckily for us, HTML5 now also supports this and it is already supported in a number of browsers (Chrome, Firefox, Safari, …).
In this article, I will show you how we can implement drag & drop in an ASP.NET MVC3 web application. We will create a webpage containing a simple drop area that changes of color when the user is dragging a file over the page and we will update the content of the page if the file upload was successful. In order to implement the client side code, we will make use of jQuery and a jQuery plugin called “jquery-filedrop” that simplifies implementing drag & drop based file upload.

Tuesday, May 29, 2012

Limiting Keystroke To Only Numbers In Windows Application C#

here is the code



 private void txtNumber_KeyDown(object sender, KeyEventArgs e)
        {
            char key = (char)e.KeyData;
            if (e.KeyData == Keys.Back)
            {
                e.SuppressKeyPress = false;
            }
            else
            {
                if (!char.IsDigit(key) || e.Shift || e.Alt || e.Control)
                {
                    e.SuppressKeyPress = true;
                }
            }
        }

This code will limit the key stroke to only numbers, shift, alt and control.

Lambda Expression in C#

Lambda expression is the new feature of C# 3.5 and it is available from vs 2008 onward. It help to iterate through the collection easily.


i => i * i

(i1, i2) => i1 + i2

parm => MessageBox.Show(
    "Do you want to save the file: " + parm + "?", 
    "Confirm file save", MessageBoxButtons.YesNo)

=> is the lambda operator which will enable the compailer to iterate through each object in the collection.
 centreDetails = centreDetailsCollection.Find(c => c.ID == 102);

here centreDetails is an object and centreDetailsCollection is its collection, ie a <T> list.
delegate int Add(int a, int b); 
public void StatementLambda(int operand1, int operan2) 
{ 
    Add result = (a, b) => 
    { 
        int c = a + b; 
        Console.WriteLine(c.ToString()); 
        return c; 
    };     result(operand1, operan2); 
}

Object Serialization


To serialize an object, you need the object to be serialized, a stream to contain the serialized object, and a FormatterSystem.Runtime.Serialization contains the classes necessary for serializing and deserializing objects.
Apply the SerializableAttribute attribute to a type to indicate that instances of this type can be serialized. A SerializationException exception is thrown if you attempt to serialize but the type does not have the SerializableAttribute attribute.
If you do not want a field within your class to be serializable, apply the NonSerializedAttribute attribute. If a field of a serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and the field cannot be meaningfully reconstituted in a different environment, then you may want to make it nonserializable.
If a serialized class contains references to objects of other classes that are marked SerializableAttribute, those objects will also be serialized.

XML Serialization


         
Here is the sample code for XML serialization.


            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Database));  //Database is a class file
            File.WriteAllText(filePath, string.Empty);
            stream = File.Open(filePath, FileMode.Open);
            xmlSerializer.Serialize(stream, dataBase);
            stream.Close();


Serialization means you are converting the object into a binary/ xml format and you can keep it in your locat disk, and whenever it is needed you can convert it into the object format.

Deserialization codes are as follows.


            Database dataBase = new Database();
           XmlSerializer xmlSerializer = new XmlSerializer(typeof(Database));
            if (File.Exists(filePath))
            {
                stream = File.Open(filePath, FileMode.Open);


                if (stream.Length > 0)
                {
                    dataBase = (Database)xmlSerializer.Deserialize(stream);
                }
               stream.Close();
               return dataBase;
             }


learn more about serialization

Rumors about Google and Asus's 7 inch tablet pc

New Rumors have surfaced that Google and Asus are getting ready to jointly release a 7-inch tablet this summer.
Digitimes, citing sources from the "upstream supply chain," claimed on Thursday that shipments of the device will begin in June in preparation for a July launch. Google had originally planned to release its "entry-level" 7-inch tablet in May, but design and costs issues caused the project to be delayed until July for "minor adjustments," according to the news outlet.
Initial shipments of the tablet are expected to reach around 600,000 units, with shipments for the year totaling between 2-2.5 million units, Digitimes reported. The Taiwanese site back in January first reported that Google is prepping a 7-inch tablet that will compete not with the market-dominating iPad, but rather the number-two Amazon Kindle Fire tablet.
Google did not immediately respond to a request for comment from PCMag on Friday. However, executive director Eric Schmidt late last year reportedly said his company would release "a tablet of the highest quality" within six months.

Read more 

Windows 8 tablets release date, specs and prices

Updated Everything you need to know about Windows 8 tablets

By

Windows 8 tablets release date, specs and prices
Windows 8 has been optimised for tablets
Microsoft's been pushing tablet computers for the best part of a decade, so you can imagine how happy the iPad's success makes them.
But Microsoft doesn't give up easily, and Windows 8 tablets will be with us later in the year. One such example, that we saw at CES from Lenovo - called the Yoga - is a wrap-around convertible tablet that becomes an ultraportable laptop.
Microsoft has now released the Consumer Preview of Windows 8, so you can check it out for yourself.
The Windows 8 release date is late 2012, so let's see what Windows 8 tablets will have in store for us. It's a crucial product for Microsoft financially.

Windows 8 to Run Adobe Flash Only

The touch-centric Metro version of Internet Explorer 10 in Windows 8 is plug-in free, but the browser may still be able to run Adobe Flash video, according to an online report. Microsoft is reportedly taking the Google Chrome approach with IE10 and building Flash capability directly into the touch-friendly browser. But Flash won't be available for every site on the Web in Metro IE10. Instead, Microsoft will only extend the capability to select popular sites, according to Windows bloggers Paul Thurrott and Rafael Rivera.
Image Credit: Winsupersite
The new capability could appear in the Windows 8 Release Preview set to debut in early June. Purported screenshots of the release preview (registration required) appeared in an online forum showing Adobe Flash player built-in to the system.
Microsoft in September said that the touch-friendly version of IE10 would be as “HTML5-only as possible, and plug-in free.” While the software giant didn't explicitly say Flash wouldn't run in Metro IE10, the company suggested that would be the case.

ead more 

Monday, May 28, 2012

Learn MVC


MVC
Microsoft’s most powerful platform/architecture, which divides your web application into three modules, Model, View And Controller.

M - Model
V – View
C – Controller

View contains all the UI part of your website/web application, Model handles all the data handling operations and the controller contains the business logics.

This architecture let you to divide your web application into separate modules and let  you to develop and test it separately.

Learn more about MVC…


Create your first MVC application

MVC 2 Tutorial

Post your questions

Post your questions and get answers from millions of professionals....
Keep reading and keep posting...

Sunday, May 27, 2012

Windows 8

Windows 8 will be released soon, Metrostyle application will give you an ambiance of a tablet for your PC's. Metrostyle apps will rewrite the future of IT...

Read more...

http://www.zdnet.com/blog/microsoft/microsoft-to-developers-metro-is-your-future/10611

http://msdn.microsoft.com/en-us/library/windows/apps/hh464920.aspx

Creating a metrostyle app... http://www.codeproject.com/Articles/364537/YaAppLauncher-A-Metro-Style-Application-Launcher-U

 Download files needed for metrostyle app development... http://msdn.microsoft.com/en-us/windows/apps/br229512.aspx

Dot net 4.5 beta

Microsoft is now on its way to introduce the new framework .net 4.5, now the beta version is released. UAT is going on all over the world. Visual studio 2011 will give u an awesome experience in programming.

Read more.. http://msdn.microsoft.com/en-us/library/ms171868(v=vs.110).aspx

http://www.asp.net/vnext/overview/whitepapers/whats-new