Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

How do I hide a control in a user control using ASP.NET C#

HI!
 I have an ASP.NET user control with 2 asp.net textboxes and AJAX calender extender controls beside them and an asp.net button. When the dates are selected and the button is clicked, the dates are sent as params to a SQL query and the data is displayed.
Some pages that use this user control use the user control as it is,(this works) but some pages use only the first text box and the button and some need just the 1st textbox.
For the ones that use 1 textbox and the button,  I need to hide the 2nd textbox and  calendar control. for the ones that use1st textbox only , I need to hide the button as well as the 2nd textbox and it's calendar control.

Could someone please help me with the logic for the scenario when only 1 textbox needs to be used by other pages without the button as well as with the button. .Any code/logic in C#  is greatly appreciated. Thankd a million in advance! It's a bit urgent!
0
amukta
Asked:
amukta
  • 3
  • 2
  • 2
  • +3
1 Solution
 
getnitincrCommented:
you can use the visible property in c#,
setting it to true or false as needed
0
 
Alpesh PatelAssistant ConsultantCommented:
IF Control modifier access is public then you can access that control in page
i.e. UserControl.TextBox1.Visible = false
0
 
meispiscesCommented:
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
maymounlbCommented:
create a public function in the user control to hide the controls you want
set the visibilty to false
and call this function from any page where you are using the user control
0
 
meispiscesCommented:
Is your problem solved?
0
 
amuktaAuthor Commented:
No..Not yet...the problem has not been solved yet.I did not meam to ide one of the user controls... I just need to hide a control soemthing like textbox in a user control for some of my pages.
0
 
amuktaAuthor Commented:
No..Not yet...the problem has not been solved yet.I did not meam to ide one of the user controls... I just need to hide a control soemthing like textbox in a user control for some of my pages.
0
 
cpetenesCommented:

Maybe add a true/false hide property to the usercontrol:

        private bool _hide = false
        public string HideSomething
        {
            get { return _hide; }
            set { _hide = value; }
        }
In the page load of the control check the property:

       protected void Page_Load(object sender, EventArgs e)
        {
}

0
 
cpetenesCommented:
Oops, let me try again.

Maybe add a true/false hide property to the usercontrol:

        private bool _hide = false
        public string HideSomething
        {
            get { return _hide; }
            set { _hide = value; }
        }
In the page load of the control check the property:

       protected void Page_Load(object sender, EventArgs e)
        {
             if(HideSomething)
                  somecontrol.Visible = false;
        }

And in the page where the control is used set the property in it's page load:

  myUserControl.Hide = true;
0
 
amuktaAuthor Commented:
Thanks a lot!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now