Custom Control 3-button control

Source: Internet
Author: User

Custom button control

Create a class gutton

Using system; using system. data; using system. configuration; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; namespace searchinfo {// <summary> // custom button control gutton /// </Summary> public class gutton: webcontrol, ipostbackeventhandler {Public String text {set {viewstate ["text"] = V Alue;} get {string STR = (string) viewstate ["text"]; If (STR! = NULL) {return STR;} return string. empty ;}} protected override htmltextwritertag tagkey // rewrite the tag. The default value is <span> -- gextbox, which generates the <span> tag {get {return htmltextwritertag. input; // return base. tagkey ;}} protected override void addattributestorender (htmltextwriter writer) // Add attributes for the tag {writer. addattribute (htmltextwriterattribute. name, this. uniqueid); // a property writer that is required for the send-back event. addattribute (htmltextwriterattribu Te. value, this. text); // writer. addattribute (htmltextwriterattribute. type, "button"); writer. addattribute (htmltextwriterattribute. type, "Submit"); // submit enables submission. The ASP Server Control is also the generated submit // base. addattributestorender (writer);} protected override void rendercontents (htmltextwriter writer) // content in the tag {// base. rendercontents (writer);} public event eventhandler click; # region ipostbackeventhandler member public Vo Id raisepostbackevent (string eventargument) {If (Click! = NULL) {Click (this, eventargs. Empty); // parameter 1: Event sender. Parameter 2: event information. }}# Endregion }}

Create gutton. aspx

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "gutton. aspx. CS "inherits =" gutton "%> <% @ register namespace =" searchinfo "tagprefix =" cc "%> <! 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"> 

Background page gutton. aspx. CS

Using system; using system. data; using system. configuration; using system. collections; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; public partial class gutton: system. web. UI. page {protected void page_load (Object sender, eventargs e) {} protected void gutton_onclick (Object sende R, eventargs e) {response. Write ("click the button! ");}}

 

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.