Tuesday, April 19, 2011

How to initialize an ASP.NET user control property ?


First way by render event and viewstate:
public partial class Test1 : System.Web.UI.UserControl
{

   
public string CurrentValue
    {
        get {
return (string)ViewState["CurrentValue"] ?? string.Empty; }
        set {
ViewState["CurrentValue"] = value; }
    }

   
protected override void Render(HtmlTextWriter writer)
    {
       
base.Render(writer);

        writer.
Write(this.CurrentValue);
    }

}

Second way by HiddenField:
        public int CurrentValue
        {
            get
            {
                return int.Parse(this.HiddenField1.Value.ToString());
            }
            set
            {
                this.HiddenField1.Value = value.ToString();
            }
        }

Render Method:

Permission Module or Security Module in Asp.Net

http://www.dotnetfunda.com/articles/article1250-permission-module-or-security-module-in-aspnet-or-silverlight-.aspx