Monday, November 25, 2013

Positioning an AutoCompleteExtender list in relation to its target control

To make the Auto Complete Extender display always below the Target textbox using JavaScript.

Step 1: Create a function in JavaScript as mentioned below

function resetPosition(object, args) {
    var tb = object._element;
    var tbposition = findPositionWithScrolling(tb);
    var xposition = tbposition[0];
    var yposition = tbposition[1] + 20; // 22 textbox height
    var ex = object._completionListElement;
    if (ex)
        $common.setLocation(ex, new Sys.UI.Point(xposition, yposition));
}
function findPositionWithScrolling(oElement) {
    if (typeof (oElement.offsetParent) != 'undefined') {
        var originalElement = oElement;
        for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
            posX += oElement.offsetLeft;
            posY += oElement.offsetTop;
            if (oElement != originalElement && oElement != document.body && oElement != document.documentElement) {
                posX -= oElement.scrollLeft;
                posY -= oElement.scrollTop;
            }
        }
        return [posX, posY];
    } else {
        return [oElement.x, oElement.y];
    }
}

Step 2: Add the following code in the AjaxControlToolkit: AutoCompleteExtender

 OnClientShown="resetPosition" 

 
Save your code and refresh the page issue has been resolved..!!

Friday, November 22, 2013

Microsoft Reporting WebForms Version Conflict Error resolved..


Error message:
This example is taken with reference to report viewer version 10.0.0.0 and version 9.0.0.0

The type 'Microsoft.Reporting.WebForms.IReportServerCredentials' exists in both 'C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'   

Solution:

Step 1. Open the Solution Explorer and right click on the Solution and select Property Pages.
Step 2. click on references and choose the report viewer which is no required.
Step 3. Click on remove and then build the solution.
















 Error resolved...!!!

For any further information on crystal report you can visit
1. Microsoft MSDN
2. Wikipedia

Monday, July 29, 2013

Tips n Tricks for Microsoft Excel

 

To remove any content or empty place from a column in Excel file.

=TRIM(CLEAN(SUBSTITUTE(,CHAR(160)," ")))

e.g.: =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," ")))

Create conditional formulas

 The IF function uses the following arguments.

Formula with the IF function 

Formula with the IF function:

Callout 1 logical_test: The condition that you want to check.

Callout 2 value_if_true: The value to return if the condition is true.

Callout 3 value_if_false: The value to return if the condition is false.


for reference you can use Microsoft

Thursday, July 25, 2013

SQL SERVER – DBCC RESEED to reset Table Identity Value to zero(or any)


DBCC CHECKIDENT is used to reset the identity column of a table in SQL Server database. e.g. If a table "TEST" has Identity column and currently has 10 records. The next Identity column value would be (say ) "11", but we want the Identity column to be (say) 21, for that we need to reset the Identity column value. The Syntax to perform this task in SQL Server is as :

DBCC CHECKIDENT(,RESEED, Value)

so the sql code to reset would be      DBCC CHECKINDENT(TEST, RESEED, 20)

This will make the next row identity column value as 21.

NOTE: If the Identity column is set below the current value in the table it will violate the unique value constraint and will display an error message. And in order to perform this sql command admin rights are required in SQL Server.

Thursday, July 11, 2013

How to make a text box take only numeric input or any specific input as per user's requirement using JavaScript

In order to insert only numeric value from textbox this JavaScript code could be applied.
Same code can be modified to restrict the users to enter different keyboard inputs as per requirement.
This can be done by changing the ASCII value mentioned in the JavaScript file.


JAVASCRIPT CODE:

write this function under the JavaScript code.

 function isNumber(event)
   {
            var KeyBoardCode = (event.which) ? event.which : event.keyCode;
            if (KeyBoardCode > 31 && (KeyBoardCode < 48 || KeyBoardCode > 57))
            {
                return false;
            }
            return true;
    }


HTML CODE:

use this code in the textbox field to perform the required operation.

onkeypress="return isNumber(event)"

One can make the text box readonly and nothing can be pasted into that by adding the following script in textbox:

onKeyPress = "javascript: return false;" onPaste = "javascript: return false;"

Sunday, April 28, 2013

Download / Upload any file and Display Message using C# in ASP.NET

* To display information using message box in ASP.NET page from server side code.

static public void DisplayAJAXMessage(Control page, string msg)
    {
            string myScript = String.Format("alert('{0}');", msg);
            ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);      
    }


e.g. : DisplayAJAXMessage(this, "Hello World");
OUTPUT: 
Fig 1: Output of DisplayAjaxMessage


* Download a file from server using link button:

protected void lnkDownloadFile_Click(object sender, EventArgs e)
    {
        try
        {
            string FileName = string.Empty;
            FileName = "demo.xls"; // Any File Name with extension
            string link = Server.MapPath("<~/Folder Name/>" + FileName); //Optional Folder Name
            FileInfo myfile = new FileInfo(link);
            Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
            Response.AddHeader("Content-Length", myfile.Length.ToString());
            Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
            Response.TransmitFile(myfile.FullName);
            Response.Flush();
            Response.End();
        }
        catch (Exception ex)
        {
            DisplayAJAXMessage(this, "File Not Found");
        }
    }


private string ReturnExtension(string fileExtension)
    {
        switch (fileExtension)
        {
            case ".xls":
                // case ".csv":
                return "application/vnd.ms-excel";
            default:
                return "application/octet-stream";
        }
    }


* Upload any file to server using C# in ASP.NET 
(Note: This example shows to upload excel file (.xls) , Just change the extension of file as per requirement to upload any type file.)

  protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (UploadFile.HasFile) //FileUpload tool from ToolBox
            {
                string Extension = Path.GetExtension(UploadFile.PostedFile.FileName);
                if (Convert.ToString(Extension).ToLower() != ".xls")
                {
                    lblError.Text = "Please select a file with extension .xls before validation";
                    return;
                }
            }
            else
            {
                lblError.Text = "Please select a file with extension .xls before validation";
                return;
            }
            string uploadFileName = Path.GetFileName(UploadFile.PostedFile.FileName);
            int index = uploadFileName.LastIndexOf('.');
            string SheetName = uploadFileName.Substring(0, index);
            string FileName = Path.GetFileName(UploadFile.PostedFile.FileName);
            string FilePath = Server.MapPath("~//" + FileName); //Optional FolderName
            UploadFile.SaveAs(FilePath);
         }
        catch (Exception ex)
        {
           DisplayAJAXMessage(this,"Error::"+ex);

        }
    }


Happy Coding 



View Amit Lal's profile on LinkedIn

Software Developer, Academic Writing Writer

Friday, March 1, 2013

Host an ASP.NET Application on the Web Server using IIS.



In order to run an .aspx page in our local system, we need ASP.NET Development Server of Visual Studio.  Here we will see how to host an asp.net application on Internet Information Services (IIS).
Following are the steps to follow:

Step 1: Open run window by Pressing windows + R button and type inetmgr.

Fig: Run Window


Step 2: Internet Information Services (IIS) Manager Page will open and right click on Sites and add new web site. 

Fig: Internet Information Services (IIS) Manager
Step 3: Fill the Site Name, the physical path directory where the webpages (.aspx) are located and change the port number from 80 to any other unused port number as its the system default port number and press OK.

Fig: Add Website Name and Physical Path


Optional Step: If you want to change the physical path later on, then it can be changed by clicking the advanced settings option in the right hand side on the Action Tab or by right clicking the website and select the Manage website ->Advanced Settings.



Fig: Advanced settings


Step 4: Now your website is ready to be browsed, you can right click on your website and go to Manage Web Site -> Browse. You will see the default page without visual studio server.


Fig: Browse website



Note: Website may not work if you have developed it in Visual Studio 2010 as your web.config file may have some tags that is not identified by the IIS. This is because creating the website the way we created just now will host your website in its own application pool that will have .NET Framework version 2 as target version. So we need to change to the .NET Framework 4.0 version.

In IIS Manager Click on the Application pools in the Connections Tab in left hand side and search for your website and right click on it and click on Basic settings.



Fig: Application pools


On Edit Applications Pool Select .NET Framework v4.xxx from the .NET Framework version drop-down list and click OK.
 

Fig: Edit Application Pool

Refresh your website and follow step 4 to view it in your browser. And Happy Browsing.



Monday, November 25, 2013

Positioning an AutoCompleteExtender list in relation to its target control

To make the Auto Complete Extender display always below the Target textbox using JavaScript.

Step 1: Create a function in JavaScript as mentioned below

function resetPosition(object, args) {
    var tb = object._element;
    var tbposition = findPositionWithScrolling(tb);
    var xposition = tbposition[0];
    var yposition = tbposition[1] + 20; // 22 textbox height
    var ex = object._completionListElement;
    if (ex)
        $common.setLocation(ex, new Sys.UI.Point(xposition, yposition));
}
function findPositionWithScrolling(oElement) {
    if (typeof (oElement.offsetParent) != 'undefined') {
        var originalElement = oElement;
        for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
            posX += oElement.offsetLeft;
            posY += oElement.offsetTop;
            if (oElement != originalElement && oElement != document.body && oElement != document.documentElement) {
                posX -= oElement.scrollLeft;
                posY -= oElement.scrollTop;
            }
        }
        return [posX, posY];
    } else {
        return [oElement.x, oElement.y];
    }
}

Step 2: Add the following code in the AjaxControlToolkit: AutoCompleteExtender

 OnClientShown="resetPosition" 

 
Save your code and refresh the page issue has been resolved..!!

Friday, November 22, 2013

Microsoft Reporting WebForms Version Conflict Error resolved..


Error message:
This example is taken with reference to report viewer version 10.0.0.0 and version 9.0.0.0

The type 'Microsoft.Reporting.WebForms.IReportServerCredentials' exists in both 'C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'   

Solution:

Step 1. Open the Solution Explorer and right click on the Solution and select Property Pages.
Step 2. click on references and choose the report viewer which is no required.
Step 3. Click on remove and then build the solution.
















 Error resolved...!!!

For any further information on crystal report you can visit
1. Microsoft MSDN
2. Wikipedia

Monday, July 29, 2013

Tips n Tricks for Microsoft Excel

 

To remove any content or empty place from a column in Excel file.

=TRIM(CLEAN(SUBSTITUTE(,CHAR(160)," ")))

e.g.: =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," ")))

Create conditional formulas

 The IF function uses the following arguments.

Formula with the IF function 

Formula with the IF function:

Callout 1 logical_test: The condition that you want to check.

Callout 2 value_if_true: The value to return if the condition is true.

Callout 3 value_if_false: The value to return if the condition is false.


for reference you can use Microsoft

Thursday, July 25, 2013

SQL SERVER – DBCC RESEED to reset Table Identity Value to zero(or any)


DBCC CHECKIDENT is used to reset the identity column of a table in SQL Server database. e.g. If a table "TEST" has Identity column and currently has 10 records. The next Identity column value would be (say ) "11", but we want the Identity column to be (say) 21, for that we need to reset the Identity column value. The Syntax to perform this task in SQL Server is as :

DBCC CHECKIDENT(,RESEED, Value)

so the sql code to reset would be      DBCC CHECKINDENT(TEST, RESEED, 20)

This will make the next row identity column value as 21.

NOTE: If the Identity column is set below the current value in the table it will violate the unique value constraint and will display an error message. And in order to perform this sql command admin rights are required in SQL Server.

Thursday, July 11, 2013

How to make a text box take only numeric input or any specific input as per user's requirement using JavaScript

In order to insert only numeric value from textbox this JavaScript code could be applied.
Same code can be modified to restrict the users to enter different keyboard inputs as per requirement.
This can be done by changing the ASCII value mentioned in the JavaScript file.


JAVASCRIPT CODE:

write this function under the JavaScript code.

 function isNumber(event)
   {
            var KeyBoardCode = (event.which) ? event.which : event.keyCode;
            if (KeyBoardCode > 31 && (KeyBoardCode < 48 || KeyBoardCode > 57))
            {
                return false;
            }
            return true;
    }


HTML CODE:

use this code in the textbox field to perform the required operation.

onkeypress="return isNumber(event)"

One can make the text box readonly and nothing can be pasted into that by adding the following script in textbox:

onKeyPress = "javascript: return false;" onPaste = "javascript: return false;"

Sunday, April 28, 2013

Download / Upload any file and Display Message using C# in ASP.NET

* To display information using message box in ASP.NET page from server side code.

static public void DisplayAJAXMessage(Control page, string msg)
    {
            string myScript = String.Format("alert('{0}');", msg);
            ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);      
    }


e.g. : DisplayAJAXMessage(this, "Hello World");
OUTPUT: 
Fig 1: Output of DisplayAjaxMessage


* Download a file from server using link button:

protected void lnkDownloadFile_Click(object sender, EventArgs e)
    {
        try
        {
            string FileName = string.Empty;
            FileName = "demo.xls"; // Any File Name with extension
            string link = Server.MapPath("<~/Folder Name/>" + FileName); //Optional Folder Name
            FileInfo myfile = new FileInfo(link);
            Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
            Response.AddHeader("Content-Length", myfile.Length.ToString());
            Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
            Response.TransmitFile(myfile.FullName);
            Response.Flush();
            Response.End();
        }
        catch (Exception ex)
        {
            DisplayAJAXMessage(this, "File Not Found");
        }
    }


private string ReturnExtension(string fileExtension)
    {
        switch (fileExtension)
        {
            case ".xls":
                // case ".csv":
                return "application/vnd.ms-excel";
            default:
                return "application/octet-stream";
        }
    }


* Upload any file to server using C# in ASP.NET 
(Note: This example shows to upload excel file (.xls) , Just change the extension of file as per requirement to upload any type file.)

  protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (UploadFile.HasFile) //FileUpload tool from ToolBox
            {
                string Extension = Path.GetExtension(UploadFile.PostedFile.FileName);
                if (Convert.ToString(Extension).ToLower() != ".xls")
                {
                    lblError.Text = "Please select a file with extension .xls before validation";
                    return;
                }
            }
            else
            {
                lblError.Text = "Please select a file with extension .xls before validation";
                return;
            }
            string uploadFileName = Path.GetFileName(UploadFile.PostedFile.FileName);
            int index = uploadFileName.LastIndexOf('.');
            string SheetName = uploadFileName.Substring(0, index);
            string FileName = Path.GetFileName(UploadFile.PostedFile.FileName);
            string FilePath = Server.MapPath("~//" + FileName); //Optional FolderName
            UploadFile.SaveAs(FilePath);
         }
        catch (Exception ex)
        {
           DisplayAJAXMessage(this,"Error::"+ex);

        }
    }


Happy Coding 



View Amit Lal's profile on LinkedIn

Software Developer, Academic Writing Writer

Friday, March 1, 2013

Host an ASP.NET Application on the Web Server using IIS.



In order to run an .aspx page in our local system, we need ASP.NET Development Server of Visual Studio.  Here we will see how to host an asp.net application on Internet Information Services (IIS).
Following are the steps to follow:

Step 1: Open run window by Pressing windows + R button and type inetmgr.

Fig: Run Window


Step 2: Internet Information Services (IIS) Manager Page will open and right click on Sites and add new web site. 

Fig: Internet Information Services (IIS) Manager
Step 3: Fill the Site Name, the physical path directory where the webpages (.aspx) are located and change the port number from 80 to any other unused port number as its the system default port number and press OK.

Fig: Add Website Name and Physical Path


Optional Step: If you want to change the physical path later on, then it can be changed by clicking the advanced settings option in the right hand side on the Action Tab or by right clicking the website and select the Manage website ->Advanced Settings.



Fig: Advanced settings


Step 4: Now your website is ready to be browsed, you can right click on your website and go to Manage Web Site -> Browse. You will see the default page without visual studio server.


Fig: Browse website



Note: Website may not work if you have developed it in Visual Studio 2010 as your web.config file may have some tags that is not identified by the IIS. This is because creating the website the way we created just now will host your website in its own application pool that will have .NET Framework version 2 as target version. So we need to change to the .NET Framework 4.0 version.

In IIS Manager Click on the Application pools in the Connections Tab in left hand side and search for your website and right click on it and click on Basic settings.



Fig: Application pools


On Edit Applications Pool Select .NET Framework v4.xxx from the .NET Framework version drop-down list and click OK.
 

Fig: Edit Application Pool

Refresh your website and follow step 4 to view it in your browser. And Happy Browsing.