Thursday, 27 September 2012

How to get text box value by using java Script



Add A text box to the Page and then

 <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="display()"/>

--JavaScript  Code--

  <script language="javascript" type="text/javascript">
        function display() {
            var text = document.getElementById('<%= TextBox1.ClientID %>').value;
            if (text==="") {
                alert("Please enter Something very carefully");
            }
            else {
                alert("Hi its good");
            }
        }
    </script>

Tuesday, 18 September 2012

How to check a number is Prime or no ?

By this Code You can check a number is Prime or not....and can you check static array values also..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class primenumber
    {
        static void Main(string[] args)
        {
            int i;
            Console.WriteLine("Please enter the nu,mber which u want to test");
            int number = Convert.ToInt32(Console.ReadLine());
            for ( i = 2; i < number; i++)
            {
                if (number % i == 0)
                {
                    Console.WriteLine("Number is not prime {0}", number);
                    break;
                }
            }
            if (number == i)
            {
                Console.WriteLine("Number is Prime {0}", number);
            }
            primenumber ob = new primenumber();
            ob.checkedi();
            Console.ReadKey();
        }
        public void checkedi()
        {
            int[] arr = {12,23,34,456,56,1243,123};
            for (int j = 0; j < arr.Length; j++)
            {
                for(int k=2;k<arr.Length; k++)
                {
                    if (arr[j] % k == 0)
                    {
                        Console.WriteLine("array number {0} is not prime", arr[j]);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Array number is {0} prime",arr[j]);
                        break;
                    }
                }
            }
        }
    }
}

Fibonacci Series code in c#




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Fibonacciseries
    {
        int prev = 0;
        int next = 1;
        public void fibonacci(int n)
        {
            for (int i = 0; i < n; i++)
            {
                int sum = prev + next;
                prev = next;
                next = sum;
                Console.WriteLine(sum);
               
            }
        }
       
        static void Main(string[] args)
        {
            Fibonacciseries ob = new Fibonacciseries();
            Console.WriteLine("Please enter the length of the series");
            ob.fibonacci(Convert.ToInt32(Console.ReadLine()));
            Console.ReadKey();
        }
     
    }
}

Thursday, 6 September 2012

How to add Twitter Follow Button to Asp.net Application using c#

If you want to add twitter follow button to your application in Asp.net
Then just do it.............

Add the given code in content place holder section where you want to add twitter button.


 <a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="true">Follow @twitterapi</a>
      <script>!function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.src = "//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); } } (document, "script", "twitter-wjs");</script> 


this code taken from twitter developer page. if you want to extra help then go to twitter developer page.

Inheritance using C#

Inheritance is mechanism by which a class can inherit the property of the Base class. A derived class can access all Non-private member of the base class.
Classes can inherit from another classThis is accomplished by putting a colon after the class name when declaring the class

public class A
{
    public A() { }
}

public class B : A
{
    public B() { }
}


Then gains all the non-private data and behavior of the base class in addition to any other data or behaviors it defines for itself.

Wednesday, 5 September 2012

Static Class in C#


A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
A Static class have these properties......
1.    Static class can’t be instantiated.
2.    Static class can contain only static members. It does not have any non static members
3.    Static class can’t contain Instance Constructor, because if any static constructor contain instance constructor then it will callable when any instance of the class is created.
For example:

public ClassName(int x, int y)
{
    this.x = x;
    this.y = y;
}

And this constructor will callable when it will be call as like this
This allows CoOrd objects to be created with default or specific initial values, like this:

ClassNamep2 = new ClassName(5, 3); // Static class does not allow to make an instance of the class. That’s why static class does not have any instance constructor.

4.    Static class does not inherited by any other derived class. Because they are implicitly sealed.

Tuesday, 4 September 2012

Add Share Button to Asp.net application


Drag and Drop a label inside of content place holder.
This label can drop any where in the page its totally depend on your choice.after that rename it as lblShare  and add the code at the page load event as given below.........
and Run your application ..........

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Label ID="lblShare" runat="server" Text=""></asp:Label>
</asp:Content>>

Code Behind.


using System.Web.UI.HtmlControls;
protected void Page_Load(object sender, EventArgs e)
{      
    lblShare.Text = "<a name=\"fb_share\" type=\"button\"></a>" +
                    "<script " +
                    "src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" " +
                    "type=\"text/javascript\"></script>";
    HtmlMeta tag = new HtmlMeta();
    tag.Name = "title";
    tag.Content = "This is the page title";
    Page.Header.Controls.Add(tag);
    HtmlMeta tag1 = new HtmlMeta();
    tag.Name = "description";
    tag.Content = "This is a page description.";
    Page.Header.Controls.Add(tag1);           
}


using this code you can share your page at Facebook. 

Code For Triangle Shape in C#

If you want to make a triangle shape using C# then just do it...........

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class testing
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                for (int j = i; j < 10; j++)
                {
                    Console.Write(" ");
                }
                for (int k =i+1; k> 0; k--)
                {
                    Console.Write("*");
                }
                Console.WriteLine("");
       
            }
            Console.ReadKey();
        }
    }
}

Output of the Program will be like this.....