I need to get the default font-name of text from a label control. (i.e)
<asp:Label Text="Test" ID="lblq" runat="server"></asp:Label>
How to find the font-name (or) font-family of the Label 'lblq' ? and Is font-family depends on the browser?
I have loaded default fonts in a dropdownlist. when I click a button, I just need to set the label 'lblq' font-name into selected value of dropdownlist.
Try:-
string myVal = lblq.Font.Name;
this is not as relavent to your question but might give you a head start
// this will give you the list of all installed fonts
using System.Drawing.Text;
InstalledFontCollection fontList = new InstalledFontCollection();
foreach(FontFamily family in fontList.Families)
{
ListBox1.Items.Add(family.Name);
}
You can find original font name using following code:
string originalFontName=lblq.Font.OriginalFontName;
Related
I am looking to replace the tag list in awesome WM with a simple text box that only displays the name of the current tag. I have tried to create a textbox that contains the following code:
mytagbox = widget({ type = "textbox" })
mytagbox.text = awful.tag.selected(s).getproperty("name")
But this does not work and reverts awesome to its default config. What is the correct code I need to put in to make this possible? I'm also using Shifty. Thanks
You were close to the correct way:
screen[1]:connect_signal("tag::history::update", function()
mytagbox.text = awful.tag.selected(1).name
end)
-- Or add_signal on awesome < 3.5
So mytagbox.text will be changing on each tags switching.
Another solution would be to change filter function on taglist
mytaglist[s] = awful.widget.taglist(s, function(t, args) return t.selected end, mytaglist.buttons)
I want to add tooltips to a form on my site. I am using the jQuery tools library. The tooltips show the content of the title attribute of an html input. Is there a way to make the asp.net textbox render out the title attribute in the html input it creates?
Since title is a global attribute, according to the W3C HTML language specifications, I would have expected a title property in the System.Web.UI.WebControls.WebControl.
However, Microsoft appears to have chosen a more 'appropriate' name for this property: Tooltip.
If you specify this property:
var label = new Label();
label.ToolTip = "tooltip";
label.Text = "text";
Controls.Add(label);
it will render:
<span title="tooltip">text</span>
which is just what you wanted.
Seeing that Tooltip is a property of the base WebControl, I assume that it will render as a title attribute for all WebControl classes.
You would do something like TextBox1.Attributes.Add("title", "Some title value");
Textbox.Attributes.Add("title","My text");
The .Attributes.Add("Attribute Name", "Attribute Value") lets you add most attributes to most controls, but always use the native property if available.
By far the easiest way is:
<asp:TextBox runat="server" title="My Title" />
Which renders
<input type="text" title="My Title" />
This also works with style etc, etc.
CheckBox newBox = new CheckBox();
newBox.Text = dtCommon[i].userName;
newBox.CssClass = "cbox";
newBox.Attributes["value"] = dtCommon[i].id.ToString();
ApprovalSelectPanel.Controls.Add(newBox);
Renders as:
<input id="ctl00_mainContent_ctl00" type="checkbox" name="ctl00$mainContent$ctl00" checked="checked" />
How can I get a value attribute on? My JQuery needs to access this!
I bet you it is setting the attribute, but on the containing span (look up one element).
You want to use the InputAttributes property instead:
newBox.InputAttributes["value"] = dtCommon[i].id.ToString();
newBox.Attributes.Add("yourAttributeName", "yourAttributeValue");
EDIT: Sorry I forgot checkboxes act a little diff so you need to do:
newBox.InputAttributes.Add("yourAttributeName", "yourAttributeValue");
If you want to access the span around the checkbox control the original would work or you could do:
newBox.LabelAttributes.Add("yourAttributeName", "yourAttributeValue");
Can you try newBox.Attributes.Add("Value", dtCommon[i].id.ToString());
If you need to store a value on the checkbox, I recommend using something besides value, such as "MyValue". You can still get this "MyValue" using the .Attributes method later in your processing. In jquery, you could use the .attr('MyValue') to obtain the value.
I have a frame with several radio buttons where the user is supposed to select the "Category" that his Occupation falls into and then unconditionally also specify his occupation.
If the user selects "Retired", the requirement is to prefill "Retired" in the "Specify Occupation" text box and to disable it to prevent it from being changed. The Specify Occupation text box should also no longer be a tab stop. If the user selects a radio button other than Retired the Specify Occupation text box should be enabled and once again and the Specify Occupation text box should once again be in the normal tab sequence.
Originally, I was setting and clearing the disabled property on the Specify occupation textbox, then I found out that, upon submitting the form, disabled fields are excluded from the submit and the REQUIRED validator on the Specify Occupation textbox was being raised because the textbox was being blanked out.
What is the best way to solve this? My approach below was to mimic a disabled text box by setting/resetting the readonly attribute on the text box and changing the background color to make it appear disabled. (I suppose I should be changing the forecolor instead of teh background color). Nevertheless, my code to make the textbox readonly and to reset it doesn't appear to be working.
function OccupationOnClick(sender) {
debugger;
var optOccupationRetired = document.getElementById("<%= optOccupationRetired.ClientId %>");
var txtSpecifyOccupation = document.getElementById("<%= txtSpecifyOccupation.ClientId %>");
var optOccupationOther = document.getElementById("<%= optOccupationOther.ClientId %>");
if (sender == optOccupationRetired) {
txtSpecifyOccupation.value = "Retired"
txtSpecifyOccupation.readonly = "readonly";
txtSpecifyOccupation.style.backgroundColor = "#E0E0E0";
txtSpecifyOccupation.tabIndex = -1;
}
else {
if (txtSpecifyOccupation.value == "Retired")
txtSpecifyOccupation.value = "";
txtSpecifyOccupation.style.backgroundColor = "#FFFFFF";
txtSpecifyOccupation.readonly = "";
txtSpecifyOccupation.tabIndex = 0;
}
}
Can someone provide a suggestion to me on the best way to handle this scenario and provide a tweek to the code above to fix the setting/resetting on the readonly property?
I would use jQuery instead it's super easy to implement...
To set the textbox as readonly...
$("#myTxtID").attr('readonly', 'readonly');
To set the textbox as not readonly
$("#myTxtID").removeAttr('readonly');
I recently had to do the same thing. Here's how I solved it.
go back to using the disabled property rather than readonly.
replace the RequiredFieldValidator with a CustomValidator. in your client and server validation functions, determine if you need to check the text input based on the condition of the Retired radio button. then check for input in the text box if you need to. (on the js side you can check the disabled property on the textbox itself to save yourself a step).
on the server side you should double check the radio button selection, and if "Retired" is selected, you should make sure that "Occupation" value is actually "Retired". this gets you around the issue of not getting a value from a disabled field, and you should be doing it anyway (never trust the user and all that).
I'm new to jquery, and sorry if this question is asked before (could find exactly what I was looking for)
I would like to implement the following convetion: If I create a error label with the name '_lblError' like this:
<div>
<asp:label ID="_lblError" text="this is a error msg"/>
</div>
classA or classB would be applied to it depending on a empty string or not in the 'text' parameter of the label.
I also would like to place this code in a external js file that would be used throughout the app.
Thanks for any help!
To start with, you probably need to give the label a css class that can be used for selection:
<asp:Label Id="_lblError" Text="This is the error message"
CssClass="ThisIsWhatWeWillllWorkWith" />
This will probably output something like
<span id="ct100__lblError" class="ThisIsWhatWeWillWorkWith">
This is the error message.
</span>
You can now select the label in jQuery using the class as selector, and add class A or B depending on whether the .text() property is empty or not.
$(function() {
$('.ThisIsWhatWeWillWorkWith').each(function() {
if($(this).text() == '') { $(this).addClass('ClassA'); }
else { $(this).addClass('ClassB'); }
});
});
All code is provided as is, with no guarantees of working without modification. But you get the general idea of how to solve the problem...
EDIT: In response to your comment, here's a way to do it without adding a css class to the label. Instead of using an <asp:Label> tag for the error message, wrap a literal in a tag you hard-code on your page:
<span class="ThisIsWhatWeWillWorkWith"><asp:Literal ID="__ltlError" Text="This is the error message.</asp:Literal></span>
Another, perhaps more elegant way, would be to create your own custom label, and use that instead.
public class ErrorLabel : System.Web.UI.WebControls.Label
{
public ErrorLabel() {
this.CssClass = "ThisIsWhatWeWillWorkWith";
}
}
You then put the error message on your page with the following line:
<asp:ErrorLabel ID="__lblError" Text="This is the error message" />
Again, not sure if the above code will work as is. But again, you get the idea of what to do...
If the idea is to provide say, have different font and/or background if there is an error and display nothing if there is no text in the error label then you could make the control a literal instead of a label. The literal control does not create a control with no text (MSDN doc)