Sunday, 24 February 2013

JQuery Carousel


JQuery Carousel


Yesterday One of my sub-ordinate asked me can we make Carousel in ASP.Net like we use to do in HTML. I thought for a while and replied :" I have not made any Carousel thing before.Let Me Try.."

After Googling a little I found many ways to achieve the same.. I will share one with you using Jquery Javascript Library..

You will need jquery-latest.pack.js and jcarousellite_1.0.1.js to achieve this functionality.. Just Google and You can download it from standard Jquery Library..

Here is the Code Snippet to achieve this:


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Carousel Demo</title>
    <script type="text/javascript" src="Scripts/jquery-latest.pack.js"></script>
 <script type="text/javascript" src="Scripts/jcarousellite_1.0.1.js"></script>
 <script type="text/javascript">
  $(function() {
  $(".myClass").jCarouselLite({
   btnNext: ".next",
   btnPrev: ".prev"
  });
 });
</script>
</head>
<body>
    <form id="form1" runat="server">
<div class="myClass">
    <ul>
        <li><img src="Images/Pic1.jpg" alt="" width="400" height="400"></img></li>
        <li><img src="Images/Pic2.jpg" alt="" width="400" height="400"></img></li>
        <li><img src="Images/Pic3.png" alt="" width="400" height="400"></img></li>
        <li><img src="Images/Pic4.jpg" alt="" width="400" height="400"></img></li>
        <li><img src="Images/Pic5.png" alt="" width="400" height="400"></img></li>
        <li><img src="Images/Pic6.png" alt="" width="400" height="400"></img></li>
        <li><img src="Images/Pic7.jpg" alt="" width="400" height="400"></img></li>
    </ul>
</div>
<button class="prev"><<</button>
<button class="next">>></button>
    </form>
</body>
</html>


and Here is the Output:



Thursday, 21 February 2013

Get Mac Address and Adapter Types ASP.NET C#


Get Mac Address and Adapter Types ASP.NET C#


Today I was thinking of getting the MAC address of a particular System.. I googled but didnt found anything suitable..So After Trying a little I was able to write my own custom Working Code which could also display the Adapter Types being Used...

First of all we have to create a custom Utility Class inside the namespace Util as follows:

Note: Here is a catch over here .. You have to manually reference to System.Management.dll within your project..

Go to Project> Right Click>Add Reference>Go To .Net Tab and Select System.Management.dll

Code for Utility.cs:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Management.Instrumentation;
using System.Management;

namespace Util
{
     public class Utility
     {
        public static string GetMacAddress(string AdapterTypes)

        {
            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapter where Name='" + AdapterTypes + "'");

            ManagementObjectCollection moc = mos.Get();

            string MACAddress = null;

            if (moc.Count > 0)

            {

                foreach (ManagementObject mo in moc)

                {

                    MACAddress = (string)mo["MACAddress"];

                }

            }

            return MACAddress;

        }

        public static List<string> GetAllAdapterTypes()

        {

            List<string> AdapterTypes = new List<string>();

            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapter Where AdapterType='Ethernet 802.3'");

            foreach (ManagementObject mo in mos.Get())

            {

                AdapterTypes.Add(mo["Name"].ToString());

            }

            return AdapterTypes;

        }
     }
}

MacAddress.aspx:


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Get Mac Address and Adapter Types</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <table class="style1">

            <tr>

                <td class="style2">

                    <asp:DropDownList ID="DropDownList1" runat="server">

                    </asp:DropDownList>

                </td>

                <td>

                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

                </td>

            </tr>

            <tr>

                <td class="style2">

                    &nbsp;</td>

                <td>

                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

                </td>

            </tr>

        </table>
    </div>
    </form>
</body>
</html>

MacAddress.aspx.cs:


using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Util;

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

            {
                foreach (string item in Utility.GetAllAdapterTypes())

                { DropDownList1.Items.Add(item); }

            }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = Utility.GetMacAddress(DropDownList1.SelectedItem.Text);
    }
}




Random Password Generator ASP.NET C#


Random Password Generator ASP.NET C#


Good Morning/Good Afternoon /Good Evening Guys.. Today I will show you a method which will help you to generate random password dynamically.. It will be helpful to use this code when you want to give your users a Random Password Upon Registration or during Forget Your Password Action..

So Here is the Code Snippet for that:

Design Part:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Generate Random Password</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Generate Password" /><br />
        <br />
        <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>&nbsp;</div>
    </form>
</body>
</html>

Code-Behind:


    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text="Your New Password is:"+GeneratePassword(8);
    }

    public string GeneratePassword(int PwdLength)
    {
   string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
   Random rndNum = new Random();
   char[] chars = new char[PwdLength];
   int strLength = _allowedChars.Length;
   for (int i = 0; i <= PwdLength - 1; i++) {
  chars[i] = _allowedChars[Convert.ToInt32(Math.Floor((_allowedChars.Length) * rndNum.NextDouble()))];
   }
   return new string(chars);
    }

Encrypt and Decrypt Connection String Section in Web.Config


Encrypt and Decrypt Connection String Section in Web.Config


Sometime during Development of a Project we may need the help of other Developer to review or Modify our codes. As Such We dont want to give the developer the confidential Specification of the Project.. So The first thing which come to our mind is how to protect the connection string from the other developer..

So Here  is a technique to achieve the same:

In the Web.Config file we found <connectionStrings> section that enable us to add ConnectionStrings


<connectionStrings>
  <add name="ConnectionString" connectionString="Provider=SQLNCLI10.1;Data 
Source=My-pc\sqlexpress;Integrated Security=SSPI;Initial Catalog=Northwind"
   providerName="System.Data.OleDb" />
 </connectionStrings>

Next is the Encryption and Decryption of the above Section..You can Use the following code snippet to get the desired result:

Note: Dont Forget to add System.Web.Configuration Namespace...


protected void Encryption(bool EncryptoValue)
    {
        Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
        ConfigurationSection sec = config.GetSection("connectionStrings");
        if (EncryptoValue == true)
        {
            sec.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
        }
        else
        {
            sec.SectionInformation.UnprotectSection();
        }
        config.Save();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Encryption(true);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Encryption(false);
    }

Read CSV File Using C# ASP.Net


Read CSV File Using C# ASP.Net


In this article we will see how we can fetch data from a CSV file and can export it to a DataReader so that we can show it row by row.. Here is how it works:

First you have to declare two string variables and their properies for store directory and filename of csv file which you want to extract data.


private string dirCSV;
private string fileNevCSV;

public string FileNevCSV
{
 get{return fileNevCSV;}
 set{fileNevCSV=value;}
}

public string dirCSV
{
 get{return dirCSV;}
 set{dirCSV=value;}
}

In the second step connect to the data source and fill it to the dataset.


public DataSet loadCVS(int noofrows)
        {
            DataSet ds = new DataSet();
            try
            {
                // Creates and opens an ODBC connection
                string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + this.dirCSV.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False";
                string sql_select;
                OdbcConnection conn;
                conn = new OdbcConnection(strConnString.Trim());
                conn.Open();

                //Creates the select command text
                if (noofrows == -1)
                {
                    sql_select = "select * from [" + this.FileNevCSV.Trim() + "]";
                }
                else
                {
                    sql_select = "select top " + noofrows + " * from [" + this.FileNevCSV.Trim() + "]";
                }

                //Creates the data adapter
                OdbcDataAdapter obj_oledb_da = new OdbcDataAdapter(sql_select, conn);

                //Fills dataset with the records from CSV file
                obj_oledb_da.Fill(ds, "csv");

                //closes the connection
                conn.Close();
            }

            catch (Exception e) //Error
            {

            }
            return ds;

        }

In the third step extract data to DataTable from generated DataSet.


this.dirCSV = "file path";
this.fileNevCSV ="file name";
DataSet ds = loadCVS(-1);
DataTable table = ds.Tables[0];

foreach (DataRow row in table.Rows)
{
//iterate through the DataTable.
}

References:

http://wiki.asp.net/page.aspx/1570/read-csv-file-using-c/

Wednesday, 20 February 2013

Staying Late @ Office


Staying Late @ Office



It's half past 8 in the office but the lights are still on...

PCs still running, coffee machines still buzzing...

and who's at work? Most of them??? Take a closer look...

All or most specimens are ??-something male species of the human race...

Look closer... again all or most of them are bachelors...

and why are they sitting late? Working hard? No way!!!

Any guesses???

Let's ask one of them...

Here's what he says... "What's there 2 do after going home... here we get to surf, AC, phone, food, coffee.. that is why I am working late... importantly no bossssssss!!!!!!!!!!!

This is the scene in most research centers and software companies and other off-shore offices.
Bachelors "time-passing" during late hours in the office just bcoz they say they've nothing else to do...
Now what r the consequences... read on...

"Working"(for the record only) late hours soon becomes part of the institute or company culture.
With bosses more than eager to provide support to those "working" late in the form of taxi vouchers, food vouchers and of course good feedback,(oh, he's a hard worker... goes home only to change..!!).They aren't helping things too... To hell with bosses who don't understand the difference between "sitting" late and "working" late!!!

Very soon, the boss start expecting all employees to put in extra working hours.
So, My dear Bachelors let me tell you, life changes when u get married and start having a family... office is no longer a priority, family is... and that's when the problem starts... becoz u start having commitments at home too.

For your boss, the earlier "hardworking" guy suddenly seems to become a "early leaver" even if u leave an hour after regular time... after doing the same amount of work.

People leaving on time after doing their tasks for the day are labeled as work-shirkers...

Girls who thankfully always (its changing nowadays... though) leave on time are labeled as "not up to it". All the while, the bachelors pat their own backs and carry on "working" not realizing that they r spoiling the work culture at their own place and never realize that they wuld have to regret at one point of time.

*So what's the moral of the story?? *

* Very clear, LEAVE ON TIME!!!

* Never put in extra time " *unless really needed *"

* Don't stay back un-necessarily and spoil your company work culture which will in turn cause inconvenience to you and your colleagues. There are hundred other things to do in the evening..

Learn music...
Learn a foreign language...
try a sport... TT, cricket.........

importantly Get a girl friend or gal friend, take him/her around town(moral of d story) ...

* And for heaven's sake net cafe rates have dropped to an all-time low (plus, no fire-walls) and try cooking for a change.

Take a tip from the Smirnoff ad: *"Life's calling, where are you??"*




Other Must Read articles:

 



Tuesday, 19 February 2013

Refresh Page/Browser Automatically after a Particular Time Period V


Refresh Page/Browser Automatically after a Particular Time Period V


If you want to refresh a web page using a mouse click then you can use following code:


<a href="javascript:location.reload(true)">Refresh Page</a>

You can also use JavaScript to refresh the page automatically after a given time period. Following is the example which would refresh this page after every 5 seconds. You can change this time as per your requirement.


<html>
<head>
<script type="text/JavaScript">
<!--
function AutoRefresh( t ) {
 setTimeout("location.reload(true);", t);
}
//   -->
</script>
</head>
<body onload="JavaScript:AutoRefresh(5000);">
<p>This page will refresh every 5 seconds.</p>
</body>
</html>

Refresh Page/Browser Automatically after a Particular Time Period IV


Refresh Page/Browser Automatically after a Particular Time Period IV


Browser Refresh Every 10 Seconds..

Design Part:


<!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>Browser Auto Refresh</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
    </div>
    </form>
</body>
</html>

Code-Behind: 


    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text=DateTime.Now.ToShortTimeString();
        Response.AppendHeader("Refresh", "10");
    }

Refresh Page/Browser Automatically after a Particular Time Period III


Refresh Page/Browser Automatically after a Particular Time Period III


Use the following Code to Refresh Your Page/Browser Every 10 Seconds after Page Load...

Design Part:

<!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>Browser Refresh</title>
    <meta http-equiv="refresh" content="10">
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h3>Browser is Refreshing Every 10 Seconds.. Notice the Time..</h3>
    <br />
    <br />
        <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label></div>
    </form>
</body>
</html>

Code-Behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text=DateTime.Now.ToShortTimeString();
    }


You Can Also Redirect the Current Page to another URL after a Certain Time Period:


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Browser Refresh</title>
    <meta http-equiv="refresh" content="15;url=http://www.dotnetvishal.com">
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h3>This Page will be redirected to www.dotnetvishal.com in 15 seconds</h3>
    </div>
    </form>
</body>
</html>

Refresh Page/Browser Automatically after a Particular Time Period II


Refresh Page/Browser Automatically after a Particular Time Period II


Use the following Code to Refresh Your Page/Browser Every 10 Seconds after Page Load...

Design Part:


<!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>Refresh Browser on Button Click</title>
    <meta id="refreshRate" runat="server" http-equiv="refresh" content=""/>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
        <br />
        <br />
        <asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
    </div>
    </form>
</body>
</html>

Code-Behind:


    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text="The Time Now is:"+DateTime.Now.ToShortTimeString();
        refreshRate.Content = "10";
    }

Alternatively, We can start the Page Refreshing Every 10 Seconds after the Button Click .. For that We have to Comment the Event in the Page Load Event and put the Same Code in the Button Click Event:


    protected void Page_Load(object sender, EventArgs e)
    {
        //Label1.Text="The Time Now is:"+DateTime.Now.ToShortTimeString();
        //refreshRate.Content = "10";
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        refreshRate.Content = "10";
        Label1.Text="The Time Now is:"+DateTime.Now.ToShortTimeString();
    }

Refresh Page/Browser Automatically after a Particular Time Period


Refresh Page/Browser Automatically after a Particular Time Period


So This is my first article in this category.. I will discuss many more ways to achieve the same functionality in my coming Articles.. I am refreshing the Browser/Page every 10 Seconds..

Design Part:


<!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>Auto Refresh Browser</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>The Browser Refresh Every 10 Seconds.. Notice the Time...</h3>
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label></div>
        <meta http-equiv="Refresh" content="10" />  
    </form>
</body>
</html>

Code-Behind:


    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text="The Time Now is:"+DateTime.Now.ToShortTimeString();
    }

Monday, 18 February 2013

Check whether a Particular Word is Available in a URL or Not


Check whether a Particular Word is Available in a URL or Not


You can Use the following Code to check whether a Particular Word is available in a Particular URL or not...


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckViewSource.aspx.cs" ValidateRequest="false" Inherits="CheckViewSource" %>

<!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>Check ViewSource</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Enter URL:"></asp:Label>
        <asp:TextBox ID="txtURL" runat="server" Height="20px" Width="300px"></asp:TextBox><br />
        <br />
        <asp:Button ID="btnSource" runat="server" OnClick="btnSource_Click" Text="Check Source" /><br />
        <br />
        <asp:TextBox ID="txtSource" runat="server" Height="300px" TextMode="MultiLine" Width="600px"></asp:TextBox>
        <br />
        <br />
        <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Find this Word in the Above Source:"></asp:Label>
        <asp:TextBox ID="txtCheck" runat="server"></asp:TextBox><br />
        <br />
        <asp:Button ID="btnCheck" runat="server" OnClick="btnCheck_Click" Text="Check Word" /><br />
        <br />
        <asp:Label ID="lblDisplay" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label><br />
        <br />
    
    </div>
    </form>
</body>
</html>

and in the Code-Behind:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net; 
using System.IO;

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

    }
    protected void btnSource_Click(object sender, EventArgs e)
    {          
            string URL=txtURL.Text;
            // Create a request for the URL.
            WebRequest request = WebRequest.Create(URL);
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // Display the status.
            Console.WriteLine (response.StatusDescription);
            // Get the stream containing content returned by the server.
            Stream ds= response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader rd= new StreamReader (ds);
            // Read the content. 
            string responser = rd.ReadToEnd ();
            txtSource.Text=responser;
    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        string URLSource=Server.HtmlEncode(txtSource.Text);
        string Check=txtCheck.Text;
        bool val=URLSource.Contains(Check);
        if(val==true)
        {
           lblDisplay.Text="The Word: **"+txtCheck.Text+"** is present in the above Source";
        }
        else
        {
           lblDisplay.Text="The Word: **"+txtCheck.Text+"** is not present in the above Source";
        }
    }
}

Check the View Source of a URL


Check the View Source of a URL


Use the following Code to get the viewsource of a particular URL Address:

Include these namespaces first:

using System.Net;
using System.IO;

Then Include two textboxes.. One for entering the URL and another for Showing the View Source.. Add a button to to make things Work:


    protected void btnSource_Click(object sender, EventArgs e)
    {          
            string URL=txtURL.Text;
            // Create a request for the URL.
            WebRequest request = WebRequest.Create(URL);
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // Display the status.
            Console.WriteLine (response.StatusDescription);
            // Get the stream containing content returned by the server.
            Stream ds= response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader rd= new StreamReader (ds);
            // Read the content. 
            string responser = rd.ReadToEnd ();
            txtSource.Text=responser;
    }


Saturday, 16 February 2013

Allow Only Numbers in Textbox Using Javascript - II [Cross Browser Compatible]

Allow Only Numbers in Textbox Using Javascript -II [Cross Browser Compatible]


I have already written a similar Post related to the above requirement over here:


So Here I am with another method with Alert Functionality and which is Cross Browser Compatible:


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Allow Only Numbers</title>
    
   <SCRIPT language=Javascript>
      <!--
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
         {
            alert("Please Enter Only Numbers!");
            return false;
         }
         else
         {
         return true;
         }
      }
      //-->
   </SCRIPT>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
   <asp:TextBox ID="txt_maxage" Onkeypress="return isNumberKey(event)" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

Friday, 15 February 2013

Embedding Windows Media Player in IE


Embedding Windows Media Player in IE


So Here I am with another Post.. This time how to integrate Windows Media Player in Internet Explorer using ASP.Net.. 

Use the following HTML Code in your .aspx file and include a .wmv Video in your root directory and rename it as Song.wmv...

Note: It will work only in IE


<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<script language=jscript FOR = VIDEO EVENT = playStateChange(NewState) type=text/jscript>
// Test for the player current state, display a message for each.
switch (NewState)
{
case 1:
alert('Stopped');
break;

case 2:
alert('Paused');
break;

case 3:
alert('Playing');
break;

// Other cases go here.
default:
//alert('Your Default Message.');
}
</script> 

<title>Embedd Windows Media Player</title>

</head>

<body>
    <form id="form1" runat="server">
    <div>   
    <object id="VIDEO" width="900px" height="600px" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">
    <param name="URL" value="Song.wmv" />
    <param name="SendPlayStateChangeEvents" value="True" />
    <param name="AutoStart" value="True" />
    <param name="uiMode" value="none" />
    <param name="windowlessVideo" value="True" />
    <param name="stretchToFit" value="true" />
    </object>
    </div>
    </form>
</body>

</html>

Wednesday, 13 February 2013

Some Hidden Goodies @ Asp.Net and MSDN Forums


Some Hidden Goodies @ Asp.Net and MSDN Forums


Here is a list of some URLs @ Asp.net and MSDN Forums very few People know of.

10000 PageViews in 105 Days from more than 95 Countries


10000 PageViews in 105 Days from more than 95 Countries


Well this time I want to say something to you all. I started this blog around 14th October,2012 just with an idea of sharing my knowledge and experience with the Community Members. I gathered some codes and created some new one.. But the sole intention was to give you guys the best Code Snippets available in the market. So I would not take the entire credit for this Website as there are numerous people involved in making this site either Knowingly or Unknowingly. 

About Me:

Well I am a graduate in Information Technology (B-Tech-IT) 2011 Batch.. Pretty Junior in comparison with other technical people out there in the market. But In my view it doesnt matter at all. Age is not what should restrict a person from helping others. I know there might be millions of people who are technically much more superior than me in the industry. But this is not what it all counts. They know but they cant share. I know and I share.. This is the difference.

When I  was in my college days My teacher would laugh at me as I didnt know simple C and OOPs concept.. That is the gap in the college education and practical knowledge. They would be amazed if they ever come to know that I am in the industry and doing good as well. The thing is Practical Knowledge really matters.. You cant learn everything with theory.. I never attended any tuition or additional classes for programming.I learn what Industry taught me. But I would like to thanks the Moderators and Developers in the ASP.Net forums which has become the Mecca for my learning.. I learnt most of my programming skills from there itself..

There are many people involved to make me what I am today.. I would like to name few of them.. First of all I would like to thanks Mr.Nitesh Maheswari,MD,Orange Softech Pvt. Ltd., for giving me the opportunity to step into this industry. Then Miss Jyoti Mahalik who was my first trainer @ Orange Softech. I would also like to thank Ashok Dhal, Sanchita Rano and Kirtika Pandey who were training and shaping my skills at the beginning of my career.From ASP.Net Forums I would like to thanks Kris van der Mast, Rami Vemula, Ruchira Chanaka Gamage, Suwandi oned gk, Rajneesh Verma,Ignat Andrei, Vincent Maverick and many more. I would also like to thanks Mr. Abhishek Sur for making me a part of Kolkata Geeks Community.

Finally I would like to thanks Mithilesh Kumar Singh,TL,TTL who is a role model in my life and my childhood teacher Md. Furquan Alam and last but not the least my Mom,Dad and Brother for supporting me in my worst times.

Today I work as Web Developer@Tata Technologies, Jamshedpur. Apart from this I am a regular Answerer in Microsoft ASP.NET Forums. I currently possess 200th Rank in the All Time Top Answerer Section of the forums with 11,000+ points. If  I cross 15000 points points within this year; I would be second youngest Community Member to be in the prestigious All-Star Category..

You can find me here:
 


Finally I would like to share the statistics of this Website from 1st November,2012 to Present:







And Here is the list of regular visitors of Our site across the Globe:









From Future Perspective I have thought a lot about this Website.. In the coming days I would improve the layout of the site.. The codes would become more clearer. I would give the download facility to download the Working Examples. Would integrate Video and Gif tutorials with each Code Snippet. Finally Would start a beginner tutorial guides with Video and Gif Tutorial. Please Stay with us for these goodies...



Tuesday, 12 February 2013

Alert User on Browser Navigation Using Javascript


Alert User on Browser Navigation Using Javascript


We always come into the situation when we have to alert User before navigating to another page or during Back Button Press in order to ensure that the data present in the current page is not lost suddenly..

Here is how to achieve this.. Works on Firefox and Internet Explorer..


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">

    <title>Capture Browser Navigation</title>
   
    <script type="text/javascript">
    function goodbye(e) {
    if(!e) e = window.event;
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    e.cancelBubble = true;
    e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog

    //e.stopPropagation works in Firefox.
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
    }
    }
    window.onbeforeunload=goodbye;
    
    </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <a href="http://google.com">click here</a>
        <input type="submit" value="Button" />
    </div>
    </form>
</body>
</html>

Opening Office Documents in Iframe within Browser


Opening Office Documents in Iframe within Browser


If a Word, Excel or PowerPoint document (.doc, .docx, .xls, .xlsx, .ppt, .pptx formats) hosted on the web is accessed through a browser, it typically asks if you want to open or save the file. You can then view it if you have MS Office or the corresponding Word/Excel/PowerPoint Viewer (freely downloadable) installed.

To increase the reach of the content in those Office documents among non-PC/Mac users, you can use Google Docs Viewer to embed them within a web page. Google Docs Viewer now supports 12 new file formats including Excel & Powerpoint.

You can generate the HTML tag for the embedded viewer that you can paste into your own web page from the home page of Google Docs Viewer. You can alternatively use the example below to append the URL of the Office document to the url querystring of the service -


<iframe src="http://docs.google.com/viewer?url=http%3A%2F%2Fdocs.google.com%2Fviewer%3Furl%3

Dhttp%253A%252F%252Flabs.google.com%252Fpapers%252F

bigtable-osdi06.pdf&embedded=true" style="border: none;" 

height="780" width="600">

</iframe>



Sunday, 10 February 2013

Check Regex Match Programmaticaly Using C#


Check Regex Match Programmaticaly Using C#


We always get into situation when we have to check the validation of the particular string using regex...
We have a separate validation control for this ie., Regular Expression Validator.. But It is not always feasible to use it.. So Here I am with an alternative..

I am going to validate the date in mm/dd/yyyy format using Regex Programmatically:


string date="02/28/2013";
Regex regex = new Regex(@"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$");
Match match = regex.Match(date);
if (match.Success)
{
// Your Insert Code
}
else
{
// Show Error Message
}

Thursday, 7 February 2013

Alert User on Browser/Tab Close Event [Cross Browser Compatible]


Alert User on Browser/Tab Close Event [Cross Browser Compatible]


This is how you can alert user on the close of the browser/Tab Close Event.. 

Create a javascript file by the name check_browser_close.js  in the root directory of the folder with the following content:


// JScript File
/**
 * This javascript file checks for the brower/browser tab action.
 * It is based on the file menstioned by Daniel Melo.
 * Reference: http://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed
 */
var validNavigation = false;

function wireUpEvents() {
  /**
   * For a list of events that triggers onbeforeunload on IE
   * check http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx
   *
   * onbeforeunload for IE and chrome
   * check http://stackoverflow.com/questions/1802930/setting-onbeforeunload-on-body-element-in-chrome-and-ie-using-jquery
   */
  var dont_confirm_leave = 0; //set dont_confirm_leave to 1 when you want the user to be able to leave withou confirmation
  var leave_message = 'You sure you want to leave?'
  function goodbye(e) {
    if (!validNavigation) {
      if (dont_confirm_leave!==1) {
        if(!e) e = window.event;
        //e.cancelBubble is supported by IE - this will kill the bubbling process.
        e.cancelBubble = true;
        e.returnValue = leave_message;
        //e.stopPropagation works in Firefox.
        if (e.stopPropagation) {
          e.stopPropagation();
          e.preventDefault();
        }
        //return works for Chrome and Safari
        return leave_message;
      }
    }
  }
  window.onbeforeunload=goodbye;

  // Attach the event keypress to exclude the F5 refresh
  $('document').bind('keypress', function(e) {
    if (e.keyCode == 116){
      validNavigation = true;
    }
  });

  // Attach the event click for all links in the page
  $("a").bind("click", function() {
    validNavigation = true;
  });

  // Attach the event submit for all forms in the page
  $("form").bind("submit", function() {
    validNavigation = true;
  });

  // Attach the event click for all inputs in the page
  $("input[type=submit]").bind("click", function() {
    validNavigation = true;
  });

}

// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {
  wireUpEvents();
});

Then Call this file in the page in which you want the alert functionality as follows:


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Browser Close</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
     <script type="text/javascript" src="check_browser_close.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html> 

Find Coordinates of Image Using Javascript


Find Coordinates of Image Using Javascript


Today I came across this problem via a Post in ASP.Net Forums.. Well I found a solution to this by a Code Snippet by Rion Williams. I try to reproduce the same on my system and Voila It Worked!!

So I am sharing the same code with you.. Hope It helps someone:


<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Find Coordinates</title>

   

 <script type='text/javascript'>

  function getMouseXY(e) {

      document.getElementById('x').value = e.pageX || event.clientX ;

      document.getElementById('y').value = e.pageY || event.clientY;

      return true;

  }

</script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

      <img src="new.jpg" onmousemove='return  getMouseXY(event);' />

  <hr />

  X:

  <input id='x' />

  Y:

  <input id='y' />

    </div>

    </form>

</body>

</html>


Note : Here new.jpg is the image i am using in my project.. You can change the source according to the image you are using..

Demo:


Saturday, 2 February 2013

Kolkata Geeks .Net Developer's Meet


Kolkata Geeks .Net Developer's Meet


Today I got the chance to attend the first Developer's Meet of my life.. I would like to thank Mr. Abhishek Sur for this Golden Opportunity.. Today We have a discussion about C# internals - Delegates, Async, Iterators, Looping etc etc. The Session was quite fantastic and the level of participation of the Users were Quite good..

Note: If anyone wants to participate for the next meet please let me know.. The Meet Usually takes place twice or once in a month in Kolkata.. Participation is Free of Cost (For This I would personally like to thanks Mr. Sur )

Here are some of the moments which I captured during the session..
[Sorry For the Quality of Images ]














Friday, 1 February 2013

MaxLength in Multiline Textbox ASP.NET


MaxLength in Multiline Textbox ASP.NET


Well Yesterday I came across this question.. So I want to share the solution with all the Community Members. Special Thanks to VINZ for providing the nice solution:



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>MultiLine TextBox MaxLength</title>
   
        <script type="text/javascript" language="javascript">

        function ValidateLimit(obj, maxchar) {
            if (this.id) obj = this;
            var remaningChar = maxchar - obj.value.length;
            var lb = document.getElementById('<%= Label1.ClientID %>');
            lb.innerHTML = remaningChar;


            if (remaningChar <= 0) {
                obj.value = obj.value.substring(maxchar, 0);
                lb.innerHTML = "0";
            }
        }


    </script>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" onkeyup="ValidateLimit(this,140)">   </asp:TextBox> <br />
    Remaining char: <asp:Label ID="Label1" runat="server" Text="140"></asp:Label>

    </div>
    </form>
</body>
</html>

Apart from this here are few other alternatives:

Using Javascript
http://www.codeproject.com/Tips/82655/ASP-NET-Limit-number-of-characters-in-TextBox-cont

Using Jquery
http://www.dotnetcurry.com/ShowArticle.aspx?ID=396
http://www.aspsnippets.com/Articles/Limit-number-of-characters-in-an-ASPNet-Multiline-TextBox-using-jQuery.aspx

Interview with Vincent Maverick (S) Durano [Vinz]


Interview with Vincent Maverick (S) Durano [Vinz]

 




Vincent Maverick (S) Durano also known as Vinz @ ASP.Net Forums is current MVP and one of the Moderators of codeasp.net.

He works as Technical Lead and Web Developer in a Research and Development company.. He is basically from Philippines.. One of the most prodigious Programmer I have ever met..

He has over 6 year of professional experience specializing mainly on Microsoft technologies, including .NET, C#,VB.NET, ASP.NET (WebForms, MVC), WebPart Framework,ASP.NET AJAX, L2S, EF, WCF, Web Services, TFS, and Sql Server.


Here are the glimpses of the Interview:

Q1.Tell Something About Yourself?

I work as a Technical Lead and a Web Developer, focusing mainly in Microsoft technology stack. I've been an MVP since 2009 for ASP.NET/IIS, Microsoft Influencer and a regular contributor at CodeASP.NET (www.codeasp.net) in which I also moderate, Local Microsoft Community (msforums.ph), AspSnippets (www.aspforums.net) but more often at the official Microsoft ASP.NET community site (www.asp.net) where I became one of the All-Time Top Answerer with ALL-STAR recognition level. I am also one of the Quiz Masters at www.beyondrelational.com, one of the wgeekswithblogs influencers and one of the article authors at HighOnConding, CodeASP.net and ASPSnippets.

Q2.What do you do?

I develop windows, webservice and web applications. I also design frameworks for web solutions and building some open source tools for webforms.

Q3.What is your Development Environment?

I'm using Visual Studio 2010 and 2012 with Web and C# configuration setup.

Q4.What is your Area of Interest?

Web development and architechting frameworks.

Q5.How did you get started Programming?

My exploration into programming began at the age of 15;Turbo PASCAL, C, C++, JAVA, VB6,Flash and a variety of other equally obscure acronyms, mainly as a hobby. After several detours, I am here today on the VB.NET to C# channel. I now work on ASP.NET+C#+EF+LINQ+AJAX+
JQuery+CSS, which go together like coffee crumble ice cream.

Q6.How has the developer Community Influenced your coding?

I can definitely say that the developer community helped me to become a better developer. I myself is a self taught guy. I remember when I got my first job that I've been assigned to develop solutions using .NET and it scares me because I don't have any experience in the framework and worst not really familiar about web and how stuff works in the stateless world. I struggled alot during those times and by the help of the technical community I was able to understand the basics and learned something each day.

Q7.Tell about your best and worst experience in life?

Q8. Your Role Model/Programmer?

There's so many of them. Most of them are MVPs and Microsoft folks.

Q9.Your Favourite Websites and Blogs?

I have lots of favorite websites but most of the time I hangout at http://forums.asp.net and http://codeasp.net/ by helping out developers from all over the world find solution to their problems . And at the same time learn something new from other developers in the community.

Q10.Your Hobbies?

Code, code and code.

Q11.Apart from Programming what do you do?

Travel, playing guitar and hangout with the band. And oh did I mentioned beer? ;)

Q12. If you were not a programmer what would be you?

An artist. Actually I wrote a blog post about it here: http://geekswithblogs.net/dotNETvinz/archive/2012/02/03/what-will-you-be-if-computers-werent-in-existence.aspx

Q13.Your Favourite Holiday Spot?

Beach

Q14.Advice to New Programmers?

three things - "READ, DO and LEARN".

For starters, you may also want to read on: http://geekswithblogs.net/dotNETvinz/archive/2010/02/26/learning-asp.net-where-to-begin.aspx

back to top