Saturday, August 22, 2020

Button control in asp.net

Button control are used to display a push button control on the web page.

Button class inherited from :

Object->Control->WebControl->Button

Button control to create a push button on the Web page that lets to post a page to the server. The control triggers an event in server code that you can handle to respond to the postback. 

ASP.NET includes several kinds of button control, each of which appears differently on Web pages. 

Button : Which render as a push button.
LinkButton : which renders as a link.
ImageBUtton : which  renders as image.
ImageMap : which lets you create a graphic that has hotspots that users can click

By default, all button controls submit the page when clicked.

We can also use the HtmlButton and HtmlInputButton controls to create buttons on the page that are programmable in server code.

Examples : 

In this example demonstrates how to create a Submit Button control that posts the Web page content back to the server.

Create a we page and add the following code  : 

<!DOCTYPE html>

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

<head runat="server">

    <title>Button control in asp.net</title>

</head>

<body>

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

        <div>

            <asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click"/>

        </div>

    </form>

</body>

</html>


Add the following code in cs file :


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace tutorials

{

    public partial class WebForm1 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

        }

        protected void Button1_Click(object sender, EventArgs e)

        {

            Response.Write("Current date : "+System.DateTime.Now);

        }

    }

}


No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...