Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to set property for a user control from cs file

how to set property for a user control from cs file

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdesignsysadmintutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ansriharsha
    wrote on last edited by
    #1

    Hi , i have created a user control numberbox which is working fine . But i want set the property value from aspx.cs file dynamically which is not possible . it is taking the value from toolboxdata table only even though i set the property in page load. numberbox code:

    using System.Collections.Generic;
    using System.Text;
    using System;
    using System.Web.UI;
    using System.ComponentModel;
    using System.Web.UI.WebControls;
    using System.Text.RegularExpressions;

    namespace ERP.Controls
    {
    /// /// Number Box ASP.NET control
    ///
    [
    ToolboxData("<{0}:NumBox runat=server>"),
    DefaultProperty("DecimalPlaces")
    ]

    public class NumBox : TextBox
    {
    
        private int mDecimalPlaces = 0;
        private char mDecimalSymbol = '.';
        private bool mAllowNegatives = true;
    
        /// /// Gets or sets the number of decimals for the number box.
        /// 
        \[
        Bindable(true),
        Category("Appearance"),
        DefaultValue(typeof(int), "2"),
        Description("Indicates the number of decimal places to display.")
        \]
        public virtual int DecimalPlaces
        {
            get { return mDecimalPlaces; }
            set { mDecimalPlaces = value; }
        }
    
    
        
    
    
    
        /// /// Gets or sets the digit grouping symbol for the number box.
        /// 
        \[
        Bindable(true),
        Category("Appearance"),
        DefaultValue("."),
        Description("The digit grouping symbol.")
        \]
    
        public virtual char DecimalSymbol
        {
            get { return mDecimalSymbol; }
            set { mDecimalSymbol = value; }
        }
    
        /// /// Gets or sets wheter negative numbers are allowed in the number box.
        /// 
        \[
        Bindable(true),
        Category("Appearance"),
        DefaultValue(true),
        Description("True when negative values are allowed")
        \]
        public virtual bool AllowNegatives
        {
            get { return mAllowNegatives; }
            set { mAllowNegatives = value; }
        }
    
    
    
        /// /// Gets or sets the value of the number box.
        /// 
        \[
        Bindable(true),
        Category("Appearance"),
        DefaultValue(0),
        Description("Indicates the number of decimal places to display.")
        \]
    
        p
    
    N R 2 Replies Last reply
    0
    • A ansriharsha

      Hi , i have created a user control numberbox which is working fine . But i want set the property value from aspx.cs file dynamically which is not possible . it is taking the value from toolboxdata table only even though i set the property in page load. numberbox code:

      using System.Collections.Generic;
      using System.Text;
      using System;
      using System.Web.UI;
      using System.ComponentModel;
      using System.Web.UI.WebControls;
      using System.Text.RegularExpressions;

      namespace ERP.Controls
      {
      /// /// Number Box ASP.NET control
      ///
      [
      ToolboxData("<{0}:NumBox runat=server>"),
      DefaultProperty("DecimalPlaces")
      ]

      public class NumBox : TextBox
      {
      
          private int mDecimalPlaces = 0;
          private char mDecimalSymbol = '.';
          private bool mAllowNegatives = true;
      
          /// /// Gets or sets the number of decimals for the number box.
          /// 
          \[
          Bindable(true),
          Category("Appearance"),
          DefaultValue(typeof(int), "2"),
          Description("Indicates the number of decimal places to display.")
          \]
          public virtual int DecimalPlaces
          {
              get { return mDecimalPlaces; }
              set { mDecimalPlaces = value; }
          }
      
      
          
      
      
      
          /// /// Gets or sets the digit grouping symbol for the number box.
          /// 
          \[
          Bindable(true),
          Category("Appearance"),
          DefaultValue("."),
          Description("The digit grouping symbol.")
          \]
      
          public virtual char DecimalSymbol
          {
              get { return mDecimalSymbol; }
              set { mDecimalSymbol = value; }
          }
      
          /// /// Gets or sets wheter negative numbers are allowed in the number box.
          /// 
          \[
          Bindable(true),
          Category("Appearance"),
          DefaultValue(true),
          Description("True when negative values are allowed")
          \]
          public virtual bool AllowNegatives
          {
              get { return mAllowNegatives; }
              set { mAllowNegatives = value; }
          }
      
      
      
          /// /// Gets or sets the value of the number box.
          /// 
          \[
          Bindable(true),
          Category("Appearance"),
          DefaultValue(0),
          Description("Indicates the number of decimal places to display.")
          \]
      
          p
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      We don't need to see all of your code, only the relevant bits. Most will just ignore a post with this much code.


      only two letters away from being an asset

      1 Reply Last reply
      0
      • A ansriharsha

        Hi , i have created a user control numberbox which is working fine . But i want set the property value from aspx.cs file dynamically which is not possible . it is taking the value from toolboxdata table only even though i set the property in page load. numberbox code:

        using System.Collections.Generic;
        using System.Text;
        using System;
        using System.Web.UI;
        using System.ComponentModel;
        using System.Web.UI.WebControls;
        using System.Text.RegularExpressions;

        namespace ERP.Controls
        {
        /// /// Number Box ASP.NET control
        ///
        [
        ToolboxData("<{0}:NumBox runat=server>"),
        DefaultProperty("DecimalPlaces")
        ]

        public class NumBox : TextBox
        {
        
            private int mDecimalPlaces = 0;
            private char mDecimalSymbol = '.';
            private bool mAllowNegatives = true;
        
            /// /// Gets or sets the number of decimals for the number box.
            /// 
            \[
            Bindable(true),
            Category("Appearance"),
            DefaultValue(typeof(int), "2"),
            Description("Indicates the number of decimal places to display.")
            \]
            public virtual int DecimalPlaces
            {
                get { return mDecimalPlaces; }
                set { mDecimalPlaces = value; }
            }
        
        
            
        
        
        
            /// /// Gets or sets the digit grouping symbol for the number box.
            /// 
            \[
            Bindable(true),
            Category("Appearance"),
            DefaultValue("."),
            Description("The digit grouping symbol.")
            \]
        
            public virtual char DecimalSymbol
            {
                get { return mDecimalSymbol; }
                set { mDecimalSymbol = value; }
            }
        
            /// /// Gets or sets wheter negative numbers are allowed in the number box.
            /// 
            \[
            Bindable(true),
            Category("Appearance"),
            DefaultValue(true),
            Description("True when negative values are allowed")
            \]
            public virtual bool AllowNegatives
            {
                get { return mAllowNegatives; }
                set { mAllowNegatives = value; }
            }
        
        
        
            /// /// Gets or sets the value of the number box.
            /// 
            \[
            Bindable(true),
            Category("Appearance"),
            DefaultValue(0),
            Description("Indicates the number of decimal places to display.")
            \]
        
            p
        
        R Offline
        R Offline
        r a m e s h
        wrote on last edited by
        #3

        I think the value of the DecimalPlaces property is not stored in ViewState. You need to override LoadViewState and SaveViewState methods in the Custom Control.

        modified on Wednesday, September 2, 2009 12:37 PM

        A 1 Reply Last reply
        0
        • R r a m e s h

          I think the value of the DecimalPlaces property is not stored in ViewState. You need to override LoadViewState and SaveViewState methods in the Custom Control.

          modified on Wednesday, September 2, 2009 12:37 PM

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          I guess too. :)

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups