1

我创建了一个自定义控件,它是一个继承文本框控件的数字文本框。但是当它呈现时,页面源显示了 2 个文本框 - 一个具有自定义控件的 id,另一个具有自定义控件的 id 并附加了 _txt_ctrl。

我希望这个基本控件(带有 _txt_ctrl)不应该呈现。如果我们做不到,至少可以向我的基本控件添加属性。我试过这条线但没有用。

base.Attributes.Add("Title", "This is a Numeric Textbox, only accepts numbers.");

![错误截图 - 附加文本框][1]

  protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("<Table id=" + this.ClientID + "_tbl" + " width='100%' cellSpacing='0' cellPadding='0' border='0'><TR><TD>");
            base.Render(writer);
            writer.Write("</TD></TR></Table>");
        }

并初始化

  protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (this.Page.ClientScript.IsClientScriptBlockRegistered("NumericTextBoxScript") == false)
            {
                string _strScriptSrc = Page.Request.ApplicationPath + "/CommonFramework/Presentation/JavaScripts/FACESNumericTextBox.js";

                string strScriptBlock = "<script src='"
                    + _strScriptSrc
                    + "'></script>";

                this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "NumericTextBoxScript", strScriptBlock);
            }

            this.RegisterClientScriptFunction();

            // Adding the TextAlign property to the control's stylesheet.            
            if (this.TextAlign != null && this.TextAlign != String.Empty)
                this.Style.Add("text-align", this.TextAlign);

            this.Attributes.Add("onkeypress", "OnKeyPress_NumericEdit(event,'" + this.ClientID + "');");
            this.Attributes.Add("onblur", "FormatInteger_NumericEdit('" + this.ClientID + "');");
            this.Attributes.Add("MaxValue", _maxValue.ToString());
            this.Attributes.Add("MinValue", _minValue.ToString());
            this.Attributes.Add("MinDecimalPlaces", Convert.ToInt32(_minDecimalPlaces).ToString());
            this.Attributes.Add("DataMode", Convert.ToInt32(_dataMode).ToString());
            this.Attributes.Add("IsMaxValueSet", IsMaxValueSet.ToString());
            this.Attributes.Add("IsMinValueSet", IsMinValueSet.ToString());
            this.Attributes.Add("ValueChange", _valueChange);
        this.Attributes.Add("Title", "This is a Numeric Textbox, only accepts numbers.");
base.Attributes.Add("Title", "This is a Numeric Textbox, only accepts numbers.");


        }
4

0 回答 0