Technological Guide.

ASP.Net FileUpload control inside Ajax UpdatePanel

Wednesday, May 18th, 2011

I’m posting this article with reference to the request from my friends and for all other world wide asp.net lovers and especially for programmers who are in need of a solution for asp.net FileUpload control inside Ajax UpdatePanel. We often face problem with FileUpload control when its placed inside Ajax UpdatePanel. There is a simple trick for it to make it upload without any issues :).

ASP.Net FileUpload control needs a full Page PostBack to upload file and proceed further. The simplest solution to use UpdatePanel is by adding PostBackTrigger to the updatepanel as shown below.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        Please upload your file: <br />
        <asp:FileUpload ID="FileUpload1" runat="server" />&nbsp;&nbsp;
        <asp:Button runat="server" ID="btnSubmit" Text="Upload"
            onclick="btnSubmit_Click" />
        <br />
        <asp:Label runat="server" ID="lblFileDetails" Text=""></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnSubmit" />
    </Triggers>
</asp:UpdatePanel>

I’m presenting you a simple example with both HTML source code and C# code behind files which is coded for Microsoft .Net Framework 3.5 (Visual Studio 2008).

You can download from: FileUploadInsideUpdatePanel

Vb2008 How to show images in ListView from Database

Saturday, August 15th, 2009

Technorati Profile
Being programmers you may get requirement to handle with images to save to database and load them into ListView container. I’m presenting a code snippet in Visual Basic 2008 which can be downloaded and can be tested on your end for the ListView items with images retrieved and updated back to the database. You can download C# coding from ListViewImgDb.

Features:

  • Allows to select image using OpenDialog.
  • You can save to database which will be an Access 2003 mdb file located in binDebug folder.
  • You can retrieve images using Retrieve Images button.
  • You can remove image using Remove button which will remove image from database directly.

Requirements:

  • Visual Basic 2008 with Microsoft .Net Framework 3.5

You can download from ListViewImgDb and use the rar file using the password: lsv123

C#2008 How to show images in ListView from Database

Thursday, August 13th, 2009

Being programmers you may get requirement to handle with images to save to database and load them into ListView container. I’m presenting a code snippet in Visual C# 2008 which can be downloaded and can be tested on your end for the ListView items with images retrieved and updated back to the database.

Features:

  • Allows to select image using OpenDialog.
  • You can save to database which will be an Access 2003 mdb file located in \bin\Debug folder.
  • You can retrieve images using Retrieve Images button.
  • You can remove image using Remove button which will remove image from database directly.

Requirements:

  • Visual C# 2008 with Microsoft .Net Framework 3.5

You can download from ListViewImgDb and use the rar file using the password: lsv123

How to create Pdf file in ASP.Net

Wednesday, June 24th, 2009

Creating Pdf files in Asp.Net may not be a requirement but many of us being developers always wish to create pdf files to deliver some information instead of always going for crystal reports or others. The Microsoft .Net Framework didn’t provide any native way to work with PDF files, to serve our purpose we need to rely on third party components that are available. The best open-source free component available is iTextSharp. iText# (iTextSharp) is a port of the iText open source java library written entirely in C# for the .NET platform. iText# is a library that allows you to generate PDF files on the fly. It is implemented as an assembly. You can download iTextSharp dll from here.

 

Here we’ll see a simple web application to make use of iTextsharp to create pdf file with our own text. Create a web application and Add reference to the iTextShar.dll file which is extracted from the zip file downloaded from the above link. Create a folder inside your application called “PDF” to store our created pdf files. Design the Default.aspx with a multilined TextBox (to let user or we to enter our preferred text in paragraphs to appear in the pdf file) and a Button to trigger the code for pdf file creation as shown in the picture.

In code behind file we’ve to add 2 namespaces inorder to use iTextSharp Classes and Methods.

 

Code Behind File

Run the application, enter the information in multilined Textbox which must be displayed in pdf and click the button Create Pdf. An alert message will prompt you saying Pdf file has been successfully created. Now close the application and check the PDF folder inside the application which will contain a Pdf file created whcih looks as follows.

Color Selector

Wednesday, June 24th, 2009
Color Selector is a small application developed in Visual C# which displays all named color along with a small strip of the color. Upon selecting the color the below panel will be updated with the selected color. As shown in the 2 images.

The DrawItem event of the combo box control has to be implemented in the code and DrawMode property for the combo box control must be set to OwnerDrawFixed in design time in order to let the DrawItem event work.

Design & Coding Application:

Create a Visual C# Windows Forms project in either Visual Studio 2005 / 2008 with Single Form which contains a button (btnLoadColorList), combo box(cmbColorList) and panel (pnlColorTester). Set the DrawMode property of cmbColorList to OwnerDrawFixed and DropDown height property of cmbColorList to 80.

Code for the Form will be as follows.

You can download the sample application developed in Visual Studio 2008 from here.

The Open Source Development Environment for .Net

Monday, June 22nd, 2009

“#Develop” (SharpDevelop) is a free open source IDE for C#, Vb.Net and Boo projects on Microsoft .Net platform. “#Develop” offers many features, few are listed below

Features of SharDevelop
SharpReport ported (including SharpQuery)
Code Coverage support based on NCover
PInvoke addin reported
Support for Web references
Right-to-left support

SharpDevelop is available for all versions of Microsoft .Net framework from below link.

http://www.icsharpcode.net/OpenSource/SD/Download/

Date Formatting in ASP.Net

Tuesday, June 16th, 2009

We need to format date values in our application often. We can format date value as shown below.

The output for the above two methods will be shown as follows.
16-Jun-2009
16-Jun-2009
We can even format a date value retrieved from database in the above method.

We can format the datetime value either module specific or page specific or application specific method using Globalization.

The output for the above 3 methods are as follows…
16-06-2009
16 June 2009
16-06-2009 15:24:42
We can apply a specific culture for globalization in module level as shown above, or in page level in page declaration or in web.config file as shown below in

Error: The Operation must use an updatable query

Tuesday, June 9th, 2009

When we work with an ASP.Net application with MS-Access as backend database, we often face the error “The operation must use an updatable query”. Even though our code compiles and builds without any errors, when we run the application, when the page tries to INSERT or UPDATE records the above error will be raised. We’ll see the details of the error root cause and the easy solution.

When working with MS-Access database in ASP.Net web application, the MS-Access database.mdb file will be placed in the App_Data folder. When we develop ASP.Net application in multi-user environment(like Windows XP, Windows 2003, Windows 2008), a.ldb file will be created whenever the database is opened. This particular .ldb file contains details of the user who opened the file, and prevents writing the records which are opened by another user.

All ASP.Net applications use the “ASPNET” machine account in Windows XP and “NETWORK SERVICE” account in Windows Server 2003, 2008 and Vista machines to access the file system of Operating System. Inorder to create, write and delete the required .ldb file, the relevant user “ASPNET” or “NETWORK SERVICE” account must needs MODIFY / WRITE permissions on the folder where the .mdb file resides which is App_Data folder in our ASP.Net Application.

To enable MODIFY / WRITE permissions on the App_Data folder, open the ASP.Net web application project folder in Windows Explorer, right click on the App_Data folder and select properties. When we reach properties we can see several tabs, among the tabs, go to Security tab which contains User Names section as shown below.

click the Edit button which will show UserNames window as shown below.

and then click Add which shows as follows

Type the account and click “Check Names” to verify the account name typed and click “OK” to add the user account. Upon clicking add, we’ll reach to Security Permission Edit Window, then click “Modify” for the account we added and click ok and Run the ASP.Net web application which can insert & update in the Microsoft Access Database.

The above solution can even fix the errors like The Microsoft Jet database engine cannot open the file (unknown), It is already opened exclusively by another user, or you need permission to view its data.

Highlight ASP.Net Gridview Row on Mouse Hover

Monday, June 8th, 2009

It’ll be very attractive & meaningful UI to highlight a GridViewRow when mouse pointer hovers which can be achieved with the following code.