UserControl and Properties

Z

Zürcher See

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

}

}
 
S

Scott Mitchell [MVP]

Zürcher See said:
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?
[snip!]

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
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
Z

Zürcher See

Scott Mitchell said:
Zürcher See said:
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?
[snip!]

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.

Yes, I know that, I was used to write UserControl for WebForm where there
wasn't such problems.
Thank's
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top