Tuesday, July 26, 2011

Make your enter key work like tab in ASP.NET using jquey

 As I am developing a solution for Insurance industry I have some form where huge data entry required. There are plenty of data entry operator who entry data in the form. As they are currently using oracle form where enter key work like tab in windows application. So my department head told me make data entry form like oracle form where operator will use enter key like tab as it is there practice. So I used javascripts and jquery for solving this problem.

  <script type="text/javascript">
    $(document).ready(function(){
        $("input").not( $(":button") ).keypress(function (evt) {
        if (evt.keyCode == 13) {
        iname = $(this).val();
        if (iname !== 'Submit'){
            var fields = $(this).parents('form:eq(0),body').find('button, input, textarea, select');
            var index = fields.index( this );
        if ( index > -1 && ( index + 1 ) < fields.length ) {
            fields.eq( index + 1 ).focus();
        }
        return false;
       }
    }
   });
  });
</script>

Please add this scripts in your data entry page and add jquery-1.4.1.min.js in your page header link. Now enter key will work like tab but when its found button with text submit will work like button.
Hope it will work for you. 











  

Sunday, July 17, 2011

How to clear the previous history of asp.Net textbox

Its a problem everybody faced in their browser. The browser cookie saved the textbox previous history. Sometimes it become security issue.
Click on image to view large
So we should clear previous history from textbox. So I just write a textbox properties in Page_Prerender event in my page(codebehind).
protected void Page_PreRender(Object sender, EventArgs e)
{
     txtPassword.Attributes.Add(“autocomplete”, “off”)
     txtConfirmPassword.Attributes.Add(“autocomplete”, “off”);
}
Hope It will solve your problem too.

Oracle database connection from ASP.NET(C#)

Here is the class DBconnection wrote for connecting oracle database from my asp.net 3.5 application.
I just create a oracle static connection properties. When any body wants to create connection the connection properties first check whether the connection exist or not. If connection exist it just return the connection. If connection is not exist then new connection will be created and returned.




Click on image to view large
Hope you it will help you connecting oracle database from ASP.NET.



Wednesday, July 13, 2011

Autocomplete textbox in ASP.NET using Ajaxcontroltoolkit

AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox.


To make a textbox autocomplete suggestion we can use jquery or ASP.NET ajaxcontroltoolkit. Today I will try to describe how to make autocomplete textbox using ajaxcontroltoolkit. I think its not a complicated work but I saw a lot of question in different forum. Let starts......

We need a  textbox and autocomplete item from visual studio 2008 toolbox.
We need web service. For adding web service a need a web service class. We can add web service by following.

Then we add a method GetCompany that returns string array. We will fetch data from database using prefix string than convert the list of data by string array format. Please check following.
Then we call the method from the ajax autocomplete tool. Like this..

Here is autocomplete tool necessary properties. Service method is the method we need to call from web service class. Service path is the web service path where the asmx page reside.
 You should add a script manager in your page top. 
Hope its done. How simple it is?
Example.








Tuesday, July 12, 2011

Rounding a value in asp.net

Rounding a decimal value in ASP.NET is very easy.
Example:
decimal total = 10.2450;
total = Math.Round(total, 2);
Here Math.Round has eight overloaded function which return different rounding value according to user needs.
In above example I need to round my total value in 2 decimal place. So I total variable and 2 integer in the function which return a decimal value with 2 integer precision.

Search This Blog

Visitor Counter