Click here to Skip to main content
15,891,764 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello
(I have a problem in desining a page. I created two user controls. in one user control i took the dropdown list, in second user control i took the label. i added these two user controls in one webpage. In drop down list i took the colors. When i change the value in drop down list it display the color according to that value in the second user control. and onething is dont take any events in the webpage it means button events. If it is possible How can I create this.
Can you Give me any idea. If it is possible give the sample code. It is very useful to me. or give any best tutorial site name because i new to the asp.net)

This is i asked the question last time. I get one reply.

Thank you for giving the solution. I tried your solution but it wont work. i think i may be write some mistake in my code can you correct me? i will send my code. to this mail
i wrote the code in dropdownusercontrol.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UserControlsExamples
{
public partial class DropDownUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DDColors_SelectedIndexChanged(object sender, EventArgs e)
{
LabelUserControl lblCtrl = (LabelUserControl)(FindControl("labelcontrol"));
Label lbl = (Label)(lblCtrl.FindControl("labelcontrol"));
//lbl.BackColor = System.Drawing.Color.FromName(DDColors.SelectedValue);
lbl.Text = DDColors.SelectedItem.Text;
}
}
}

//The code in LabelUsercontrol.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UserControlsExamples
{
public partial class LabelUserControl : System.Web.UI.UserControl
{
public Label Display_Label
{
get
{
return this.DisplayLabel;
}
set
{
this.DisplayLabel = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}

can you look at this code and tell me what i did wrong
and i didnt write any code in .aspx.cs file
Posted
Updated 7-Apr-11 2:28am
v3
Comments
Toniyo Jackson 7-Apr-11 8:14am    
Added pre tag for code
[no name] 7-Apr-11 8:19am    
If you are referring to an answer you have previously received then it would be helpful to supply a link. No one is going to search through the history to find what you are talking about.

Why are you creating custom controls for this anyway? What problem are you trying to solve?

1 solution

Surely this is a followup of some other answer, yet:
This is not the correct way:
Label lbl = (Label)(lblCtrl.FindControl("labelcontrol"));

Instead of this, once you have the usercontrol with you, directly refer the Display_Label property exposed.

Thus, this should do:
Label lbl = lblCtrl.Display_Label;


Try to understand how properties are exposed and used. Hit-n-Try would not help much.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900