Applying html formating in label control - asp.net

The html formating is applied great in this case.
The Surname is displayed with size 5.
lblWelcome.Text = "Welcome:<font size=''5''>" & txtSurname.Text & "</font>"
Why the html style is not applied in this example?
lblWelcome.Text = "Welcome:<font color=''white''>" & txtSurname.Text & "</font>"

Please, please, please don't use font tags. Also, if you really want to output HTML from the server side then you should be using a Literal control.
Here is an example of how I would do it:
aspx/ascx file:
Welcome: <asp:Literal id="lit1" runat="server" />
code behind:
lit1.Text = "<span class='welcome'>" & txtSurname.Text & "</span>"
OR your other example:
lit1.Text = "<span class='welcomeBig'>" & txtSurname.Text & "</span>"
css:
span.welcome { color:#fff; }
span.welcomeBig { font-size:24px; }
Hope this helps

As an alternative, you could use the ASP.NET Literal web control and set its Mode property to Encode or Transform.
Literal1.Mode = LiteralMode.Encode
Literal.Text = "Welcome:<font color='white'>" & txtSurname.Text & "</font>"
In the above code, the HTML elements will be transformed into proper HTML, leaving just the surname text in white.

You could just set the ForeColor property on the Label.
lblWelcome.Text = txtSurname.Text;
lblWelcome.ForeColor = "white";
You'd have to put the 'Welcome' outside the label, but it would probably make more logical sense.
Welcome:<asp:Label id="lblWelcome" runat="server" />

Also don't forget to HTML encode the surname: Server.HtmlEncode(txtSurname.Text);

Related

Need to change textcolor inside textarea with hiddenfield results

I have a form, which has a text area. I want to be able to set the text color of the text inside of the text area when they click the color intended.
So far, I have it to where when they click the color, it sets the hex color inside of a hiddenfield. How could I go about changing the textcolor with css based on the hiddenfield results.
I don't think I can alter the CSS with the GET/POST method, because I want the color to change immediately, not only when the form is posted. Is there a way to do this with either javascript or PHP?
I use the setting of the color to the hiddenfield using (through the img src):
onclick="document.getElementById('color').value = '#ffffff'; " />
HERE IS A JSFIDDLE OF WHAT I HAVE SO FAR:
jsfiddle.net/ymG6t
Ok I figured it out! Instead of using
onclick="document.getElementById('color').value = '#ffffff'; " />
I used: onclick="document.getElementById('color').style.color = '#ffffff';" />
onto the field itself. No need for the hiddenfield!
I have a solution. copy and paste code below:
<script>
function change_color(col){
if ( col == 'red'){
document.getElementById("text").style.color = '#f00';
}
if ( col == 'green'){
document.getElementById("text").style.color = '#0f0';
}
if ( col == 'blue'){
document.getElementById("text").style.color = '#00f';
}
}
</script>
<form>
<input type='radio' onchange="change_color(this.value)" name='color' value='red' >Red<br>
<input type='radio' onchange="change_color(this.value)" name='color' value='green' >Green<br>
<input type='radio' onchange="change_color(this.value)" name='color' value='blue' >Blue<br>
Text:<textarea id='text'>Here is the text that you want to change it's color</textarea>
</form>
Save into a new file with *.php extension.
If you want to save it as html, you must add html tag for header, body and other such as <html> in the beginning, <head>, and then <body>, and of course with it's close tag.
use it as a reference, you can modify the code/script as you need.
may it help! :D

how to bind image in Listbox with data

Hi all i have one problem in list box in which i would like to bind image with data on condition . Like when user is active i like to display different image , when he is not working like to display different image . this time i am displaying name in different color on his status like not working then in Red color, working with green color.
My html is
<asp:ListBox ID="ddlDriver" Width="100%" AutoPostBack="true" OnSelectedIndexChanged="ddlDriver_SelectedIndexChanged"
runat="server" BackColor="White" Height="380px">
</asp:ListBox>
Code :
if (_driv.DriverStatus == 1)
{
ddlDriver.Items[i].Text = ddlDriver.Items[i].Value + "-" + ddlDriver.Items[i].Text + " " + OrderTota;
ddlDriver.Items[i].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "red");
}
else if (_driv.DriverStatus == 2)
{
ddlDriver.Items[i].Text = ddlDriver.Items[i].Value + "-" + ddlDriver.Items[i].Text + " " + OrderTota;
ddlDriver.Items[i].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "green");
}
please help me about this issue.
You may define two css classes with appropriate background-image property and conditionally set class on items in code-behind

how to preserve the orgianl backgroundColor when hovering?

below is the code that works fine but the only problem i have is : its overriding the alternative row with backgroundColor='white' how can i have my orginal alternative color when onmouseout ?
<AlternatingRowStyle BackColor="#DEEEE9" Font-Size="8pt" />
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
e.Row.Attributes.Add("style", "cursor:pointer;");
}
You can specify what color exactly should be restored on onmouseout:
if (e.Row.RowType == DataControlRowType.DataRow)
{
string bgcolor = "white"
if (e.Row.RowState == DataControlRowState.Alternate)
{
bgcolor = "#DEEEE9";
}
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + bgcolor + "'");
e.Row.Attributes.Add("style", "cursor:pointer;");
}
I don't get it, why not just take out the "e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");" and set it to the color of the original alternate???
instead of specifying a specific color, use the hover css attributes.
See:
http://www.codeproject.com/KB/webforms/MouseHoverUsingCSS.aspx
Try something like this:
var color = "<%=System.Drawing.ColorTranslator.ToHtml(GridView1.AlternatingRowStyle.BackColor)%>";
This works well with much less code. Create a custom attribute in the mouseover before setting the backgroundColor and use it on the mouse out. Works perfectly for alternating row colors.
row.Attributes["onmouseover"] = this.originalstyle=this.style.backgroundColor;this.style.cursor='hand';this.style.backgroundColor='#ffccff';";
row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.backgroundColor=this.originalstyle;";

Using <b> in fckeditor

i want to print some default string value in bold but i am using tag but it is not rendered as bold rather it is showing it is printing the same etc
var defaultFCKValue = '----Original Message---- \n';
defaultFCKValue += '<b>From:</b> ' + from + '\n';
defaultFCKValue += '<b>Sent:</b> ' + date + '\n';
defaultFCKValue += $('div.popupContent div div.message').html();
var oEditor = FCKeditorAPI.GetInstance("<%=FCKeditorSelfDocument.ClientID %>");
var oDOM = oEditor.EditorDocument;
oDOM.body.innerText = defaultFCKValue;
The problem is that the <b> tags are being escaped/encoded and are being rendered as <b>
You might want to try using
oEditor.setHtml(defaultFCKValue)
See the js docmentation for fckeditor.
Try <strong> rather than <b>, as <b> tags have been depreciated in most doctypes. It may not directly solve your problem, but it is at least good practice.

ASP.NET How can i add superscript into a label control?

For example currently, the value is set with lblAmount.Text = Amount & " €"
How can i add (dynamically) superscript to the € sign?
use the SUP tag.
lblAmount.Text = Amount & "<sup>€</sup>"
You do this best by adding either a style attribute or by adding a class (and adding the style in a style tag or a css file.
<asp:Label id="lblAmount" runat="server"></asp:Label><asp:Label id="lblAmountSymbol" runat="server" CssClass="yourclass"></asp:Label>
span.yourclass {
font-size:9px;
vertical-align:top;
}
or
<asp:Label id="lblAmount" runat="server"></asp:Label><asp:Label id="lblAmountSymbol" runat="server"></asp:Label>
and this, in your code file
Me. lblAmount.Style.Add(HtmlTextWriterStyle.FontSize, "9px")
Me. lblAmount.Style.Add(HtmlTextWriterStyle.VerticalAlign, "top")
You could also use the html equivalent sup:
Me. lblAmount.Text = Amount & " <sup>€</sup>"
Goto Start->Programs->Accessories->System tools->Character Map
Now select this Character ² from the Characters listed.
Click Select
Click Copy
Then try to change the text of any control by pasting this Character in the Lable or Button Caption at Properties.
Even you can wrting code also like this:
Code\Button1.Text = "mm ²"\Code
This is working fine with me.

Resources