Search code examples
c#asp.netwebformsaspx-user-control

Webforms: Prevent auto generation of property on user control when Generating Local Resources


I have an old project that needs localizing and which has custom user control and custom properties on the control. When I generate the local resource file for a page it adds in all the properties with a default value and I am having to go in and strip them all out. Is there a way to prevent the property from auto generating on the control when running the 'Generate Local Resource' option?

Before generating resource

<ws:wsTextBox ID="txtCounter" Text="5" Width="18%" runat="server"/>

After generating resource

<ws:wsTextBox ID="txtCounter" Text="5" Width="18%" runat="server" meta:resourcekey="txtCounterResource4" wsEnabled="False" wsRequired="False"/>

The control in question

using System;
using System.ComponentModel;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace wsServerControls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")]

    public class wsTextBox : TextBox
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]

        private Boolean _enabled = true;
        private bool _required = false;
      
        public Boolean wsEnabled
        {
            get
            {
                _enabled = (ViewState["_enabled"] == null) ? false : (Boolean)ViewState["_enabled"];
                return _enabled;
            }
            set
            {
                _enabled = value;
                ViewState["_enabled"] = value;
                if (_enabled == false)
                {
                    this.Style.Add("border", "none");
                    this.Style.Add("font-family", "Verdana");
                    this.Attributes.Add("readonly", "readonly");
                    this.Attributes.Add("onfocus", "this.blur();");
                    this.TabIndex = -1;
                }
                else
                {
                    this.Style.Remove("border");
                    this.Style.Remove("font-family");
                    this.Attributes.Remove("readonly");
                    this.Attributes.Remove("onfocus");

                }
            }
        }

        public Boolean wsRequired
        {
            get
            {
                _required = (ViewState["_required"] == null) ? false : (Boolean)ViewState["_required"];
                return _required;
            }
            set
            {
                _required = value;
                ViewState["_required"] = value;
            }
        }        

    }
}

I have tried setting the Localization attribute to false and Browsable attriubute to false but this does not seem to work.


Solution

  • Never figured this out, in the end I just wrote my own resx generator.