Create hyperlink in TextBox control - c#

Is there some way that I could create a hyperlink within a Textbox control? The catch: I would like only certain text to act as a hyperlink. For example, StackOverflow.com allows me to make only THIS text act as a hyperlink. Is there some way to do this in C# from withing a Textbox?

Use a RichEditCtrl. Does the text need to be editable? Otherwise you could use Labels and Hyperlinks in a StackPanel.

Related

How to lighlight link in text box

I have to create some controls similar to a control TextBox. But I want this control can Highlight link as RichTextBox, Because I have problem with RichTextBox so i can't use it. How do I highlight a link in a TextBox? or I have to set each property by a line of code?
I want to display it in a TextBox as shown below:
This is not possible. A simple TextBox control cannot be used to display formatted text.
A hyperlink is just specially formatted text: all it really does is change the foreground color to blue and the text style to underlined. TextBox controls don't allow this type of granularity. All text in the control has the same formatting applied to it.
What you would need to use is a RichTextBox control. This is specifically designed for displaying formatted text, and not only does it allow you to define arbitrary formatting for specific bits of text, but it has built-in support for detecting and highlighting hyperlinks. You say in your question that you had a "problem" with using the RichTextBox, so that is really the question that you should have been asking.

How to display HTML formatted content in to label using C# WinForm?

I am using C# WinForms.
I want to display HTML formatted content in a Label control. Is it possible to do this? How can I do this?
A label is not meant to display formatted text. You can apply only one format to a label, which will be applied to the whole string.
If you want to display HTML-formatted text in a Windows Forms form, you'd better use a WebBrowser control instead of a label.
Source : http://www.codeproject.com/Answers/1121356/Display-HTML-formatted-string-in-to-label
You can do this but with correct approach
either use
<asp:PlaceHolder runat="server">
or can
try
<asp:Literals>

How to add HTML Markup to a textbox or label Control in a windows form C#

Let's say that my textbox control is named messageTB. I would like to know if it is possible to do the following:
messageTB.Text = "Hello <b>World</b>"
and have the output text to show "Hello World". In other words is there a way to enable html markup for the control? I am using visual studio.
The standard windows forms textbox control can't do it.
If you want formatted text you need a richtextbox or some other control.
There's a browser control that you could insert (rather than a textbox or label). Here's how to set the contents...
string html = "<html><body><strong>HelloWorld!</strong></body></html>";
Browser.DocumentText = html;
No. messageTB would have to be a Literal control for this to work.
It's clumsy, but I have used two adjacent Textboxes, one with format set to bold, to do this.
At least I get the look I want on the page.

Should I use a repeater?

I have a table similar to:
ID...NAME.....HTMLTEXT
1....Footer....`<b>test</b>`
where each entry has some HTML text and an associated Name and ID.
What I want to do in ASP.net C# is to list each of these entries on a page in such a way that the HTML text should be displayed exactly how it is meant to be (e.g. <b>test</b> should show 'test' in bold) and each entry should be editable. When the Edit button is clicked on an entry, the HTML text should be replaced by a textbox with the text inside it so that you can edit it and save it.
For example:
FOOTER --EditButton--
TEXT
test
Now I am not sure on what is the best way to do this. Should I use a repeater with an ItemTemplate for each entry? If I use a repeater, and an edit button is clicked, how do I know which edit button is clicked and how do I know which textbox to display the text etc?
You could also use a ListView - I tend to use this because its pretty robust. The data bound controls support the <%# Bind("Field") %> statement. You setup your templates in ItemTemplate or EditItemTemplate, and if you add the proper commands to the buttons in the UI, it all wires up the proper events for you (depending on how you data bind). If you don't use a datasource control, you have to manually tap into the ItemEditing, ItemUpdating, etc. events.
Additionally, if you need to, you can get references to the controls using the current item's FindControl("ID") method.
HTH.
Create a custom control (.ascx) and on this control make the line with the view that you wish, and handle the change/save/delete etc.
Then place this control in the repeater and just give him an id to load and edit.

Label,TextBox,Asp.net

I have a label and a text box associated to it . I have added some text in text box which is invisible at first... now I want to display the content after I go On the label...
If you are using an HTML label rather than an ASP label, you can use the onmouseover event. From within this event, you can then turn on/off the visibility of the text.
If you want to show one textbox after typing something in another, you can use the javascript onBlur() event to show it.
using jquery it can be:
$("#MyLabel").mouseover(function(){
$("#MyTextBox").attr("visible","true");
});

Categories