how to set property for a user control from cs file
-
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
-
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
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
-
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
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
-
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
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.