Conditional user interface in ASP.NET

T

Terence

Dear all,

I am converting an asp application to aspx and encountered a problem.
The problem is that i need output different html code based on some
condition. For example,
in asp, there is a variable (let say, bEditMode), if bEditMode= false, then
the page display the value in text.
If the bEditMode = true, then it should display textbox rather than just the
text.
In asp, it can be done easily by:

if bEditMode Then
Response.Write "User Name from database"
Else
Response.Write "<input type=""text"" />"
End If

How can I do this in aspx ?

Thanks in advance.

Terence
 
O

Oliver

Hi Terence,

The easiest way is to put both controls on the page. Then you can just
switch their Visible property:

Label1.Visible = bEditMode
TextBox1.Visible = Not bEditMode

Of course you could get fancy and create the controls in code and assign
them to a placeholder control but it probably isn't worth the effort.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top