Action Controls in ASP.NET


Introduction and Demonstration

Action controls allow users to perform some action on that page, such as navigating to a different URL, submitting a form, resetting a form's values, or executing a client script. Here is list of such controls.
Control Purpose **************************************************** Button Displays a command button that posts a form to the server when clicked. ImageButton Displays an image that posts a form to the server when clicked. LinkButton Displays a hyperlink text that posts a form to the server when clicked. Hyperlink Displays a hyperlink text that navigates from one page to another when clicked.

The simplified syntax of these controls is as follows:


<asp:button id="MyButton" text="Click Me!!" runat="server"/>
 
<asp:imagebutton id="MyImageButton"
   imageurl="aspnetian.jpg" runat="Server"/>
 
<asp:linkbutton id="MyLinkButton" text="Click Me" runat="server"/>
 
<asp:hyperlink id="MyHyperLink"
   text="Click Me"
   navigateurl="ActionControls.aspx"
   target="_blank"
   runat="server"/>

The controls can then be accessed programmatically with code fragments like the following:


MyButton.CommandName = "Sort"
MyImageButton.CommandArgument = "Ascending"
MyLinkButton.CommandName = "Filter"
MyHyperLink.NavigateUrl = "http://web.itorian.com/"

Index.aspx Page:

<%@ Page Language="vb" %>
<html>
<head>
   <title>Action Control Example</title>
   <script runat="server">
      Sub Page_Load( )
         MyButton.CommandName = "Sort"
         MyImageButton.CommandArgument = "Ascending"
         MyLinkButton.CommandName = "Filter"
         MyHyperLink.NavigateUrl = " http://dotnet.oreilly.com/"
      End Sub
   </script>
</head>
<body>
   <h1>Action Control Example</h1>
   <form runat="server">
      <asp:table id="MyTable"
         border="1"
         cellpadding="5"
         cellspacing="0"
         runat="server">
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               Button Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:button id="MyButton" text="Click Me!!" runat="server"/>
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               ImageButton Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:imagebutton id="MyImageButton"
                  imageurl="aspnetian.jpg" runat="Server"/>
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               LinkButton Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:linkbutton id="MyLinkButton"
                  text="Click Me" runat="server"/>
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               HyperLink Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:hyperlink id="MyHyperLink"
                  text="Click Me"
                  navigateurl="ActionControls.aspx"
                  target="_blank"
                  runat="server"/>
            </asp:tablecell>
         </asp:tablerow>
      </asp:table>
   </form>
</body>
</html>

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples