Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2008, 04:02 AM
Registered User
 
Join Date: May 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default user control in user control

Hi,
I have a user control that is used in several other user controls.
The control has some buttons and i want to set their properties from let's say from one of the user controls. i have this code:

protected Button btnPrevious;

and the property
public bool EnabledPrevious { get { return btnPrevious.Enabled; } set { this.btnPrevious.Enabled = value; } }

from the other user control i have this code in the Page_Load method:

WebControl1 Top = new WebControl1();
Top = (WebControl)Page.LoadControl("path to the control");
Top.EnabledPrevious = false;

but the button Previous remains Enabled.
Can please anyone help me?

All i figure it out is that the property is set but ultimately it isn't processed, and remains true
 
Old May 2nd, 2008, 07:55 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Let's decompose your code:

WebControl1 Top = new WebControl1(); //<-- Creates a new instance of the control class
Top = (WebControl)Page.LoadControl("path to the control"); //<-- Loads the control from the source file, overwriting the previously created instance

You are creating new instance of the control, where you really need to get at the instance created by the markup that include the control. Unless the instance "Top" is the one getting added to the container (the outer user control) this code will do nothing.

Presumably in your outer control markup you have an instance of the control. You need to access that instance by the ID provided in the markup. Then you can manipulate its properties and disable the button.

-Peter
peterlanoie.blog
 
Old May 2nd, 2008, 08:42 AM
Registered User
 
Join Date: May 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes that was the problem.
i did't need to make new instance. i just needed to take the id from the markup.
thanx






Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM
Help with control initialization in user control mike_remember ASP.NET 1.0 and 1.1 Professional 7 December 19th, 2005 11:08 AM
user control nashnash ASP.NET 1.0 and 1.1 Professional 6 November 8th, 2004 09:55 PM
User Control stu9820 ASP.NET 1.0 and 1.1 Basics 20 July 20th, 2004 11:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.