Thursday 21 March 2013

Autocomplete textbox in c# windows application...


 take a form with a textbox named txtname. Here I am fetching names from the database.



public partial class Form9 : Form
{ public string strConnection = ConfigurationManager.ConnectionStrings["test1"].ConnectionString;
 AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
public Form9()
{
InitializeComponent();
}private void Form9_Load(object sender, EventArgs e)
{OdbcDataReader dReader;
OdbcConnection conn = new
OdbcConnection();
conn.ConnectionString = strConnection;OdbcCommand cmd = new OdbcCommand();
cmd.Connection = conn;cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select distinct name from sample order by name";
conn.Open();
dReader = cmd.ExecuteReader();if (dReader.HasRows == true)
{while (dReader.Read())
namesCollection.Add(dReader["name"].ToString());
}else
{MessageBox.Show("Data not found");
}
dReader.Close();txtname.AutoCompleteMode = AutoCompleteMode.Suggest;
txtname.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtname.AutoCompleteCustomSource = namesCollection;
}
}
Google

Wednesday 20 March 2013

Printing using C# for Windows Application

Printing using C# for Windows Application


A PrintDialog control is used to open the Windows Print Dialog and let user select the printer, set printer and paper properties and print a file. A typical Open File Dialog looks like Figure 1 where you select a printer from available printers, set printer properties, set print range, number of pages and copies and so on. Clicking on OK button sends the document to the printer.






Creating a PrintDialog
We can create a PrintDialog at design-time as well as at run-time.

Design-time
To create a PrintDialog control at design-time, you simply drag and drop a PrintDialog control from Toolbox to a Form in Visual Studio. After you drag and drop a PrintDialog on a Form, the PrintDialog looks like Figure 2.

 

Run-time

Creating a PrintDialog control at run-time is simple. First step is to create an instance of PrintDialog class and then call the ShowDialog method. The following code snippet creates a PrintDialog control.
PrintDialog PrintDialog1 = new PrintDialog();
PrintDialog1.ShowDialog();

Printing Documents
PrintDocument object represents a document to be printed. Once a PrintDocument is created, we can set the Document property of PrintDialog as this document. After that we can also set other properties. The following code snippet creates a PrintDialog and sends some text to a printer.

private void PrintButton_Click(object sender, EventArgs e)
{
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = "Print Document";
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
//Call ShowDialog
if (printDlg.ShowDialog() == DialogResult.OK)
printDoc.Print();
}


Summary

A PrintDialog control allows users to launch Windows Open File Dialog and let them select files. In this article, we discussed how to use a Windows Open File Dialog and set its properties in a Windows Forms application.

And this post was originally posted by Ashutosh jain...

Javascript to detect mobile browser

Javascript to detect mobile browser....

put this javascript on page and it will detect that the device is mobile,tablet and ipad or not.


<script type="text/javascript">

var mobile = function(){
return {
detect:function(){
var uagent = navigator.userAgent.toLowerCase();
var list = this.mobiles;
var ismobile = false;
for(var d=0;d<list.length;d+=1){
if(uagent.indexOf(list[d])!=-1){
ismobile = true;
}
}
return ismobile;
},
mobiles:[
"midp","240x320","blackberry","netfront","nokia","panasonic",
"portalmmm","sharp","sie-","sonyericsson","symbian",
"windows ce","benq","mda","mot-","opera mini",
"philips","pocket pc","sagem","samsung","sda",
"sgh-","vodafone","xda","palm","iphone",
"ipod","android"
]
};
}();

if(mobile.detect()){
  alert(you have opened page in mobile, tablet or ipad.);
                   //following line is to open mobile version of page.
window.location = "http://www.test.com/mobile"
  }else{
                    alert('You are using a desktop browser to view this page..');
}

</script>

How to Read XML file in c#

How to Read XML file in c#

here i am first showing you an xml which we are going to read.


<?xml version="1.0" encoding="utf-8" ?>

<root>

<customer id="1">

<fname>Tahir</fname>
<lname>Nasir</lname>
    <address>3 Kingston Road, Toronto, Canada</address>
</customer>
<customer id="2">
<fname>Atif</fname>
<lname>Ramu</lname>
<address>983 Damujs park</address>
</customer>
<customer id="3">
    <fname>Bill</fname>
    <lname>Horton</lname>
    <address>9 cars diver</address>
</customer>
<customer id="4">
    <fname>Kajoor</fname>
    <lname>Tree</lname>
    <address>1 New homes drive</address>
</customer>
<customer id="5">
<fname>Andy</fname>
<lname>Patel</lname>
<address>786 Ahmadiyya Ave, Maple, ON L6A 3A2</address>
</customer>
</root>
Above is an xml and we have saved it as mycompany.xml in the root directory...
and here is the code to read xml nodes names dynamically and then the method to read xml nodes.


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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /* below is code to read  node names */

        XmlTextReader reader = new XmlTextReader(Server.MapPath("mycompany.xml"));

        reader.WhitespaceHandling = WhitespaceHandling.None;
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(reader);


        foreach (System.Xml.XmlNode node in xmlDoc.SelectNodes("root/customer"))
        {
            List<string> nodeNames = new List<string>();
            foreach (System.Xml.XmlNode child in node.ChildNodes)
            {
                if (!nodeNames.Contains(child.Name))
                {
                    ltrblog.Text += child.Name;
                    ltrblog.Text += "/";
                    nodeNames.Add(child.Name);
                }
            }
            ltrblog.Text += "<br/>";
        }

         /* below is method call to read node values */

        ProcessNodes(xmlDoc.SelectNodes("root/customer"));
    }

    public void ProcessNodes(XmlNodeList nodelist)
    {
        ltrblog.Text += "<br/><br/>";
     

            foreach (XmlNode x in nodelist)
            {
                ltrblog.Text += x.SelectSingleNode("fname") != null ? x.SelectSingleNode("fname").InnerText : "";
                ltrblog.Text += "<br/>";
                ltrblog.Text += x.SelectSingleNode("lname") != null ? x.SelectSingleNode("lname").InnerText : "";
                ltrblog.Text += "<br/>";
                ltrblog.Text += x.SelectSingleNode("address") != null ? x.SelectSingleNode("address").InnerText : "";
                ltrblog.Text += "<br/>";
            }

        
    }
}

and its out put is labled in literal named as ltrblog...
so out put will be as below.

Monday 18 March 2013

Scrolling likebox at bottom of the page

 Scrolling facebook likebox


How to create scrolling facebook like box as you can see on page.

Below is html page that you can use to create scrolling facebook like box at the bottom of the page.

 
//for maximize view of box
 
<div id="divfacebook" style="background-color: white; bottom: 10px; bottom: 5px; display: none; height: 273px; margin-bottom: 5px; padding: 2px; position: fixed; right: 0px; width: 300px; z-index: 999;">

 
//anchor tag for minimize button

<a href="javascript:void(0);" onclick="javascript:CloseDiv();" style="background: #3B5998; color: white; display: inline-block; font-family: Arial; font-size: 12px; font-weight: bold; height: 16px; padding: 3px; position: absolute; right: 10px; text-align: center; text-decoration: none; top: 15px; width: 12px;">-</a>

//generate iframe from facebook likebox plugin http://developers.facebook.com/docs/reference/plugins/like-box/ and untick show stream checkbox

       <iframe allowtransparency="true" frameborder="0" scrolling="no" src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FBridzetech&amp;width=292&amp;height=258&amp;show_faces=true&amp;colorscheme=light&amp;stream=false&amp;border_color&amp;header=false&amp;appId=140536862789242" style="border: none; height: 258px; overflow: hidden; width: 292px;"></iframe>
    </div>


//for minimize version of box

<div id="divshowfacebook" style="background-color: white; border: 1px solid #315C99; bottom: 5px; display: none; height: 57px; left: 0px; margin-left: 5px; padding: 12px; position: fixed; width: 198px; z-index: 999;">

//generate iframe from facebook likebox plugin http://developers.facebook.com/docs/reference/plugins/like-box/ and untick show stream checkbox and untick show faces.

<iframe allowtransparency="true" frameborder="0" scrolling="no" src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FBridzetech&amp;width=292&amp;height=62&amp;show_faces=false&amp;colorscheme=light&amp;stream=false&amp;border_color&amp;header=false&amp;appId=140536862789242" style="border: none; height: 62px; overflow: hidden; width: 292px;"></iframe>
//anchor tag for maximize button

         <a href="javascript:void(0);" onclick="javascript:ShowFacebook();" style="background: #3B5998; color: white; display: inline-block; font-family: Arial; font-size: 12px; font-weight: bold; height: 11px; padding: 3px; position: absolute; right: 9px; text-align: center; text-decoration: none; top: 8px; width: 9px;">+</a>
    </div>
<input id="hidflag" type="hidden" value="move" />


//javascript for scrolling box
 
    <script language="javascript" type="text/javascript">
        var flag = document.getElementById('hidflag').value;
        var bwidth;
        $(document).ready(function () {
            viewfacebox();
       });
        function viewfacebox() {
            if (typeof window.innerWidth != 'undefined') {
                bwidth = window.innerWidth
            }

            // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
            else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
                bwidth = document.documentElement.clientWidth
            }

            // older versions of IE

            else {
                bwidth = document.getElementsByTagName('body')[0].clientWidths
            }
            bwidth = bwidth - 320;
            if (flag == "move") {
                setTimeout("Move();", 5000);
                setTimeout("Change();", 12000);

            }
            else {
                DisplaySmallBox();
                Change();
            }
        }
       
        function Move() {           
            document.getElementById("divfacebook").style.display = "";
            $(function () {
                $('#divfacebook').stop().animate({ 'right': 0 }, 2000);
                $('#divfacebook').stop().animate({ 'right': bwidth }, 5500, function () {
                });
            });
        }

        function Change() {
            document.getElementById('divfacebook').style.left = '';
            document.getElementById('divfacebook').style.left = "0px";
        }
        function CloseDiv() {
            document.getElementById("divfacebook").style.display = "none";
            document.getElementById("divshowfacebook").style.display = "";
        }
        function ShowFacebook() {
            document.getElementById("divfacebook").style.display = "";
            document.getElementById("divshowfacebook").style.display = "none";
        }
        function DisplaySmallBox() {
            document.getElementById("divfacebook").style.display = "none";
            document.getElementById("divshowfacebook").style.display = "";
        }   
           
    </script>


How to make Ajax call with post parameters


first include any jquery min file in your page and then on document.ready function or on any function of javascript you can make a ajax call like below. i am writing it on document.ready event.


$(document).ready(function () {
 $.ajax({
        type: "POST",
        url: "HandleWebRequests.aspx", //here you can use handler also ...
        data: "{email:bridzetech@gmail.com&name=bridzetech}",
        success: function (response) {
            alert(response);
        },
        error: function (response) {
            \\write code if error is returned.     
            alert(response);
        }
    });
});
 
 
and you can access these parameters on page or handler using request.form element.
like as below. i am accessing these parameters on aspx page using c#.

 string name = Convert.ToString(Request.Form["name"]);
 string email= Convert.ToString(Request.Form["email"]);
 

Sunday 17 March 2013


"  Click event of facebook like button...  "

 
How to know user has clicked on like button ??
ans is save below html file and run in your browser. 


<!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" xmlns:fb="http://ogp.me/ns/fb#">
<head>
</head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<body>
    <div id="fb-root">
    </div>

    <script type="text/javascript" language="javascript">
        window.fbAsyncInit = function () {
            // init the FB JS SDK
            FB.init({
                appId: '140536862789242', // ur app id
                status: true,
                cookie: true,
                xfbml: true,
                oauth: true, // enable OAuth 2.0
                channelUrl: 'http://www.yoursite.com/channel.html' //custom channel
            });

            // Additional initialization code such as adding Event Listeners goes here
            FB.Event.subscribe('edge.create', function (response) {
                alert("user has clicked on like...");
            });

            FB.Event.subscribe('edge.remove', function (response) {
                alert("user has clicked on unlike...");
            });
        };

        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
            fjs.parentNode.insertBefore(js, fjs);
        } (document, 'script', 'facebook-jssdk'));
    </script>

    <fb:like href="https://www.facebook.com/Bridzetech" send="false" layout="button_count" width="450" show_faces="false"></fb:like>
</body>
</html>



edge.create event is fired on when like is clicked, and edge.remove is fired when user clicks on unlike...