Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1062531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:38:30+00:00 2026-05-16T18:38:30+00:00

I have a problem with the default value attribute. When I add my control

  • 0

I have a problem with the default value attribute.

When I add my control to page at design mode, default value does not work. This is my code:

[DefaultProperty("Text")]
[ToolboxData("<{0}:KHTLabel runat=server key=dfd></{0}:KHTLabel>")]
public class KHTLabel : Label ,IKHTBaseControl
{
    [Bindable(true)]
    [Category("Appearance")]
    [DefaultValue("KHT")]
    [Localizable(true)]
    public string Key
    {
        get
        {
            String s = (String)ViewState["Key"];
            return ((s == null) ? String.Empty : s);
        }

        set
        {
            ViewState["Key"] = value;
        }
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {......

But, at design mode when I add a control from the toolbox, the key does not exist

<cc1:KHTLabel ID="KHTLabel1" runat="server"></cc1:KHTLabel>
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:38:30+00:00Added an answer on May 16, 2026 at 6:38 pm

    That’s not what the [DefaultValue] attribute does, I’m afraid. What it does it allows the Visual Studio designer (specifically the “Properties” grid) to determine what to show by default and therefore how to know to show the value as bold when it’s different from the default.

    It’s upto you to have something in your code that holds the value “KHT” as the default value. There’s a bit of relevant detail in this 2008 blog posting of mine.

    The following code is fairly rudimentary, and I haven’t been able to verify it compiles, but it should give you some idea how you could handle “forcing” the value of your DefaultValueAttributes into the ViewState:

    private string GetDefaultAttributeValueForProperty(string propertyName)
    {
        var attributesForProperty = (from prop in typeof(KHTLabel).GetProperties()
                     where prop.Name == propertyName
                     select System.Attribute.GetCustomAttributes(prop)).First();
        var defaultValueAttribute = (from attr in attributesForProperty
                     where attr.GetType() == typeof(DefaultValueAttribute)
                     select ((DefaultValueAttribute)attr).Value).FirstOrDefault();
    
        return Convert.ToString(defaultValueAttribute);
    }
    public KHTLabel()
    {
        ViewState["Key"] = GetDefaultAttributeValueForProperty("Key");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem with my code. I use this JS $(document).ready(function() { //Default Action
I have a weird problem, and I don't know if this is the default
I have a problem with the CSS of the datepicker, I downloaded a default
I have a strange WPF/XAML problem. By default, I want all of the nodes
I have problem with my query on C, I’m using the oci8 driver. This
I have problem SIMILAR to preventing form data reposting, but not quite the same
We have added a yes/no product attribute labelled: Allow this product to have coupons
I'm showing the code to this problem for example purposes, but really my question
I'm looking for help setting a new default property value for an inherited control
I have this function function createSlidingGallery(){ gallery_position = parseInt(jQuery(.imageWrapper.default).attr(rel)); gallery_position_min = 0; gallery_position_max =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.