I,m a novice in ASP.net programming. I wonder how to use functions and events associated with each control. I have seen few books and couldn't get it. Can anyone help me out.??

What have you tried?

Each different control is going to have different events available, and I won't even try to go through the list of them. For any given control you want to test, there's nothing better than simply going to google, typing in the control name, and usually that will be enough to get you a link to MSDN and a wealth of information on the control, its properties and events, and usage examples.

One of the earliest things to wrap your head around would probably be a button click event. If you're using C# as your code behind, you would wire up a click event like the following:

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

<!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:Button ID="btnDemo" runat="server" Text="Click Here" OnClick="btnDemo_Click" />
        <br /><br />
        <asp:Literal ID="litMessage" runat="server" />
    </div>
    </form>
</body>
</html>

The relevant line being

<asp:Button ID="btnDemo" runat="server" Text="Click Here" OnClick="btnDemo_Click" />

In it, I've created the button, called it btnDemo, provided text, and told it what handler I want to respond to the button's OnClick event. Now to the code file...

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

public partial class buttondemo : System.Web.UI.Page
{
    protected void btnDemo_Click(object sender, EventArgs e)
    {
        litMessage.Text = "You clicked the button!";
    }
}

I've created my handler function that simply updates a literal control's Text property on the web page.

hi apegram Thanx for the early and prompt reply.few days back i was trying to avoid loading the entire page after setting auto postback for a dropdown list control.I knew, it has something to do with 'postback is not true',page should be loaded but i couldn't get the correct syntax like page.isnotpostback==true. i thought it will be useful to know all possible events used with page for example. thanks a lot will be elated if u can guide me further...

In C# syntax, the syntax for working or not working with things during postback is the following:

if (this.IsPostBack)
{
    // code inside this block will only execute during postbacks
}
else 
{
   // code inside this block will only execute on non-postbacks
}

// alternately, can handle like this
if (!this.IsPostBack)
{
    // code inside this block will only execute on non-postbacks
}
else 
{
    // code inside this block will only execute during postbacks
}

The exclamation point is the "not" operator here.

bool someBool = true;
if (!someBool) // if someBool is not true
{
    // someBool is declared as true, so this will not execute
}

someBool = false;
if (!someBool)  // if someBool is not true
{
    // now someBool has been set to false, so this block will execute
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.