Event within an Event Issue

T

Tim.Forbess

Using asp.net 2.0 I have a web project with one page which contains 2
user controls. One user control is a message bar with a label control
and the other user control that contains a treeview control.

I created an event on the tree user control to publish any error
messages back to the page. The page in turn will call a method on the
message bar control to show the message in the label.

The tree control has some nodes populate during On_Load no problem. One
node has its child nodes populated from a database. I do this using the
treeview event OnTreeNodePopulate.

The problem is during the processing of the OnTreeNodePopulate event I
fire the event to publish an error message but the message bar label is
not updated. I've traced the code and the error message event is passed
to the page which calls the message bar control which updates label
control with the error text, but when the page is returned there is no
text in the label still.

My only thought is maybe because i'm firing an event (my error event)
within an event (tree's OnTreeNodePopulate event) that is somehow the
issue?

Thanks in advance
 
T

Tim.Forbess

Simplified the example. Forget the user controls. The behavior exists
simply trying to update a label on the page from the tree control's
OnTreeNodePopulate event with an event. Very simple code below
reproduces the behavior. Ideas???

-----------default.aspx------------
<%@ Page Language="C#" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
this.MessageEvent += new
MessageEventHandler(HandleMessageEvent);
}

public void HandleMessageEvent(string msg)
{
MessageLabel.Text = msg;
}

public void OnPopulate(Object sender, TreeNodeEventArgs e)
{
OnMessageEvent("populating");
}

public delegate void MessageEventHandler(string msg);
public event MessageEventHandler MessageEvent;
public void OnMessageEvent(string msg)
{
if (MessageEvent != null)
MessageEvent(msg);
}
</script>

<html>
<head runat="server"><title>Test</title></head>
<body>
<form id="form1" runat="server"><div>
<asp:TreeView ID="TreeControl" runat="server"
OnTreeNodePopulate="OnPopulate">
<Nodes>
<asp:TreeNode Text="Root" Expanded="False"
PopulateOnDemand="true"></asp:TreeNode>
</Nodes>
</asp:TreeView>
<asp:Label ID="MessageLabel" runat="server"
Text=""></asp:Label>
</div></form>
</body>
</html>
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top