1

I am working on asp.net webforms. I have a usercontrol which has several server controls. There are three related dropdown boxes. If there are multiple values on all these dropdown boxes, I have to let the user choose values from them and then I save them in database. If each one of them has only one value, then I have to show the values as read only - say as asp.net labels. These values also need to be saved in the database. Please let me know how to replace one set of controls with another and get their values.

Thanks

2
  • You can display drop downs as read only without making them labels - would this fulfill your requirement? Commented Feb 27, 2013 at 19:25
  • Unfortunately no! The users say they can't read through the greyed out controls :( Commented Feb 27, 2013 at 19:37

1 Answer 1

1

So to show one set of controls over the other, consider the following HTML:

<asp:DropDownList ID="List1" runat="server" Visible="false" />
<asp:DropDownList ID="List2" runat="server" Visible="false" />
<asp:DropDownList ID="List3" runat="server" Visible="false" />
<asp:Label ID="Label1" runat="server" Visible="false" />
<asp:Label ID="Label2" runat="server" Visible="false" />
<asp:Label ID="Label3" runat="server" Visible="false" />

if you want the drop down lists visible then run this in the code-behind where relevant:

List1.Visible = true;
List2.Visible = true;
List3.Visible = true;

and in contrast, if you want the labels visible then run this code:

Label1.Visible = true;
Label2.Visible = true;
Label3.Visible = true;

Please note that when a control in ASP.NET is not visible - it's not rendered. So the control is not included in the HTML. This is why I set all of them to invisible to start with.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.