How to disable asp.net button on postback ?


DisableButton
Hi

Recently in one project there was requirement to disable asp.net Submit button on postback then i did like this using inline javascript

  <asp:Button runat="server" ID="BtnSubmit" 
  OnClientClick="this.disabled = true; this.value = 'Submitting...';" 
  UseSubmitBehavior="false" 
  OnClick="BtnSubmit_Click" 
  Text="Submit" />
Advertisements

Code Cleanup free tool for Visual studio 2010/12


Hi

Recently i was doing code cleanup of my project. I was searching some tool for this work then i got very nice tool. It is really very useful tool for developer. You also just try it.

You can download from here

http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/

You can read the documentation from here

http://www.codemaid.net/documentation/#reorganizing

I hope it will help to other developers.

How to integrate Twitter like plugin in website ?


twitter

Hi

If we have to integrate Twitter like plugin in website. Then we can integrate like this.

Step 1: Download the jquery.followbox.min.js plugin
Step 2: Give the UserId of your twitter Account

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
       <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>

    <link href="followbox.css" rel="stylesheet" type="text/css" />
    <script src="jquery.followbox.min.js" type="text/javascript"></script>
    <script type="text/javascript">
   $(function(){
   $('#mytwitterfollowbox').followbox({
       user: 'Chandradev819'
   });
   });
   </script>
</head>
<body>
    <form id="form1" runat="server">
   <div id="mytwitterfollowbox" class="follow-box-container"></div>
    </form>
</body>
</html>


.

You can download the code from here.

How to create effect on Textbox using CSS ?


CssEffect

Hi

We can add very nice effect on asp.net Textbox using this CSS like this


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
    text {
    border: 1px solid #666;
    border-radius: 5px;
    padding: 3px;
}

.text:focus {
    border: 1px solid #07c;
    box-shadow: 0 0 5px #07c;
    outline: none;
}
    
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        UserName : <asp:TextBox ID="TextBox1" CssClass="text" runat="server"></asp:TextBox>
        <br /> <br /> 
        Password&nbsp; : <asp:TextBox ID="TextBox2" CssClass="text" runat="server"></asp:TextBox>
        <br />
        
    </div>
    </form>
</body>
</html>

How to use Masked Edit ajax validator control for Date ?


Mask

If we have to validate Textbox for Date format then “Ajax Masked Edit” control is one of the easiest solution to do this task. We can do like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Image ID="Image1" ImageUrl="~/Calendar_scheduleHS.png" runat="server" />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        <asp:MaskedEditExtender   
            ID="MaskedEditExtender1"  
            runat="server"  
            TargetControlID="TextBox1" 
            Mask="99/99/9999"   
            MaskType="Date" 
           CultureName="en-US" 
            MessageValidatorTip="true"/>  
     
         
        <asp:MaskedEditValidator   
            ID="MaskedEditValidator1"  
            runat="server"  
            ControlToValidate="TextBox1"  
            ControlExtender="MaskedEditExtender1"  
            IsValidEmpty="false"/>  
    
        <asp:CalendarExtender ID="CalendarExtender1" TargetControlID="TextBox1" format="dd/MM/yyyy"  PopupButtonID="Image1" runat="server"/>
        <br />
    </div>
    </form>
</body>
</html>


Posted in Ajax. 1 Comment »

Excel reading using ExcelDataReader dll


Hi
We will get the scenario to read the Excel file and display somewhere or save in some database
We can do this task using so many approaches
1. Using OLEDB driver
It is one of the traditional and famous approaches. But here is one problem. If you will upload huge data i.e more than 255 character in one column. If you will upload it then it will truncate 255 char. But you can fix this issue while changing the registry. But if it is web based application then this approach will be not suitable.
2. Using ExcelDataReader DLL
It is a Lightweight library used for reading Microsoft Excel files in .NET. It is open source dll. Here is not limitation on char size. It is also very simple to use in the project.

Step1: Download the dll using this link
http://exceldatareader.codeplex.com/

Step2: write the code in code behind file like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ICSharpCode.SharpZipLib;
using ICSharpCode;
using Excel;
using System.IO;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        dataUpload();
    }
    protected void dataUpload()
    {

        if (FileUpload1.HasFile)
        {
            string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName);

            string path = FileUpload1.PostedFile.FileName;

            FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read);

            //for excel 2003
            // IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            // for Excel 2007
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            excelReader.IsFirstRowAsColumnNames = true;
            DataSet result = excelReader.AsDataSet();
            excelReader.IsFirstRowAsColumnNames = true;
            GridView1.DataSource = result;
            GridView1.DataBind();

        }
        else
        {
            LblError.Text = "Unable to upload the selected file. Please check the selected file path or confirm that the file is not blank!";
        }


    }
}

.

You can also download the code from here

Posted in C#. 10 Comments »

How to convert Numeric Value to Word formate using C# ?


NoConverter
Hi

We used to get scenario to convert Numeric value to word format so many time in our project. We can do this task like this

Step1: Create on static class like this


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Converter
/// </summary>
public class Converter
{
	public static string NumberToWords(int number)
{
    if (number == 0)
        return "zero";

    if (number < 0)
        return "minus " + NumberToWords(Math.Abs(number));

    string words = "";

    if ((number / 1000000) > 0)
    {
        words += NumberToWords(number / 1000000) + " million ";
        number %= 1000000;
    }

    if ((number / 1000) > 0)
    {
        words += NumberToWords(number / 1000) + " thousand ";
        number %= 1000;
    }

    if ((number / 100) > 0)
    {
        words += NumberToWords(number / 100) + " hundred ";
        number %= 100;
    }

    if (number > 0)
    {
        if (words != "")
            words += "and ";

        var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
        var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

        if (number < 20)
            words += unitsMap[number];
        else
        {
            words += tensMap[number / 10];
            if ((number % 10) > 0)
                words += "-" + unitsMap[number % 10];
        }
    }

    return words;
}
}

Step 2: Create the aspx code like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 <asp:TextBox ID="txtNo" runat="server" />
    <br />
    <asp:Button ID="btnSubit" runat="server" Text="Submit" onclick="btnSubit_Click" /> <br />
    <asp:Label ID="lblmsg" ForeColor="Red" runat="server" />
        <br />
    </div>
    </form>
</body>
</html>

Steps 3: Call the static class in Code behind file like this


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubit_Click(object sender, EventArgs e)
    {
        int inputVal=Convert.ToInt32(txtNo.Text);
        lblmsg.Text = Converter.NumberToWords(inputVal);
    }
}

Posted in C#. 7 Comments »