Programming analysis of ASP. NET LinkButton component

Source: Internet
Author: User
Tags what is asp

What is ASP. NET LinkButton component programming? First, let's take a look:

The LinkButton component in the WebForm component of ASP. NET is also A server component, which is somewhat similar to the <A> identifier in HTML. Its main function is to display a hyperlink on the ASP. NET page. When the link is pressed, the page will transmit information to the server and process the corresponding events on the server.

I. important components of the ASP. NET LinkButton component:

The following table describes some common attributes and events of the LinkButton component.

Common attributes and events of the LinkButton component

Text is an attribute, that is, the Text displayed by the LinkButton component.

CommandName and CommandArgument have the same functions. When a Click event is triggered, the two attributes can be used to conveniently transmit data to the server. Some important usage of these two attributes are described below.

OnClick is triggered when the component is clicked.

OnCommand is also an event and similar to the above OnClick event. The difference is that when this event is triggered, the CommandName and CommandArgument attribute values are passed to the server.

2. Use the CommandName and CommandArgument attributes on the ASP. NET page:

You may be confused about the CommandName and CommandArgument attributes in the ASP. NET LinkButton component. In fact, they play a very important role. Example:

If there are 100 ASP. NET linkbuttons in one of your pages, you need to determine which LinkButton is being pressed on the server side. Without these two attributes, you can assign values to the Text attribute of each LinkButton and check the Text attribute value to determine which LinkButton is pressed. Of course, you can also give different names to each LinkButton. Of course, you just want the same name, in ASP. NET), and then in the event processing function, it checks the Sender attribute value to determine which LinkButton is pressed. Although these methods are all feasible, they are not complicated. With the CommandName and CommandArgument attributes, you can easily solve these problems.

Assign values to the CommandName and CommandArgument attributes of LinkButton in the program. Then, through the OnCommand event, you can obtain data from the CommandEventArgs class to determine which ASP is used. NET LinkButton is pressed. So what does the CommandEventArgs class do? The CommandEventArgs class stores data related to Button events, and can access the data through CommandEventArgs class attributes in event processing. After a LinkButton is pressed, the data triggered by this LinkButton is stored in the CommandEventArgs class of the server, accessing the attributes in the CommandEventArgs class also accesses the pressed LinkButton. In this case, you may still have some questions. Here is a program example to illustrate it.

Iii. usage of the ASP. NET LinkButton component:

This article describes how the LinkButton component transmits the CommandName and CommandArgument attribute values through the OnCommand () event. And how to read data in the CommandEventArgs class in the program.

Is the interface for running the program:

The source code of Link. aspx is as follows:

 
 
  1. <%@ Page Language ="C #"Debug ="True"%>
  2. <Html>
  3. <Head>
  4. <Title> Link Button component demo program </title>
  5. <Script runat ="Server">
  6. Protected VoidLinkButton_Command (ObjectSender, CommandEventArgs e)
  7. {
  8. Message. Text ="You choose :"+ E. CommandArgument;
  9. }
  10. </Script>
  11. </Head>
  12. <Body>
  13. <Form runat ="Server">
  14. <Table cellspacing = 0 cellpadding = 0 border = 1>
  15. <Tr> <td> select a date: </td> </tr>
  16. <Tr>
  17. <Td align = center>
  18. <Asp: LinkButton Text ="Monday"Runat ="Server"CommandArgument ="Monday"Oncommand ="LinkButton_Command"/>
  19. </Td>
  20. </Tr>
  21. <Tr>
  22. <Td align = center>
  23. <Asp: LinkButton Text ="Tuesday"Runat ="Server"CommandArgument ="Tuesday"Oncommand ="LinkButton_Command"/>
  24. </Td>
  25. </Tr>
  26. <Tr>
  27. <Td align = center>
  28. <Asp: LinkButton Text ="Wednesday"Runat ="Server"CommandArgument ="Wednesday"Oncommand ="LinkButton_Command"/>
  29. </Td>
  30. </Tr>
  31. <Tr>
  32. <Td align = center>
  33. <Asp: LinkButton Text ="Thursday"Runat ="Server"CommandArgument ="Thursday"Oncommand ="LinkButton_Command"/>
  34. </Td>
  35. </Tr>
  36. <Tr>
  37. <Td align = center>
  38. <Asp: LinkButton Text ="Friday"Runat ="Server"CommandArgument ="Friday"Oncommand ="LinkButton_Command"/>
  39. </Td>
  40. </Tr>
  41. <Tr>
  42. <Td align = center>
  43. <Asp: LinkButton Text ="Saturday"Runat ="Server"CommandArgument ="Saturday"Oncommand ="LinkButton_Command"/>
  44. </Td>
  45. </Tr>
  46. <Tr>
  47. <Td align = center>
  48. <Asp: LinkButton Text ="Sunday"Runat ="Server"CommandArgument ="Sunday"Oncommand ="LinkButton_Command"/>
  49. </Td>
  50. </Tr>
  51. </Table>
  52. <Asp: Label id ="Message"Runat ="Server"/>
  53. </Form>
  54. </Body>
  55. </Html>

Iv. ASP. NET LinkButton component programming summary:

This article describes some important components of the LinkButton component, that is, some important attributes and events. A program example is used to describe how to use it. The emergence of the LinkButton component makes it easier to PASS Parameters on the ASP. NET page. However, this component cannot be used in browsers that do not support the javascript language because it uses the Submit () method in the javascript language to Submit pages.

This section describes the programming of ASP. NET LinkButton components. It is helpful for you to learn ASP. NET LinkButton component programming.

  1. Analysis on Transmission Mechanism of ASP. NET Component Design
  2. Analysis on complex attributes and status management of ASP. NET Component Design
  3. Analysis of ASP. NET httpHandler
  4. Programming of ASP. NET components
  5. Programming analysis of ASP. NET CheckBoxList component

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.