Append text to label in ASP.NET/C#? [closed]

Onreybbry

New Member
Lets say I have a form where the user enters some data and then click Submit. I have some validation to check length of fields in the code behind and if they forgot the name I set the text in a label:\[code\] if (siteName.Length == 0) { lblErrorCreateSite.Text = "A Site Name is required.<br/>"; }\[/code\]If I also have a field called description and this is also empty can I append an error message to lblErrorCreateSite or do I have to create another label?\[code\] if (siteDescription.Length == 0) { lblErrorCreateSite. // if both name and description is missing add some additional text to the label }\[/code\]I'm just checking to see if there's an easier way than to have a lot of if statements (if this AND that...)Thanks in advance.Edit:I just realized I can do\[code\] if (siteName.Length == 0) { lblErrorCreateSite.Text = "A Site Name is required.<br/>"; } if (siteDescription.Length == 0) { lblErrorCreateSite.Text = lblErrorCreateSite.Text + "A description is required."; }\[/code\]?
 
Top