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

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.

Related

Adding line-height style to a label in asp.net

In my webpage there is label having multiple lines of text.
I need to add line-height property to that label in asp.net.
Thanks.
There are 2 ways to do this.
1) add a style for this. and give cssClass for that label.For example,
.line
{
line-height:150%;
}
And add the class to your label.
<asp:Label ID="Label1" runat="server" cssClass="line" />
2) Add style in code behind
Label1.Style.Add("line-height","150%");
Change the line-height value to whatever you want
Try below code:
LabelID.Style.Add("line-height", "100px")

is there a way to increase the length tooltip is displayed in asp.net chart?

I have a chart that displays a tooltip (string) when hovered over. Is there a way to control the delay/time the tooltip is displayed to the user?
<asp:Chart runat="server" ID="Chart2" Width="340px" Height="265px">
<!--Define Things in here-->
</asp:Chart>
Backend:
//define what rec is
string tooltip = rec;
Chart2.ToolTip = tooltip;
I just came up with a pretty simple solution to this classic problem with the help of some Javascript I borrowed from here: http://bonrouge.com/~js_tooltip
Asp.NET renders tooltips as a title attribute on the actual HTML page generated. You can take advantage of this fact to apply whatever style you like to the tooltip by overriding it with two very simple javascript functions.
function showTooltip(control) {
var ttext = control.title;
var tt = document.createElement('SPAN');
var tnode = document.createTextNode(ttext);
tt.appendChild(tnode);
control.parentNode.insertBefore(tt, control.nextSibling);
tt.className = "tooltipCss";
control.title = "";
}
function hideTooltip(control) {
var ttext = control.nextSibling.childNodes[0].nodeValue;
control.parentNode.removeChild(control.nextSibling);
control.title = ttext;
}
Next you need to design your css for your tooltip:
position:absolute;
border:1px solid gray;
width:300px;
margin:1em;
padding:3px;
background: Red;
Finally you need to wire up the JavaScript to your control
Chart2.Attributes.Add("onmouseover", "showTooltip(this)");
Chart2.Attributes.Add("onmouseout", "hideTooltip(this)");
Hope this helps.... I've been looking for a SIMPLE way of doing Tooltips for all my Asp.Net stuff for ages. I don't like to declare my Tooltip code in separate spans or whatever as this is really no good for my dynamically generated stuff. Anyway I just wanted to add this somewhere online. Hope it helps someone out.
Sorry, but probably not.
Most tooltips are a browser feature, and display either the alt tag of an img, or the title tag of most elements. So the control of how long that tooltip displays is going to vary from browser to browser.
It's possible that the tooltip is under your control, and is an html element displayed with javascript on mouseover, or the charts and the tooltip might be in Flash or Silverlight, but if that's the case we'd need to see your code.
I'm guessing probably not. If you need more flexibility I would recommend going with a jQuery tooltip solution.
To add to Ravendarksky's answer: I used his code but if I moved my mouse during the mouseout event over the tooltip content, IE would issue an unhandled exception (no issues in Chrome, I did not check Firefox):
0x800a138f - JavaScript runtime error: Unable to get property 'nodeValue' of undefined or null reference
So I simply wrapped the implementation of hideTooltip in a conditional checking for null and all was well in IE [and Chrome]:
function hideTooltip(control) {
if (control.nextSibling.childNodes[0] != null) {
var ttext = control.nextSibling.childNodes[0].nodeValue;
control.parentNode.removeChild(control.nextSibling);
control.title = ttext;
}
Or you can use HoverMenuExtender of asp.net. You can also modify the pop up content/design.
Code reference sample here: http://asp-net-example.blogspot.com/2009/11/ajax-hovermenuextender-how-to-use.html

default border color for .net textbox

I change the border style and border color on a .net textbox to solid red respectively. After a postback I am attempting to return the textbox to its default values, but I cannot seem to get the color right. I have googled this, and tried to get the default values in the debugger, but the values in the debugger always look too dark of a gray when applied. Is there an easy way to return to the default look and feel of a textbox?
try this:
TextBoxTitle.BorderColor = System.Drawing.Color.Empty;
You can write two CSS classes:
.tb_with_border {
border: 1px #FF0000 solid;
}
.tb_without_border {
border: none;
}
.. and then you can change styles by assigning CssClass property of your textbox, for example:
Textbox1.CssClass = "tb_without_border";
or in markup:
<asp:TextBox id="Textbox1" runat="server" CssClass="tb_with_border" />
If you're just switching the particular element style off then this works:
Textbox1.BorderColor = Nothing
You should be using CSS to do this anyways...
Textbox1.Style.Remove("border")
txt_TextBox.BorderColor = System.Drawing.Color.Empty;
txt_TextBox.BorderStyle = BorderStyle.NotSet;
Simple. Add another textbox or dropdownlist with default values and make it hidden.
To RESET to defaults, just set your textbox's border color, width and style to that of the hidden textbox like so:
txtMyTextBoxToReset.BorderColor = txtHiddenTextBox.BorderColor;
txtMyTextBoxToReset.BorderWidth = txtHiddenTextBox.BorderWidth;
This works in all browsers and works for Drop down lists as well

Line break in Label

when i m writing a long sentence in label without line break then it does wrap automatically.
i m putting that label in tag. how can i wrap that long sentence.
Unclear, but you can force a line break by adding a <br /> in it.
<label>Some long long long long long long<br /> long long long label</label>
create style sheet like this "
.label { word-wrap: break-word }
and assign to you label
check the link for more detail : http://www.css3.com/css-word-break/
I'd hesitate to use the CSS3 solution without some kind of IE fallback.
You need to add the following CSS to your label:
label { display: block; width: 100px; }
Then change the width to the width you'd like your label to be and the sentence will wrap within the space.
By default a label has inline display which makes width control difficult.
If you still need the label to be inline with your input field, float the label.

Applying html formating in label control

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);

Resources