0
votes

I need to add a property to my custom control that writes & reads values from the DB, but when the user changes the property value from properties box, it writes it on my page as attribute of my control.

How can I prevent Visual Studio from writing the property value on the page?

1
asp.net web server control? can you show some markup and the control class declaration?Davide Piras
What do you mean by "write on my page as attribute of my control"?Otiel
I mean that if i set value (ReadWriteDBValue) from properties window in visual studio it will add attribute to control in form like '<cc1:MyCTRL ID="Test" runat="server" ReadWriteDBValue="value" />' my objective is to save the value in DB Only, without adding this attribute to Control ElementSaif Khaled Omari

1 Answers

0
votes

I think the DesignMode property of the Control class is what you are looking for:

    public string ReadWriteDBValue 
    {
        get
        {
            if (!this.DesignMode)
                return GetValueFromDB();
            else
                return string.Empty;
        }
        set 
        {
            if (!this.DesignMode)
                SetValueFromDB(value);

        }
    }

There are certain cases where the DesignMode property will not help. Here is a post that talks more about the DesignMode property:

http://dotnetfacts.blogspot.com/2009/01/identifying-run-time-and-design-mode.html

So in the past I've used the DesignMode property in combination with the System.ComponentModel.LicenseManager.UsageMode property.

if (!this.DesignMode && System.ComponentModel.LicenseManager.UsageMode != LicenseUsageMode.Designtime)
{
     //insert code that you do not want to be performed at design time.
}