Hide my icon

What I want to achieve is when the user entered the wrong data, the image label will be displayed.

The visible method is not recommended due to my lblMessage service for other purposes.

My big big problem now that users have corrected their input field, the label message is disabled, but the image is still visible, simply because I set lblMessage to null .

Is there any method that I can use, for example, when there is something to have lblMessage call the CSS image, but whenever there is nothing in lblMessage, css does not start?

 if (!Utils.mtdIsBlank(Session["Message"])) { lblMessage.Text = Session["Message"].ToString(); Session["Message"] = null; } else { lblMessage.Text = ""; } 
+4
source share
1 answer

It seems your problem is that you do not know how to add / remove styles for your asp.net controls. You can use CssClass for asp.net controls (label, panel, ...) as follows:

 lbl.CssClass = "new-class"; 

For your example, something like this should work for you:

 if (!Utils.mtdIsBlank(Session["Message"])) { //If is not blank no image lblMessage.Text = Session["Message"].ToString(); Session["Message"] = null; lblMessage.CssClass = "no-img"; } else { //Show alert image lblMessage.Text = ""; //Replace with-img with the css class you are using lblMessage.CssClass = "with-img"; } 

Then you need to add the css property:

 .no-img{ background: none; //Anything else } 
+2
source

Source: https://habr.com/ru/post/1447694/


All Articles