How To Expose A Panel As A Property In User Control

Aug 20, 2010

I have a user control with a panel on it:

CustomControl.ascx
<%@ Control Language="vb" CodeBehind="CustomControl.ascx.vb" %>
<asp:Panel ID="myPanel" runat="server"></asp:Panel>

I'd lke to expose that panel as a property that I can use at design time.

CustomControl.ascx.vb
<ParseChildren(True), PersistChildren(False)> _
Partial Public Class CustomControl
Inherits System.Web.UI.UserControl
#Region "Members and Properties"
<PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property SomePanel() As Panel
Get
Return myPanel
End Get
Set(ByVal value As Panel)
myPanel= value
End Set
End Property
#End Region
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write(myPanel.HasControls.ToString())
End Sub
End Class

And then bring the control onto a page like so:

<ucl:CustomControl runat="server">
<SomePanel>
<asp:Label ID="lblText" AssociatedControlID="txtBox" runat="server"></asp:Label>
<asp:TextBox id="txtBox" runat="server"></asp:TextBox>
</SomePanel>
</ucl:CustomControl>

When I run the page, HasControls is true but nothing is rendered. What am I doing wrong?

View 1 Replies


Similar Messages:

Web Forms :: How To Expose User Control Custom Property At Its Code Behind File

Mar 10, 2010

I created a simple gridview user control with a custom property ProfileType which should load different records depending on the ProfileType value when attaching to a web page.

This is my web page:

[code]....

how I can expose user control custom property at its code-behind file.

View 2 Replies

Web Forms :: Accessing A Public Property Of A Nested User Control In A Master Page From A Pages' User Control?

Sep 10, 2010

I've got a web site that has a master page and that master page (mpMaster that has a user control ucControl1) which has a sub user control (ucControl2), this user control has a property which accepts a value. Now, I have a page that uses the master page
and on this page I have another user control (ucPageControl), I need to find a way of setting the value in ucControl2 from ucPageControl. Is this possible at all?

View 5 Replies

Security :: How To Expose More Properties Under User Class

Jul 16, 2010

I am using a custom membership provider. I want to expose additional properties under User class.

So in my custom membership provider class I added few Properties (FirstName, LastName, Address, etc) and set their value in ValidateUser(). However back in aspx.cs if I type User. I do not see FirstName, LastName and Address in intellisense.

Is what I'm attempting to do even possible? Or do I need to resort to using my own custom user class? In which case I wouldn't need to use custom membership provider because I can program my custom user class to do everything that custom membership provider can do. Only thing is I would need to pass this user object in session object.

View 3 Replies

Web Forms :: Set Button Property In A User Control From Another User Control

Mar 22, 2011

i have 2 user control : uc1 and uc2. and i have button in uc2 i call button1, i want to set commandArgument of button1 from uc1, how can i do this?

View 5 Replies

Web Forms :: Expose Server Control As Properties?

Feb 14, 2010

Is it possible to expose server control as properties? See below.

[Code]....

Now If i pass Panel1, it's string. Casting error. How do i get around this.

View 1 Replies

Custom Server Controls :: Property Collections Not Persisted When Control Inside Update Panel And Content Placeholder

Apr 13, 2010

I'm creating an ASP.NET Control which has a property collection for Columns which the user can edit in the Property Collection Editor..

In most circumstances this works fine, the collection can be edited in the designer and the appropriate tags are added inside the control in the ASPX file.

It works fine when

My control is added to the form

[Code]....

My control is added inside an Update Panel

[Code]....

[Code]....

However, if My control is inside a Content Placeholder which is inside an Update Panel, it fails to work as it should. In this scenario, when the Columns collection is edited in the designer, if you then switch back to Source view, the Columns collection is emptied. I have to save the aspx page before switching back to Source view for the changes to be kept.

[Code]....

how to get around this problem? Is there something I may have missed?

Here's the code for the Control

[Code]....

View 2 Replies

Forms Data Controls :: Expose Event Of Nested Control?

Jun 4, 2010

I have a detailsview that contains a radio button list, and a couple of check boxes. I want to run some code when the radiobuttonlist selection is changed, or when the checkboxes are checked or unchecked. how I can do that even though the controls are nested inside another control?

View 2 Replies

How To Expose Child Control Style Properties In A Custom Composite WebControl

Feb 23, 2010

I am writing a custom composite WebControl and want to expose styles of child controls it encapsulates to the ASP.NET designer. The code I currently have is similar to the skeleton below (which for simplicity only has one child control).

With the code below, I can see property "ChildPanelStyle" in the designer, but when I try to modify one of the properties (e.g. CssClass) in the designer, it immediately resets itself to its default value. It looks like the designer serialization isn't happening.

What am I doing wrong?

UPDATE

I've updated the sample with an additional style property that is managed directly by the custom control, rather than simply being the property of a child control.

The HeaderStyle property is persisted properly by the designer, but the ChildPanelStyle property isn't.

Of course I could manage all my styles like HeaderStyle, and apply them during rendering, but I'm hoping there's a simpler solution whereby child controls can take care of themselves, and I don't need any custom rendering.

[code]....

View 1 Replies

User Control - Must Supply Property?

May 28, 2010

i built a user control and i want to make one of its properties as a must, that's mean if you not supply this control when you create the control the project won't be compile, just like if you omit the runat="server" property.

View 17 Replies

Web Forms :: How To Get Property Value From The User Control

Oct 28, 2010

I have a user control that has the following property

public string ReportID

View 6 Replies

Add Description To An User Control Property In Vb.net?

Jul 10, 2010

I created one web user control with property named "ReadonlyField" with boolean datatype. I am able to use in my web pages and now i wanted to add a description to that property so that i dont need to explain each time to my team member what is that property's intention.

I got following snippet in c# but didnt find any equivalent in vb.net and also not sure whether it will work or not.

[Description("My Description")]
public int MyIntProperty
{
get {..}
set {..}
}

View 1 Replies

How To Map A User Control Property To A Server Control Within It

Jun 2, 2010

I have a user control with a WebDateTimeEdit server control on it (essentially a TextBox). I'd like to be able to set some of the server control's properties by way of the user control's markup or programatically. for example I have this defined on my user control:

[code]....

this blows up because WebDateTimeEdit1 is null.

is there any way I can make this happen? also can do I do this

myControl2 .Font.Size = FontUnit.Point(8);

where the Font property is read only on the server control?

View 2 Replies

How To Insert A Panel Control Inside Web User Control

Mar 23, 2010

How do i create a simple web user control like Panel control (System.Web.UI.WebControls.Panel). you can drag any control inside the panel that already in the page that what i want.

View 5 Replies

Can Insert User Control With Inner-tag Content As Property Value

Apr 16, 2010

I have a control that I want to be able to mark areas as editable. When a user enters a username and password, they can then edit these editable areas.One of the area to edit is the main content of the page. Since I want them to be able to edit this on every page, I have put the editable control into the master page, wrapped around the ContentPlaceHolder of the master page.I found out how to allow the parser to allow <prefix:tag></prefix:tag> rather than just ending it with />, but I can't figure out how to get the text within the tags to be accessible through something like a Text property. A prime example of this behavior is the Label control, where you can put <asp:Label>Hello!</asp:Label> and access Hello! through the .Text property in the code.

View 10 Replies

Access Page Property From User Control?

Apr 2, 2010

how to access a property on my parent page from a user control?

View 2 Replies

Setting A Property For A User Custom Control?

Jan 25, 2010

I have created a user custom control, and what I would like to do is to pass it the text value from a label where I can carry out some other processing.

View 2 Replies

C# - User Control Not Retaining Property Values?

Oct 28, 2010

I have a very simple user control with 5 radio buttons on it, and 3 properties (ID, RatingSetID, and Rating). On the initial load of the page they are on, the code acquires data and places the data into the 3 properties. However, when the submit button is clicked the page reloads and the 3 properties get reset to 0, they are in the !IsPostBack as well.

View 2 Replies

Databind A Property On A Custom User Control?

Nov 29, 2010

I have a custom user control UserProfileLink on which I have two basic string properties, UID and UserFullName which I would like to use in a template column in a DataGrid like this:

....
<ItemTemplate>
<td:UserProfileLink ID="uplUser" runat="server" UID="<%#Eval("UserUID") %>" UserFullName="<%#Eval("UserFullName") %>" />
</ItemTemplate>
....

I get an error saying "The server tag is not well formed" which leads me to believe this type of binding isn't possible. Is there a way to do this, or is it impossible?

View 1 Replies

Set Web User Control Property To GridView Selected Row?

Feb 2, 2010

I have a web user control (ascx) that exposes an "ID" property. What I want to do is set this property when the SelectedIndexChanged event fires in a gridview in the containing page. However, I can't seem to do it.... Here's my code:

protected void grdPhysicians_SelectedIndexChanged(object sender, EventArgs e)
{
physicians_certif1.mdID = grdPhysicians.SelectedDataKey.ToString();
mvData.SetActiveView(viewEdit);
panAdditional.Visible = true;
}

Physicians_certif1 is the user control. It seems the user control is loading before the SelectedIndexChanged event has a chance to set it's property.

View 2 Replies

C# - Can't Initialize A User Control Property Using Eval

Feb 23, 2010

I designed a user control. It contains a public property "CurrentValue". When I try to initialize the property using an Eval expression, a null value is assigned.

// In below code, label assignment is OK, RatingNull user control assignment get null

<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Difficulty") %>'
<uc1:RatingNull ID="RatingNull1" runat="server" CurrentValue='<%# Eval("Difficulty") %>' />
</ItemTemplate>

If I directly assigned a value (ie, CurrentValue="5"), user control works fine.

public partial class RatingNull : System.Web.UI.UserControl
{
private string _CurrentValue;
public string CurrentValue
{
get { return _CurrentValue; }
set { _CurrentValue = value; }
}
(...)

View 1 Replies

'DataBind' A Single Property Of A User Control?

Dec 3, 2010

Before I get to the question, let me give a bit of background. I'm trying to develop a custom caching mechanism that I can apply to custom built user controls. (Please be aware that I know that there are some built in caching mechanism in .NET) Depending on certain flags set declaratively in the mark-up the control should load a cached version of its previously rendered content or execute normally (and if certain flags are set it should generate a cache of its content for next time it loads). I would like to be able to pass certain flags declaratively in the mark-up and being able to check their value at Page Init and, depending on the flag value, determine whether the control should load a cached version or not.

<uc:MyUC ID="N1" runat="server"
CacheProp='<%# SomeEnum.A | SomeEnum.B |SomeEnum.C %>'
PropA='<%# this.SomePropA %>'
PropB='<%# (this.SomePropB %>'
PropC='<%# this.SomePropC %>'
/>

The problem that I'm facing is that as far as I'm aware I can only get the value of the properties declaratively assigned in the mark-up if I called the DataBind(). However I'm faced with two problems: Firstly calling this.DataBind() from within MyUC will trigger the binding of all its child controls which would defeat the purpose of the cache; also all user controls have been built so that they will not call DataBind() before the LoadComplete event has fired, so to make sure that the parent controls they live in has done its initialisation and has computed the properties that are declaratively passed to the child user control (ie PropA, PropB, PropC).And now the question: is there a way to bind the CacheProp property so to retrieve its value without data binding all other properties and without triggering the data binding of all its child controls?

View 1 Replies

VS 2010 User Control - No Bindable Property?

Nov 27, 2011

When I add a user control which has bindable properties to an asp.net page I do not see its bindable properties on the designer's dialog box when I click the edit Data bindings on the Repeater-Listview

Code:
Imports System.ComponentModel
<System.ComponentModel.DefaultBindingProperty("Text")> _
Public Class UserControls_ucSpecialTextBox
Inherits System.Web.UI.UserControl
...
<EditorBrowsable(EditorBrowsableState.Always), _

[Code] ....

View 6 Replies

Web Forms :: How To Access Parent's Property From User Control

Apr 13, 2010

I'm having trouble to access a Parent's property in User Control. I don't know how to access the parent. The Parent Page's name is Search.aspx. I saw the example below and tried it:

[Code]....

Than I could access the Parent's Property, but when I ran the website I got these errors:

1. The user control is not declared in the parent page
2. The user contol has a circular reference

View 3 Replies

Access Property Of Parent Page In User Control?

Oct 25, 2010

I have a hidden field on my default.aspx page. Within default.aspx page I have a user control which has a label on it. I need the label to display the value on the hidden field. How can I go about this?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved