Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, November 11, 2011

Access modifier Accessibility Levels

Declared accessibility Meaning
public Access is not restricted.
protected Access is limited to the containing class or types derived from the containing class.
internal Access is limited to the current assembly.
protected internal Access is limited to the current assembly or types derived from the containing class.
private Access is limited to the containing type.

Thursday, September 29, 2011

Option changes event

<

head>

<

style>

.important

{ background-color:yellow; } .sorta-important { background-color:lightyellow; }

</

style>

<title>Untitled Page</title>

</

head>

<

body>

<

select onchange="this.className=this.options[this.selectedIndex].className" class="important"> <option class="important" selected="selected">Item 1</option> <option class="sorta-important">Item 2</option> </select>

</

body>

</

html>

Saturday, September 17, 2011

ASP.NET TIPS: SENDING EMAIL USING ASP.NET (GMAIL OR YOUR SERVER)

  using System.Net.Mail;
using System.Net;

        MailMessage mail = new MailMessage();
        mail.To.Add("**@gmail.com");
        mail.To.Add("**@gmail.com");
        mail.From = new MailAddress("**@gmail.com");
        mail.Subject = "Email using Gmail";

        string Body = "Hi, this mail is to test sending mail from devenvexe" +
                      "using Gmail in ASP.NET";
        mail.Body = Body;

        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential
             ("***@gmail.com", "******");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);

Monday, September 12, 2011

Reset Controls Value using Asp.net / Javascript / J query


Reset Controls Value using Asp.net / Javascript / J query

Asp.net:

Dynamicaly you have to  add controls means you don't know controls id so we can find control type in particular page after we can reset the page if your using C#.net coding mean page will refersh ,or if you are using javascript /j query means page not refresh

C#.net Coding:

    protected void Button1_Click(object sender, EventArgs e)

    {

        ResetControl(this);

    }

    public void ResetControl(Control Parent)

    {

        foreach (Control c in Parent.Controls)

        {

          

                switch (c.GetType().ToString())

                {

                    case "System.Web.UI.WebControls.TextBox":

                        ((TextBox)c).Text = "";

                        break;

                    case "System.Web.UI.WebControls.CheckBox":

                        ((CheckBox)c).Checked = false;

                        break;

                    case "System.Web.UI.WebControls.RadioButton":

                        ((RadioButton)c).Checked = false;

                        break;

 

                }

            }

        }

 

Javascript:

 

You can add client event in button .

 

<script language="javascript" type='text/javascript'>

 

        function CLSEvent()

        {

              for (i=0; i<document.forms[0].length; i++)

              {

                    doc = document.forms[0].elements[i];

                    switch (doc.type)

                    {

                        case "text" :

                                doc.value = "";

                                break;

                          case "checkbox" :

                                doc.checked = false;

                                break;   

                          case "radio" :

                                doc.checked = false;

                                break;               

                          case "select-one" :

doc.options[doc.selectedIndex].selected = false;

                                break;                     

                          case "select-multiple" :

                                while (doc.selectedIndex != -1)

                                {

                                      indx = doc.selectedIndex;

                                      doc.options[indx].selected = false;

                                }

                                doc.selected = false;

                                break;

                                   

                          default :

                                break;

                    }

              }

        }

 

</script>

 

 

JQuery:

function clear_form_elements(ele) { 

     $(ele).find(':input').each(function() {  
         switch(this.type) { 

             case 'password': 

              case 'select-multiple': 

            case 'select-one': 

             case 'text': 

              case 'textarea': 

                $(this).val(''); 

                 break; 

             case 'checkbox': 

              case 'radio': 

                this.checked = false;

         }

     });

}

Saturday, September 3, 2011

Doubt on Indexer in C Sharp

Hi Sir,

I have doubt in indexer in c sharp. Can you explain me the
uses of indexer and example program with and without indexer. That
must be same program. Also need any real time example of indexer.


With Thanks & Regards,

J.Harishankaran

Mobile: 9677357493

Wednesday, August 31, 2011

Delegate-Lambda Expression (=>):

 

 

Lambda Expression  (=>):

 

A lambda expression is an unnamed method written in place of a delegate instance.

The compiler immediately converts the lambda expression to either

 

  • Delegate Instance
  • Unmanaged Method
  • Lambda Expression it introduced in C# 3.0

 

Below is delegate method declaration

 

     public delegate int AddTwoNumberDel(int fvalue, int svalue);

 

     We can use lambda expression

       

                 AddTwoNumberDel AT = (a, b) => a + b;

          int result=   AT(1,2);

          MessageBox.Show(result.ToString());

 

Before that what we used Please check this url

 

http://jsdotnetsupport.blogspot.com/2011/08/beginner-delegate-program.html

 

 

What is Syntax in Lambda Expression?:

 

A lambda expression has the following form:

 

(parameters) => expression-or-statement-block

 

(a, b) => a + b;   this program

 

(a, b)  èParameter

a+b     è Expression /statement block

=>      è  Lambda Expression

 

You can write Following format also

 

(a, b) =>{ return  a + b }

 

Func ,Action Keyword:

 

Lambda Expression mostly used Func and Action Keyword

  • Func Keyword is one of the generic Delegate

Example 1:

 

Func<int, int,string> Add = (fvalue, svalue) => (fvalue + svalue).ToString();

            MessageBox.Show(Add(3, 5));          // outPut 8

           

Example 2:

 

Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue;

            MessageBox.Show(Add(3, 5).ToString());          // outPut 8

 

Above program  how its working ?

 

Func  è Func is Keyword

 

Func<int, int,string> è first Two type is parameter ,Last type is return type

 

Add  è Add is Method Name

 

(fvalue, svalue èParameter

 

(fvalue + svalue).ToString(); è Statement

 

 

Other feature:

 

  • You can access outer variable also 

Ex:

 

Int value=50;

 

Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue+ value;

            MessageBox.Show(Add(3, 5).ToString());          // outPut 58

 

Question ?

 

Int value=50;

 

Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue+ value;

  

    Int value=100;

 

            MessageBox.Show(Add(3, 5).ToString());  

 

    Int value=200;

 

Post your Answers ….Get Special Gift ….  To Bloger…..

 

 

Action Keyword:

 

Action Type same like Func method but The Action type receives parameters but does not return a parameter. The Func type, however, receives parameters and also returns a result value. The difference is that an Action never returns anything, while the Func always returns something. An Action is a void-style method in the C# language

 

Example:

 

using System;
 
class Program
{
    static void Main()
    {
      // Example Action instances.
      // ... First example uses one parameter.
      // ... Second example uses two parameters.
      // ... Third example uses no parameter.
      // ... None have results.
      Action<int> example1 =
          (int x) => MessageBox.Show("Write {0}", x);
      Action<int, int> example2 =
          (x, y) => MessageBox.Show ("Write {0} and {1}", x, y);
      Action example3 =
          () => MessageBox.Show ("Done");
      // Call the anonymous methods.  Or example1(1)
      example1.Invoke(1);
      example2.Invoke(2, 3);
      example3.Invoke();
    }
}
 
 
 
Output
Write 1
Write 2 and 3
Done

Thursday, August 25, 2011

doubt...User Controls VS Custom Controls


Hi Ravi,
 

What are user controls?

  • User controls are custom,
  • reusable controls, 
  • Microsoft offer an easy way to partition and reuse common user interfaces across ASP.NET Web applications
How to create User Control,
 
Ctrl+Shift +A  => Add Usercontrol ==> Design control
 
Rules For creating user controls:
 
The syntax you use to create a user control is similar to the syntax you use to create a Web Forms page (.aspx).
The only difference is that a user control does not include the <html>, <body>, and <form> elements since a Web Forms page hosts the user control.
 
How to Add your User Control;
 
you can register your control in particular  your page
<%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>
and add control
<html>     <body>           <form runat="server">                <UC:TestControl id="Test1" runat="server"/>           </form>     </body>   </html> 
How to add RunTime:
 
// Load the control by calling LoadControl on the page class. Control c1 = LoadControl("test.ascx");              // Add the loaded control in the page controls collection.	 Page.Controls.Add(c1); 
 

What are custom controls?

 

Custom controls are compiled code components that execute on the server,
expose the object model, 
and render markup text,
such as HTML or XML, as a normal Web Form or user control does.
 
How to create Custom control:
 
Ctrl+Shift+A=> Add class library=>render control => excute program
 
User Control vs Custom Control:
 
 
 
 

Factors

User control

Custom control

Deployment

Designed for single-application scenarios

Deployed in the source form (.ascx) along with the source code of the application

If the same control needs to be used in more than one application, it introduces redundancy and maintenance problems

Designed so that it can be used by more than one application

Deployed either in the application's Bin directory or in the global assembly cache

Distributed easily and without problems associated with redundancy and maintenance

Creation

Creation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD)

Writing involves lots of code because there is no designer support

Content

A much better choice when you need static content within a fixed layout, for example, when you make headers and footers

More suited for when an application requires dynamic content to be displayed; can be reused across an application, for example, for a data bound table control with dynamic rows

Design

Writing doesn't require much application designing because they are authored at design time and mostly contain static data

Writing from scratch requires a good understanding of the control's life cycle and the order in which events execute, which is normally taken care of in user controls

 
 
Reference :
 
Micrsoft
 
Thanks to Micrsoft 
  
On Thu, Aug 25, 2011 at 3:37 PM, ravi kumar <ravidravi@gmail.com> wrote:
  
What is the Difference between user control & custom control in asp.net.....Please give me some example......
 

Wednesday, August 24, 2011

Runtime Assign Method using Delegate


Writing Plug-in Methods with Delegates




A delegate variable is assigned a method dynamically. This is useful for writing plug-
in methods. In this example, we have a utility method named  Add,Sub that applies
a NumberOper . The NumberOper method has a delegate
parameter,


   ///

        /// delegate  declaration
        ///

        ///
        ///
        ///
        public delegate int NumberOperation(int fvalue, int svalue);
        ///

        /// Button click event it will call NumberOper method
        ///

        ///
        ///
        private void btnClick_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt16(txtfvalue.Text);
            int b = Convert.ToInt16(txtsvalue.Text);
            txtresult.Text = NumberOper(a, b, Add).ToString();//Dynamic we Assign Method name
        }
        ///

        /// Button click event it will call NumberOper method
        ///

        ///
        ///
        private void btnSub_Click(object sender, EventArgs e)
        {

            int a = Convert.ToInt16(txtfvalue.Text);
            int b = Convert.ToInt16(txtsvalue.Text);
            txtresult.Text = NumberOper(a, b, Sub).ToString(); //Dynamic we Assign Method name

        }

        ///

        /// Main Method with delegate Parameter
        ///

        /// first value
        /// second value
        /// Dynamic Delegate
        /// call method add or sub and return result
        public int NumberOper(int a, int b, NumberOperation AT)
        {

          return   AT(a, b);
        }

        ///

        /// Add two numbers Methos
        ///

        /// first Value
        /// Second value
        /// Result
        public int Add(int a, int b)
        {
            return a + b;
        }
        ///

        /// Sub two number
        ///

        /// first value
        /// Second value
        /// int value
        public int Sub(int a, int b)
        {
            return a - b;
        }



Beginner Delegate program

Add Two Number Delegate Program 

 public delegate int AddTwoNumberDel(int fvalue, int svalue);

        private void btnClick_Click(object sender, EventArgs e)
        {
            AddTwoNumberDel AT = Addnumber;                   // create delegate instance
           //is shorthand for

            //AddTwoNumberDel AT = new AddTwoNumberDel(Addnumber);

           
            int a = Convert.ToInt16(txtfvalue.Text);
            int b = Convert.ToInt16(txtsvalue.Text);
            txtresult.Text = AT(a, b).ToString();          // invoke Method
            //is shorthand for
            //txtresult.Text = AT.Invoke(a, b).ToString();
        }


        public int Addnumber(int fvalue, int svalue)
        {

            return fvalue + svalue;

        }
Note:
Copy and past your VS Editor it will Work... Do you want sample application mail me ...