473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Accessing a property in a webcontrol from parent page

Hi!

Could someone please help me with the following; I have a WebControl that
basically looks like this:

public class LeftMenu : System.Web.UI.WebControls.WebControl
{
private string m_CurrentNodeId = string.Empty;

public string CurrentNodeId
{
get
{
return m_CurrentNodeId;
}
}

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

private void custExpand_Click(object sender,EventArgs e)
{
m_CurrentNodeId = e.SomeStringValue;
}
}

Which I'm loading into my parent page like this:

public class Default
{
protected LeftMenu mmLeftMenu;
protected System.Web.UI.WebControls.Panel pnlLeftMenu;
public string CurrentNodeId = String.Empty;

private void Page_Load(object sender, System.EventArgs e)
{
mmLeftMenu =
(LeftMenu)LoadControl(pnlLeftMenu,@"~\Controls\Lef tMenu.ascx");
CurrentNodeId = mmLeftMenu.CurrentNodeId;
}
}

Problem is CurrentNodeId in Default never gets the value of
mmLeftMenu.CurrentNodeId, because custExpand_Click gets fired after the
Page_Load in Default. How should I set things up, so that I can get the
value of mmLeftMenu.CurrentNodeId in Default???

Thanks.
Nov 18 '05 #1
3 1435
What you have here is an issue of sequence. This problem is fairly common,
esp. among newer developers of ASP.Net, as the .Net SDK seems to have a lot
of samples using the Page_Load event. In point of fact, however, the
system.Web.UI.Page class is derived from System.Web.UI.Control, and every
Control has about a dozen event handlers that you can wire up, all of which
occur in a specific sequence. To find out more about the sequence of events,
see:

http://msdn.microsoft.com/library/de...nLifecycle.asp

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"spmm#" <sp******@yahoo.com> wrote in message
news:41***********************@news.xs4all.nl...
Hi!

Could someone please help me with the following; I have a WebControl that
basically looks like this:

public class LeftMenu : System.Web.UI.WebControls.WebControl
{
private string m_CurrentNodeId = string.Empty;

public string CurrentNodeId
{
get
{
return m_CurrentNodeId;
}
}

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

private void custExpand_Click(object sender,EventArgs e)
{
m_CurrentNodeId = e.SomeStringValue;
}
}

Which I'm loading into my parent page like this:

public class Default
{
protected LeftMenu mmLeftMenu;
protected System.Web.UI.WebControls.Panel pnlLeftMenu;
public string CurrentNodeId = String.Empty;

private void Page_Load(object sender, System.EventArgs e)
{
mmLeftMenu =
(LeftMenu)LoadControl(pnlLeftMenu,@"~\Controls\Lef tMenu.ascx");
CurrentNodeId = mmLeftMenu.CurrentNodeId;
}
}

Problem is CurrentNodeId in Default never gets the value of
mmLeftMenu.CurrentNodeId, because custExpand_Click gets fired after the
Page_Load in Default. How should I set things up, so that I can get the
value of mmLeftMenu.CurrentNodeId in Default???

Thanks.

Nov 18 '05 #2
You might need to make your webcontrol raise an event when custExpand_Click
is hit, which the page can hook into...something like

public class LeftMenu: WebControl{
public event CommandEventHandler NodeClick;
...
private void custExpand_Click(object sender,EventArgs e) {
m_CurrentNodeId = e.SomeStringValue;
if (this.NodeClick != null){
CommandEventArgs ev = new CommandEventArgs("clicked",
m_CurrentNodeId);
this.NodeClick(this, ev);
}
}
}

the in your page, you can:

page_load{
mmLeftMenu =
(LeftMenu)LoadControl(pnlLeftMenu,@"~\Controls\Lef tMenu.ascx");
mmLeftMenu.NodeClick += new CommandEventHandler(mmLeftMenu_NodeClick);
}

private void mmLeftMenu_NodeClick(object sender, CommandEventArgs e) {
Response.Write("node value: " + e.CommandArgument);
}
Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"spmm#" <sp******@yahoo.com> wrote in message
news:41***********************@news.xs4all.nl...
Hi!

Could someone please help me with the following; I have a WebControl that
basically looks like this:

public class LeftMenu : System.Web.UI.WebControls.WebControl
{
private string m_CurrentNodeId = string.Empty;

public string CurrentNodeId
{
get
{
return m_CurrentNodeId;
}
}

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

private void custExpand_Click(object sender,EventArgs e)
{
m_CurrentNodeId = e.SomeStringValue;
}
}

Which I'm loading into my parent page like this:

public class Default
{
protected LeftMenu mmLeftMenu;
protected System.Web.UI.WebControls.Panel pnlLeftMenu;
public string CurrentNodeId = String.Empty;

private void Page_Load(object sender, System.EventArgs e)
{
mmLeftMenu =
(LeftMenu)LoadControl(pnlLeftMenu,@"~\Controls\Lef tMenu.ascx");
CurrentNodeId = mmLeftMenu.CurrentNodeId;
}
}

Problem is CurrentNodeId in Default never gets the value of
mmLeftMenu.CurrentNodeId, because custExpand_Click gets fired after the
Page_Load in Default. How should I set things up, so that I can get the
value of mmLeftMenu.CurrentNodeId in Default???

Thanks.

Nov 18 '05 #3
Thanks to both of you! Karl your solution works perfectly.
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
I am looking for a easy way to trap an Exception that may occurr in any one of 30 child web controls to be trapped at the topmost parent WebUser control or Page Level. I have tried variations of...
2
by: eagle | last post by:
How do I access a control, like a placeholder, from another page, or another user control that may be on the same page. For instance, I have a web page with 2 user controls. One user controls...
1
by: Jeremy Chapman | last post by:
I have a property will an array of webcontrols. The control features a custom property editor which can add and remove web controls to the array, but how do I persist the informtion by...
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
6
by: Steve | last post by:
I'm trying to iterate over all the form controls in my MasterPages content page. Basically, I've got dropdowns, textboxes, etc that I want to format in Page_Load() I've added this code to my...
1
by: Charles Zhang | last post by:
I created a custom server control that derives from WebControl. I found Parent and Page property are null for the control I created. But Parent is a readonly property so that I have no way to...
1
by: shapper | last post by:
Hello, I have a class where I created various controls. One of the controls have a property which is a generic list of WebControl. Then in web site page I have something like: Dim a As New...
4
by: nottarealaddress | last post by:
I'm trying to get my feet wet in VB2005 (our new standard at work after officially stopping new development in VB6 about a month ago). I'm working with a simple sql 2005 table of 50 entries, one...
5
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.