UserControl and Properties

Discussion in 'ASP .Net Building Controls' started by Zürcher See, Apr 15, 2004.

  1. Zürcher See

    Zürcher See Guest

    Who can explain me why this very simple UserControl with the "Document"
    property, when is in a WebForm, I can't see/set the "Document" property from
    the Properties Frame of VisualStudio?

    WebUserControl1.ascx

    <%@ Control Language="c#" AutoEventWireup="false"
    Codebehind="WebUserControl1.ascx.cs"
    Inherits="WebApplication1.WebUserControl1"
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <asp:Label id="Label1" runat="server">Label</asp:Label>

    WebUserControl1.ascx.cs
    sing System;

    using System.Data;

    using System.Drawing;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.HtmlControls;

    using System.ComponentModel;

    namespace WebApplication1

    {

    /// <summary>

    /// Summary description for WebUserControl1.

    /// </summary>

    public class WebUserControl1 : System.Web.UI.UserControl

    {

    protected System.Web.UI.WebControls.Label Label1;

    private string _document;

    private void Page_Load(object sender, System.EventArgs e)

    {

    // Put user code to initialize the page here

    this.Label1.Text=Document;

    }

    [Category("Misc"),Browsable(true)]

    public string Document

    {

    get{if (this._document!=null) return this._document; else return "";}

    set{this._document=value;}

    }

    #region Web Form Designer generated code

    override protected void OnInit(EventArgs e)

    {

    //

    // CODEGEN: This call is required by the ASP.NET Web Form Designer.

    //

    InitializeComponent();

    base.OnInit(e);

    }


    /// <summary>

    /// Required method for Designer support - do not modify

    /// the contents of this method with the code editor.

    /// </summary>

    private void InitializeComponent()

    {

    this.Load += new System.EventHandler(this.Page_Load);

    }

    #endregion

    }

    }
     
    Zürcher See, Apr 15, 2004
    #1
    1. Advertisements

  2. The reason is because Visual Studio .NET has poor designer support for
    User Controls. What you should experience with your User Control,
    though, is that the Document property can be accessed in the page's
    Code-Behind class via IntelliSense.

    For a thorough examination of User Controls, check out my article:

    An Extensive Examination of User Controls
    http://msdn.microsoft.com/asp.net/u...l=/library/en-us/dnaspp/html/usercontrols.asp


    Happy Programming!

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Apr 15, 2004
    #2
    1. Advertisements

  3. Zürcher See

    Zürcher See Guest

    Yes, I know that, I was used to write UserControl for WebForm where there
    wasn't such problems.
    Thank's
     
    Zürcher See, Apr 15, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.