I am looking for a solution. My treeview control contains the menuitems for my web application and its populated from a sitemap and it's working fine. Now I need to add alternative text to that menu items created. How can I add alternative text to these treeview items.
My treeview code is like below
protected void MainMenu_NodeDataBound(object sender, TreeNodeEventArgs e)
{
var siteMapnode = e.Node.DataItem as SiteMapNode;
e.Node.Value = siteMapnode.Url;
e.Node.NavigateUrl = string.Empty;
e.Node.SelectAction = (siteMapnode.Url != String.Empty) ? TreeNodeSelectAction.Select : TreeNodeSelectAction.None;
e.Node.PopulateOnDemand = false;
}
Not really sure what you mean by 'alternative text' but you may be looking for the Tag property.
Example:
...
e.Node.Tag = "Alternative Text, whatever that means.";
...
You can set a Node's Tag property to whatever you want since it's type object, which I find pretty handy. Reference here.
There is no alt. I believe what you want is title, which is set using the ToolTip attribute:
e.Node.ToolTip = "I provide useful info about the link."
Which will get rendered as:
Some Text
alt is used to specify alternate text for elements when they can't be rendered (i.e. NOT anchor tags). Outside of IE, browsers will not use this to provide text that displays when the element is hovered.
From HTML Techniques for Web Content Accessibility Guidelines 1.0:
In addition to clear link text, content developers may specify a value
of the "title" attribute that clearly and accurately describes the
target of the link.
If more than one link on a page shares the same link text, all those
links should point to the same resource. Such consistency will help
page design as well as accessibility.
If two or more links refer to different targets but share the same
link text, distinguish the links by specifying a different value for
the "title" attribute of each A element.
Alternate text in ASP.Net :
AlternateText="Your Text"
Related
I have a little help pop-up that displays some text when the user presses a "?" label next to a drop-down to explain the different selections.
I did it using the Help.ShowPopup command since that seemed the easiest.
I was hoping there was a way to add different font properties to parts of the text or at least to the whole thing without having to go the direction of a CHM/HTML help-file.
Here is what I am trying to do:
private void helpLbl_Click(object sender, EventArgs e)
{
// for some reason, it ignores the 'parent' parameter
// and lays it out on the screen's coordinates
Point helpLocation = helpLbl.PointToScreen(Point.Empty);
helpLocation.Y += helpLbl.Height; // have it display underneath the control
Help.ShowPopup(this, // hosting form
#"<b>Fixed:</b>
Removes a fixed amount from the sale
<b>Percent Value:</b>
Removes a set percentage of the selected package from the sale
...", helpLocation);
I was hoping since there's the option to use an HTML document to display the help, I could use HTML tags to format what was being displayed, but it doesn't appear so. Any ideas?
Is there a way to do something like displaying a RichTextBox in the help pop-up?
Another possibility is generating a HTML document on-the-fly, but it asks for a "url" if I'm not supplying the text directly and I think that might be a little over-kill for the small amount I'm trying to do here.
You have two options. One is to use a WebBrowser Control. This natively accepts HTML and displays it. The problem with it is its kind of bloated just to use as a simple label.
Your second option is to simply create a RichTextLabel, simply like this:
public class RichTextLabel : RichTextBox
{
public RichTextLabel()
{
BorderStyle = BorderStyle.None;
}
}
Add this to your form and set the Rtf property to your RTF code. You will have to convert your HTML to RTF, which is easy if you got a program such as Microsoft Word, for example.
I am using default asp.net ToolTip property, the text is
This is Going to be a long text
Thats why we decided to split it.
but using <br/> to split the line doesn't work, it renders as a text, and I want it to break the line instead.
Here is my code:
Label lblActionText = new Label();
lblActionText.Text = "Helloooo Phaltu";
lblActionText.Style.Add("cursor", "pointer");
lblActionText.ToolTip =
"This is Going to be a long text"
+ "<br/>"
+ "Thats why we decided to split it.";
I've not tried this but would "System.Environment.NewLine" not do the job instead of the BR tag?
You can use this to insert a line break inside a ToolTip.
lblActionText.ToolTip = " First text " + Environment.NewLine + " second text ";
Use the line break character entity (
). It is easy to implement but the only problem is that this will work in IE & Chrome but not Firefox.
lblActionText.ToolTip = "This is Going to be a long text
Thats why we decided to split it.";
See jsFiddle: http://jsfiddle.net/jafLf/
You are passing a string value to a Tooltip, and that's why the HTML element <br /> is not working.
However you can try this ASP.Net AJAX TooltipExtender
This works only on IE but other browsers are not!!
If you want to have a customize tooltip then seach for jQuery tooltips to have a formatted tooltip
You can do this with adding a table in the tooltip :)
Example: ASP forum
The ASP.NET ToolTip property corresponds to the HTML title attribute.
In IE and Chrome you can simply do:
<span title="multiline
tool
tip">Mouseover me!</span>
However, that won't work in Firefox as it actually follows the W3C guidelines for CDATA.
CDATA is a sequence of characters from
the document character set and may
include character entities. User
agents should interpret attribute
values as follows:
Replace character entities with characters,
Ignore line feeds,
Replace each carriage return or tab with a single space.
Your best bet (considering you also want to change the colour) would be to go with a jQuery solution such as QTip which gives you all the customisation you want and more..
You cannot change the color of a tooltip with the default title attribute. For that the only way is to use a javascript generated tooltip.
There are plenty of plugins for jQuery such as:
Dynamic tooltip
Popup Bubble
jQuery Horizontal Tooltips
Coda Popup Bubble
Awesomeness
TipTip
(mb)Tooltip
vTip
jGrowl
jQuery Ajax Tooltip
Digg-style post sharing tool with jQuery
Input Floating Hint Box
Simpletip
qTip
Orbital Tooltip
And many more, check them here: Stylish jQuery Tooltip Plugins Webdesign
You can also just create your own using javascript. Add a mouseover event on the element then show a hidden div over the element with whichever html elements you want, in whichever color you need.
It is also more safe to use a javascript approach for cross-browser compatibility.
I have a Search.aspx page which calls UCSearch control. UCSearch control does everything like getting what is being searched and what should be displayed, etc. I am trying to give the title to the page. As i dont have any info to write the code in the aspx page, i am thinking to write it in the control. But it is not displaying me when i tried using Page.Title in control. What am i doing wrong?? This is in Asp.net and C#.
Page.Title = "Search Results for Newark, NY";
Thanks in advance!!
Does not:
this.Page.Title = "My beautiful title";
work?
You should be able to get to the ASPX using the Parent property of the control. Cast that property to a Page (it's a WebControl or something similarly generic), then set its Title property. If you have a hierarchy of master pages or are nesting this control in other controls, you may need to traverse the Parent hierarchy for a few more levels.
You could also fire an event from your user control, passing the Title that you would like to display. You could then handle this event on the page, and set the title.
This does require a small amount of code in your aspx page, however, at least now the user control does not care where the title goes, the parent of the control can worry about it. If ever you want to change where this title goes, or even put it in multiple places, you don't have to change the user control. Let me know if you want a sample, I'll add it.
If you don't like that idea, then cederlof's answer will work, I just tested it.
protected void helloBtn_Click(object sender, EventArgs e)
{
this.Page.Title = "hello from control";
}
** You can use naming container to find the parent control of the current control. Through this way you can move through the page hierarchy.
Quickwatch will help you a lot in figuring out the things and building the statement for quick casting. Do some more research on naming container.
var container = userControl.NamingContainer;
if(container is Page)
{
Page p = container as Page;
p.Title = "Your Title";
}
**
Above is not the exact solution, but can help you it you can usercontrol directly on the page. Unless you need to iterate through the page controls. This was just for an quick help.
I got this Text box with default value as "First Name" ..Now when I click inside this text box to enter name , this value "First Name" keeps on displaying. What I want is to the text box to clear as soon as I click inside it. What property do I need to set in mt textbox tag ?
[Edit]
ok anything from Telerik that I can use to do that ?
There is not out of the box functionality in TextBox that will accomplish this, but the ASP.Net Ajax Toolkit has a Watermark Extender that will do everything you want.
I have used both, but now personally use a jQuery Watermark Plugin
Either will work just fine, choose based on your needs.
According to the Telerik docs you just have to set the EmptyMessage property on their TextBox control. Demo Page Here
In the code behind, on Page Load you can add the following code to achieve this
TextBox1.Attributes.Add("onClick", "javascript:if(this.value=='First Name'){this.value='';}");
You can use the method suggested by #Josh. If you do not want to use Ajax Toolkit controls or JQuery you could write it on your own using Javascript. Write a function which gets called when the foucs is received by the textbox control. I thik the function is called onfocus or just focus in Javascript.
Hi I just wrote this small function which will achieve your desired result
function clearInputBox(x,prefil){
if(x.value == prefil){
x.value = '';
}
}
Your input box looks like this
<input type='text' value='First Name' onfocus="clearInputBox(this,'First Name')" />
May be this will help you
Taking Shobans advice one step farther, you could add something like this to your Page subclass
protected override void OnInitComplete(EventArgs e)
{
string jsString = "javascript:if(this.value=='" + TextBox1.Text + "'){this.value='';}";
TextBox1.Attributes.Add("onFocus", jsString);
base.OnInitComplete(e);
}
What this will do is, it will always consider that default string is the one this controll contains at esign time (the initial one in your .aspx file), so you wont have to manually change it in codebehind every time you change your .aspx. Remember, that OnIinitComplete fires before any viewstate or postback data has been applied, but after the controlls on your page have been set to their default values.
P.S. As anishMarokey pointed, use onFocus vs onClick, since fields can gain focus without clicks via Tab key.
I need something as a placeholder. I at first looked to Content Control as a solution but I'm having some problems with it.
I then looked into adding CustomXML to the .docx but turned away from that because of the i4i lawsuit.
Then I decided I would just plain change the text of the Content Control through OpenXML SDK 2.0 but even if it's so marked the Content Control doesn't go away. I guess that it doesn't know that the text changed unless it happens inside word.
I could perhaps just remove the CC and place text instead but I'm afraid of problems with format and styles it could bring and also it would kind of defy the purpose of the Content Control.
Then I started wondering if I could define my own placeholders that Word could recognize. Through Building blocks perhaps. It doesn't have to do anything except be easy to find using OpenXML and somehow taggable so I know what to replace it with. I'm not really sure what can be done with Building Blocks but I'm hoping it's do-able.
Not sure what solution would be best for me but what I need is:
a)Something that's easy to place in the template, perhaps predefined Content Control placeholders that you can place where you wan't and style as you like.
b)When the data has been added it removes all placeholders, it won't be modified again. It keeps the style/format defined in the placeholder.
TO RECAP, I need answer to either
How can I edit Content Controls in OpenXML SDK so they will be removed after text is added.
-OR-
Can I define my own custom OpenXML tag for a Word Document that I could then replace?
Perhaps this can help you,
private void DeleteSdtBlockAndKeepContent(MainDocumentPart mainDocumentPart, string sdtBlockTag)
{
List<SdtBlock> sdtList = mainDocumentPart.Document.Descendants<SdtBlock>().ToList();
SdtBlock sdtA = null;
foreach (SdtBlock sdt in sdtList)
{
if (sdt.SdtProperties.GetFirstChild<Tag>().Val.Value == sdtBlockTag)
{
sdtA = sdt;
break;
}
}
OpenXmlElement sdtc = sdtA.GetFirstChild<SdtContentBlock>();
OpenXmlElement parent = sdtA.Parent;
OpenXmlElementList elements = sdtc.ChildElements;
var mySdtc = new SdtContentBlock(sdtc.OuterXml);
foreach (OpenXmlElement elem in elements)
{
string text = parent.FirstChild.InnerText;
parent.Append((OpenXmlElement)elem.Clone());
}
sdtA.Remove();
}
Take a look at using a Field. The mail merge fields are designed for exactly this purpose.
I don't understand from your question if you are only interested in a solution that automatically removes the ContentControl/SDT when you modify it using the OpenXML SDK, or whether you want it to disappear after the content is modifed programmatically or by a user.
If the former, I think you'll have to remove it yourself as Bilel suggested. If the latter, you should look at this property: ContentControl.Temporary ("the ContentControl is automatically deleted when the user types in the control, or when the text in the control is changed programmatically. When the ContentControl is automatically deleted from the document, the text in the control remains in the document.")