?
Solved

How can I hide or show User Controls

Posted on 2004-10-18
2
Medium Priority
?
241 Views
Last Modified: 2008-02-01
ok, I'm a new asp.net programmer.  I have created an webform which will become a Order Entry screen.  Basicly I have 10 questions to ask the user in order to get the correct Item selected.  Currently I have 10 User Controls with each one containing one of the 10 questions.  Most user controls contain a table and within that table either a drop down list, buttons or datagrids.

Here is what I need help with.  Sometimes all 10 question don't have to be answered.  Depending on their selectons (as an example) for the frist question, might make question #8 irrelevant.  So in that case I would want to hide Question #8.  No need to show the user a question they don't have to answer.  So I want to turn that question invisible based on the answer of question #1.  I currently load all 10 user controls in on the page Init of the main form.  So how can I turn these user controls on and off as the fill out the form?  Also there is no specific reason why I put the questions in user controls.  If there is some other way to show and hide questions that is better, please let me know.  

And remember I am a new program, so any syntax you can provide or sample code would be greatly appreciated!!!

Thanks for your help!
0
Comment
Question by:accmats
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
tusharashah earned 2000 total points
ID: 12338555
You can do it with one of the following way:

1)
 -  Make a Table RunAsServer Control.
 -  Drag & drop different control on different row.
 -  Show/Hide rows using Table1.Rows[0].Visible = false/true;

2)
 -  Drag each User Control in different Panel.
 - Show/Hide Panel using Panel1.Visible = false/true;

-tushar
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 12338575
Every control that is visible on a page has a .Visible property. On the server you can access this property to show or hide a usercontrol

Example code

Protected WithEvents __uc as YourUserControl

Private Sub Page_Load(ender as Object, e as System.EventArgs)
  If(Page.IsPostBack) Then
    __uc.Visible = False
  End If
End Sub

However, when there is no postback, you will need to do something on the client. Therefore you will need to know the id of the object you want to hide. With javascript you can then manipulate the visibility of an object (style.display).

For example:

Add the following javascript code:

<script language="javascript">
<!--
function visibility(id, vis){
  var o = document.getElementById(id);
  if(o) o.style.display=(vis?"block":"none");
}
//-->
</script>

And you can add this to, for example, a button

<asp:button runat="server" onClientClick="visibility('theIDofyourobject', false)" />
<asp:button runat="server" onClientClick="visibility('theIDofyourobject', true)" />

But you might be better of to use the first approach and a postback after the user has finished a question.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

771 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