473,385 Members | 1,769 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,385 software developers and data experts.

Treeview problem, get value from selected node in another usercontrol ? asp.net 2.0

Hi,

I have two usercontrols one menu control that use ASP.NET 2.0 Treeview
control, then a main usercontrol for showing the selected URL in a
Iframe.

The problem is when i raise the OnSelectedNodeChanged on the menu and
add the URL value into a session or Viewstate key and collect the value
on the second (main usercontrol) the value is always i step behind the
actual click value ?

Anyone have a solution on this ? can i get the value on the Treeview in
some other way then storing in a seperate session/viewstate key ?

Thanks
Jesper

Dec 17 '05 #1
3 2382
Hi Jesper,
I think your Main Usercontrol try to get the value too much early, in the
Page_Load.
Try to get the value in the Page_PreRender event handler.

Personally when I have to do a communication between User Controls, I raise
en event from the Provider Control,
I subscribe to the event from the Page which holds the controls, and in the
event handler I send a message to a public method of the Consumer Control.

I Hope this helps,

--
Daniel TIZON
MCP - MCSD.NET - MCT

<je************@yahoo.se> a écrit dans le message de news:
11*********************@z14g2000cwz.googlegroups.c om...
Hi,

I have two usercontrols one menu control that use ASP.NET 2.0 Treeview
control, then a main usercontrol for showing the selected URL in a
Iframe.

The problem is when i raise the OnSelectedNodeChanged on the menu and
add the URL value into a session or Viewstate key and collect the value
on the second (main usercontrol) the value is always i step behind the
actual click value ?

Anyone have a solution on this ? can i get the value on the Treeview in
some other way then storing in a seperate session/viewstate key ?

Thanks
Jesper

Dec 17 '05 #2
Hi, thanks for your answer. Think you have right that the main
usercontrol is trying to get the value before a new has been set.
Will try to get it in the PreRender method.

But if you have time i would really like to see a short exemple of your
solution for it. What to learn a new way to handle this and your
solution sounds intressting.

Thanks
Jesper

Dec 17 '05 #3
Ok, here is the scenario and the solution:
-I have 2 WebUserControls :
ProviderControls.ascx : it contains a TextBox and a Button.
ConsumerControl.ascx : it contains a Label
I have a WebForm called HostPage.aspx
The communication consist to pass the content of the textbox to the label
only when we click on the button

Code in App_Code folder : MyHandlers.cs
--------------------------------------------
public delegate void ConsumerControlEventHandler(object sender,
ConsumerControlEventArg e);
public class ConsumerControlEventArg : EventArgs
{
public string TheValue = string.Empty;
}

Code in ProviderControl.ascx.cs
-----------------------------------
public partial class UserControlsCommunication_ProviderControl :
System.Web.UI.UserControl
{
public event ConsumerControlEventHandler NewValue;
protected void cmdOK_Click(object sender, EventArgs e)
{
ConsumerControlEventArg arg = new ConsumerControlEventArg();
arg.TheValue = txtValue.Text;
NewValue(this, arg);
}
}

Code in ConsumerControl.ascx.cs
-----------------------------------
public partial class UserControlsCommunication_ConsumerControl :
System.Web.UI.UserControl
{
public string Param1
{
get
{
String s = (String)ViewState["Param1"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Param1"] = value;
}
}
void Page_PreRender(object sender, EventArgs e)
{
lblResult.Text = Param1;
}
}

Code in HostPage.aspx.cs
---------------------------
public partial class UserControlsCommunication_HostPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ProviderControl1.NewValue += new
ConsumerControlEventHandler(ProviderControl1_NewVa lue);
}

void ProviderControl1_NewValue(object sender, ConsumerControlEventArg e)
{
ConsumerControl1.Param1 = e.TheValue;
}
}
Have fun :)

--
Daniel TIZON
MCP - MCSD.NET - MCT

<je************@yahoo.se> a écrit dans le message de news:
11*********************@g47g2000cwa.googlegroups.c om...
Hi, thanks for your answer. Think you have right that the main
usercontrol is trying to get the value before a new has been set.
Will try to get it in the PreRender method.

But if you have time i would really like to see a short exemple of your
solution for it. What to learn a new way to handle this and your
solution sounds intressting.

Thanks
Jesper

Dec 17 '05 #4

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

Similar topics

4
by: Karim El Jed | last post by:
Hi, I'm trying to expand a special Node of my TreeView from Codebehind. I have a TreeView on a page for navigating to another site. On the other tsite here is the same TreeView more precisely a...
7
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made...
5
by: Juanjo | last post by:
I need to know how to maintain de status (nodes expanded and selected) of a treeview in a master page. I have a master page with a treeview. I have a default page, when the treeview is expanded...
0
by: Treeview Trouble | last post by:
I have an application where there are two radio buttons each of which populates a treeview control with a directory structure. Each radio button corresponds to a different directory which may or...
2
by: Claus | last post by:
Hello, I have a long treeview with scrollbars. When I scroll down and press a treeview node, then the Load event fires and navigate in an iframe to another page. The problem is, that afterwards...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
2
by: rfm | last post by:
I have a TreeView with 1 expanded top node, it has several childnodes (call it row A), which have childs of their own. The top node is selected correctly and all childnodes from the row A nodes...
1
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem...
0
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.