Solved

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

Posted on 2010-11-28
10
460 Views
Last Modified: 2012-08-14
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
Comment
Question by:amukta
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 2

Expert Comment

by:getnitincr
ID: 34227906
you can use the visible property in c#,
setting it to true or false as needed
0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34228169
IF Control modifier access is public then you can access that control in page
i.e. UserControl.TextBox1.Visible = false
0
 
LVL 7

Expert Comment

by:meispisces
ID: 34228230
0
 
LVL 2

Expert Comment

by:maymounlb
ID: 34228853
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
 
LVL 7

Expert Comment

by:meispisces
ID: 34231069
Is your problem solved?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:amukta
ID: 34231454
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
 

Author Comment

by:amukta
ID: 34231457
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
 
LVL 1

Expert Comment

by:cpetenes
ID: 34233457

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
 
LVL 1

Accepted Solution

by:
cpetenes earned 500 total points
ID: 34233477
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
 

Author Closing Comment

by:amukta
ID: 34284597
Thanks a lot!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now