Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
1) How we will specify in user control behave differently for two web pages.

2) As i have one user control which is to be used in two webpages.But i need to make some controls to be invisible.
Posted
Updated 16-Feb-13 18:45pm
v2

can we use one user control in multiple asp.net webpage by making some controls invisible
Yes.

How we will specify in user control behave differently for two web pages.
By exposing controls via defining user control public properties or using FindControl method. Once you have reference to the control, set the visibility.
 
Share this answer
 
v2
Your user control can take parameters so that each page can pass different parameters. Depending on this parameter, you can turn on/off features in the control.

Eg:
ASP.NET
<user:MyControl id="myUserControl" runat="server" CustomProperty="Some Value" ></user:MyControl>
 
Share this answer
 
You must create parameters in User Control on behalf of those parameters you can hide/show controls.
 
Share this answer
 
means u want to make controls visibility as per ur requirements, which u have added in user control.
then u have to declare property in user control using get set assign them to control

i.e if u have button in user control and u want to make is visible false as per ur requirements ,Then create property
C#
public bool BtnVisibility
{
get
{
}
set
{
btn1.Visible= value;
}
}



value for visibility u have to pass from page where u have added ur user control
like follows
MyUserControl.BtnVisibility = false;

refer following article.They have created user control and assing values to lable on page.Same way do for control visibility.
http://www.dotnetfunda.com/articles/article16.aspx[^]
 
Share this answer
 
Comments
Member 9840927 17-Feb-13 11:43am    
Thank u but i am not getting user control name in aspx page error like it is a field but used as type
Pallavi Waikar 17-Feb-13 11:51am    
have u added reference of that user control on ur page..and also check for runat attribute <myCtr.MyUserControl id="MyUserControl" runat="server"/> in .aspx page...for help check following link. http://msdn.microsoft.com/en-us/library/c0az2h86%28v=vs.100%29.aspx

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