I’m CSSing my project and would like to customize the font color for the feedback label. My project is built in 3 layers (DAL, BLL, normal page). In the BLL I catch exceptions and I guess this is where I would add the CSS stylesheet reference. Unfortunately, I can’t get it to work, this is what it looks like.
BLL
Public Function deleteCustByCustID(ByVal CustID As Integer) As Boolean
If dataCust.DeleteCust(Cust) Then
Throw New Exception("The customer was removed.")
Return True
Else
Throw New Exception("The customer wasn't removed. Please try again.")
Return False
End If
End Function
ASPX.vb page
Try
bllCust.deleteCustByCustID(CustID)
Catch ex As Exception
lblFeedback.Text = ex.Message
End Try
I have my CSS pages stored in a CSS folder. I would like to assign the font color lime to a success and the font color red to a failure.
Any help is much appreciated!
Another option: if you have assigned an ID value to the markup for your “feedback” area, and if you added a
runat="server"to that element, you can access theCssClassproperty in your code-behind file.By way of example:
Markup
Code
Then you can use the CSS rules denoted by @rockerest in his answer.
EDIT:
Okay, I looked at your code again, and I see a big problem: you should NEVER use exceptions as a method of controlling program flow. That is probably error #1.
A not-too-uncommon method of returning a more meaningful result from your methods is to encapsulate a result object. Here is a simple example:
You would amend your current function to return a
Resultobject instead ofBoolean, and assign the values of theResultobject depending on your query results:Then, in whatever code calls the
deleteCustByCustIDmethod, you assign theMessageproperty to the content of the feedback area and theCssClassthat matches theIsValidstate.Make sense?
EDIT 2:
Okay, assuming you have a CSS class for errors, “.error” and a CSS class for, uh, not errors, “.success”. Then, let’s pretend the following snippet was inside an event handler or somesuchthing:
Now you have a
Resultobject that has aIsValidstate value (it will be either true or false) and aMessagestring value. Your next step is to apply the message to the feedback element’s (I’ll assume here that you use an ASP.NETLabelcontrol)Textproperty, and then, based on the value ofresult.IsValid, assign the correct class to the label’sCssClassproperty:HTH.