September 20, 2012

Using jQuery allowing Only Alphanumeric Characters in a Textbox


Requirement

Need to restrict the users by entering other than Alphanumeric Characters, if any user enters Non- Alphanumeric Characters then need to trim those Characters and display a message beside the respective textbox saying only Alphanumeric Characters are allowed…

 Solution:

We have many solutions but using jQuery is the best way to achieve, with this we can use more flexible and reliable Regular expression technology with jQuery to achieve the above requirement.

 Script Code:

 $(function () {

             $("#span_txtFirstName").hide();

            $("[id*='txtFirstName']").keyup(function () {

                $("#span_txtFirstName").hide();

                if (this.value.match(/[^a-zA-Z0-9 ]/g)) {

                    this.value = this.value.replace(/[^a-zA-Z0-9 ]/g, '');

                    $("#span_txtFirstName").toggle(500);

                }

            });

 
HTML Code:

<asp:TextBox ID="txtFirstName" runat="server" Width="200px" CssClass="styled_input"></asp:TextBox>

<span id="span_txtFirstName" class="RegistrationNumericDiv">oops! Only AlphaNumberic Charecters are Accepted.</span>

 
Explanation:

In the above HTML Code is the normal code as I used asp.Net TextBox control to present this demo, but we can use any technology here as our browser parser can understand only HTML tags so every technology has their own parser to parse their respective language code to HTML code. Next line we have a SPAN tag which is used to hold the message to the user whenever user types a non-alphanumeric character in the respective textbox and this SPAN tag hide/show will be handled in the given jQuery code itself.

As we can see we use the regular expression to validate each character enter by the user and if anything wrong we replace those character(s) with empty string (‘’) and we show the message by toggling the  SPAN tag..

That’s it we are done with our requirement J

Thank you

Happy Coding J

September 14, 2012

Google Maps Navigation Beta Version for Android arrives in India

Finally, Google Maps Navigation Beta for Android has been rolled out in India delivering voice-based navigation in major parts of the country. Apart from this, the application even proffers live traffic updates.
In order to make use of this service, all that’s needed is to type in or dictate the name or the address of the place intended to visit and travelers are all set to go. Interestingly, users needn’t have worry about spelling mistakes as the app corrects it automatically to offer the required results. The application will provide directions orally in a familiar native accent on activating the Indian English locale setting.

“We’re excited today to announce that both of these features are now available for Google Maps users in India — one of the most dynamic and fastest-growing markets for online map services worldwide. Google Maps Navigation (Beta) is free and accessible to any smartphone user running Android 2.2 or later, and live traffic information is visible on both the mobile and desktop versions of Google Maps,” reads a post on the official Google blog.

The application is said to offer live traffic information for six major cities within the country including Bengaluru, New Delhi, Chennai, Pune, Hyderabad and Mumbai. On activating the traffic layer option, the app will provide colored highlights such as red for tight jams, while the yellow and green markings denote slow moving and free-flowing traffic, respectively. Users will also be able to find ‘typical’ traffic conditions for a specific time or day.

Google Maps Navigation Beta for Android can be picked up for free via the Play store.

Date Problem when having Client & Server in different TimeZone

Hi, I want to share my problem and its solution i found..

Problem : I have developed one client Application in which iam getting data from database in to DataView Object, Now my task is to show the records on the Grid which are greater than or equal to current system date.
To do so i used following code
(overview not exactly)
 
String today = DateTime.Now.ToString();
dv.RowFilter = string.Format("TODATE >=#{0}#", today);
 
Its working fine on some systems and raising exceptions on some other systems.
Solution : the exact problem is culture the system. When the culture is different what we expecting then its getting execption to fix this problem i coded the above code as follows:
 
CultureInfo culture = new CultureInfo("en-US");
String today = DateTime.Now.ToString("d",culture);
dv.RowFilter = string.Format("TODATE >=#{0}#", today);
 
Now this code perfectly works on any ssytem with any culture.
Happy to Share Code
 

You are attempting to access powerpivot data that was added using a newer version of powerpivot


The Report which you are using is built on new power pivot version, for this reason reports are not working on old power pivot version and showing below error message.

 

Resolution:  Please install new version of power pivot (i.e. 11.0.2100.60) from below link.


 

Impact :  If you are installed new power pivot version from above link existing reports which are built on old Power pivot will open with the below message in a dialogue box

Saying that “Do you want Upgrade the workbook”, if you click on OK the report will work fine.

September 13, 2012

Solution for Parsing an Excel file in C# and the cells seem to get cut off at 255 characters


Problem: An excel sheet containing say 10 rows and in couple of columns in couple of rows having data with more than 255 characters. When I try to upload this file in ASP.Net application using traditional OLEDB provider I cannot saw the whole data in particular cell means which is chopping out or we can say trimming to 255 characters when loaded in to my dataset object.

Solution: Having done sleepless nights I found some solutions to fix this issue… those are presented below

Solution-1:

If your application is used only on one computer then you can directly go to the following registry settings and change the TypeGuessRows  value.

HKLM\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows

64 bit systems:

HKLM\SOFTWARE\wow6432node\microsoft\jet\4.0\engines\excel\TypeGuessRows

By setting this value to zero, the all lines of your spreadsheet are scanned for type guessing, rather than the default of 8. If any text fields longer than 255 chars are encountered, then those columns are deemed to be memo fields.

Note that you are still not 100% guaranteed to get the right data types, depending on your data.

Note also the HKLM scope of this key though - it will affect every OleDB Excel import by any process on that machine and this lead to degrade performance depending on the size of the data.

Solution-2:

A second way to work around this problem (without modifying the registry) is to make sure that rows with fields, which have data 255 characters or greater, are present in the first 8 rows (default value of TypeGuessRows is 8) of the source data file.

 

Solution-3:

This is the recommended solution by me as there is no need to change any registry or take care to have those lengthy data to be in first 8 rows. Instead we have a tool called NPOI which can be download from npoi.codeplex.com.

Using this dll we can upload the spreadsheet without worrying of chopping your data and also it has many features like creating the spreadsheet on fly including charts, reports etc.., for more information you can find on this site npoi.codeplex.com.

Anyway reading data using this NPOI is different from the traditional OLEDB provider. Please find the following method which with return a Data Table object by sending the File Path and the respective SheetName as input.

public static DataTable getExcelData(string FileName, string strSheetName)

    {

        DataTable dt = new DataTable();

        HSSFWorkbook hssfworkbook;

        using (FileStream file = new FileStream(FileName, FileMode.Open, FileAccess.Read))

        {

            hssfworkbook = new HSSFWorkbook(file);

        }

 

        ISheet sheet = hssfworkbook.GetSheet(strSheetName);

        System.Collections.IEnumerator rows = sheet.GetRowEnumerator();

       

        while (rows.MoveNext())

        {

            IRow row = (HSSFRow)rows.Current;

 

            if (dt.Columns.Count == 0)

            {

                for (int j = 0; j < row.LastCellNum; j++)

                {

                    dt.Columns.Add(row.GetCell(j).ToString());

                }

 

                continue;

            }

 

            DataRow dr = dt.NewRow();

            for (int i = 0; i < row.LastCellNum; i++)

            {

                ICell cell = row.GetCell(i);

 

                if (cell == null)

                {

                    dr[i] = null;

                }

                else

                {

                    dr[i] = cell.ToString();

                }

            }

            dt.Rows.Add(dr);

        }

 

        return dt;

    }

 

May be I presented the solutions straight forward without more explanation or discussion but presently my motto is to provide you the reasonable and permanent solution for those who suffering with similar problem.

Hope this research and the code helps you a lot.. if so please drop a comment below which may be more encroached for me..

 

Happy Coding J