• C#代码


    using System;
    
    using System.Web.UI;
    
    using System.Web.UI.WebControls;
    
    using System.ComponentModel;
    
     
    
    using System.Text;
    
     
    
    namespace Controls
    
    {
    
        /// <summary>
    
        /// MyTextBox2 的摘要说明。
    
        /// </summary>
    
        [ToolboxData("<{0}:MyTextBox2 runat=server></{0}:MyTextBox2>")]
    
        public class MyTextBox2 : System.Web.UI.WebControls.WebControl,INamingContainer
    
        {
    
            private Label lbl;
    
            private TextBox txt;
    
     
    
            protected override void CreateChildControls()
    
            {
    
                base.CreateChildControls ();
    
     
    
                lbl = new Label();
    
                lbl.ID = "lbl";
    
                lbl.Style.Add("display", "none");
    
                Controls.Add(lbl);
    
     
    
                txt = new TextBox();
    
                txt.ID = "txt";
    
                txt.AutoPostBack = true;
    
                txt.TextChanged += new EventHandler(txt_TextChanged);
    
                Controls.Add(txt);
    
     
    
                lbl.Attributes.Add("onclick", "showbox(this,'" + txt.ClientID + "');");
    
     
    
                ChildControlsCreated = true;
    
            }
    
     
    
            protected override void OnPreRender(EventArgs e)
    
            {
    
                base.OnPreRender (e);
    
                if(txt.Text.Trim().Length == 0)
    
                    return;
    
                double t = 0;
    
                try
    
                {
    
                    t = double.Parse(txt.Text.Trim());
    
                }
    
                catch(Exception ex)
    
                {
    
                    ex.ToString();
    
                }
    
                lbl.Text = t.ToString("c");
    
            }
    
     
    
     
    
            protected override void RenderChildren(HtmlTextWriter writer)
    
            {
    
                StringBuilder sb = new StringBuilder();
    
     
    
                sb.Append("<script language='javascript'>");
    
                sb.Append("function showbox(lbl,txtID){lbl.style.display='none';var txt=document.getElementById(txtID);txt.style.display='block';}");
    
                sb.Append("</script>");
    
     
    
                this.Page.RegisterStartupScript("MyTextBox2JS", sb.ToString());
    
     
    
                lbl.RenderControl(writer);
    
                txt.RenderControl(writer);
    
            }
    
     
    
            protected override HtmlTextWriterTag TagKey
    
            {
    
                get
    
                {
    
                    return HtmlTextWriterTag.Div;
    
                }
    
            }
    
     
    
            private void txt_TextChanged(object sender, EventArgs e)
    
            {
    
                if(txt.Text.Trim().Length == 0)
    
                    return;
    
                double t = 0;
    
                try
    
                {
    
                    t = double.Parse(txt.Text.Trim());
    
                }
    
                catch(Exception ex)
    
                {
    
                    ex.ToString();
    
                }
    
                lbl.Style.Add("display", "block");
    
                lbl.Text = t.ToString("c");
    
                txt.Style.Add("display", "none");
    
            }
    
        }
    
    } 
  • 相关阅读:
    从O(n^3) 到 O(n)求最大连续和
    冲刺博客NO.6
    冲刺博客NO.5
    冲刺博客NO.4
    冲刺博客NO.3
    冲刺博客NO.2
    冲刺博客NO.1
    结对开发:四则运算(网页版)
    课堂作业3
    软件工程概论02~ 四则运算
  • 原文地址:https://www.cnblogs.com/ddlzq/p/3529607.html
Copyright © 2020-2023  润新知