How to show a hyperlink in a text - c#

I have a text which may contain some special characters like <b></b> or a link. I want the user to be able to click on the link and open it. TextBlock or RichTextBox seems doesn't show links in a proper way:
<RichTextBox >
<Paragraph>
click here: http://www.google.com
</Paragraph>
</RichTextBox>
How can I show a text like that in a page?
Update: seems my question isn't clear. I ask a server for content and it returns back to me something like this:
from <b><i><a href="http://www.google.com" rel=nofollow> lorem ipsom
NPR:

 tapped in front of you probably know Bill Gates...
I want to show this in a WINDOWS PHONE page. TextBlock doesn't render it well. how can I show it human readable?

The way to solve your problem I see in using of WebBrowser control.
Then, accordingly to the article, you should go with Javascript to manage the links clicking etc (unless you want the links would be opened automatically with standard logic of Windows Phone):
Script is disabled in the WebBrowser control by default. Set the
IsScriptEnabled property to true if you want to enable scripting in
your control. You can then call scripts using the InvokeScript method.
The ScriptNotify event occurs when JavaScript in the WebBrowser
control passes a string to managed code.
That's a bit tricky way, but if you want to go any other way, you would have to implement your own parser of the code and build the sentence with labels and custom hyperlinks (as in provided above suggestions from comments).

Related

how to open modal popup on textbox click in c#

I have a TextBox and and I want to open a Popup on clicking TextBox. There is no Click event for TextBox. I want to do it in C# completely. I don't need jquery in opening Popup on Click of TextBox.
Asp.net textbox:
<asp:textbox onclick="myJavaScriptFunction()" runat="server" id="myTextBox" ... >
#edit
jquery example:
$("#target").click(function() {
alert("Handler for .click() called.");
});
The nature of creating a website solution like you are doing makes this impossible. In ASP.NET WebForms and MVC you do not deliver C# code to the user so you cannot create client side behavior with C#; instead, you deliver an HTML page and assets like files for Javascript, CSS, images, etc. If you want to invoke client side behavior, you need code that will run client side. That means using Javascript, and I recommend that you use jQuery while doing that.
nirmus's answer will give you an example for that, but to answer your question completely bluntly the answer is: "You can't."

How to display a website only in the default browser

I'm currently having an issue after a click on an hyperlink inside a wpf Page.In my RequestNavigate or Click (both have the same behavior in this situation) event I do the usual Process.Start(hyperlink.NavigateURI).The problem is that this event opens the webpage both in the default browser (the behavior I'm looking for) and in my wpf Page object as well which I don't want.I was wondering if there was any workaround for this issue? Thanks in advance.
You need to set e.Handled = true to say you have already handled the hyperlink
See Example using Hyperlink in WPF
The reason your current page also loads with the Url is because you are using a Hyperlink. Try using either a Hyperlink with no Url, a button or a styled Label

Prevent CTRL V in HTML Editor Ajax Control MS

Hello I am using in C# HTML EDITOR Control MS Ajax.
I would like to know if is possible FORCE the control HTML EDITOR to DO NOT ACCEPT text from PASTE (short cut ctrl+v or menu command).
My aim is to prevent css inline code to be added to the text.
I would allow user to add text if pasted just with HTML EDITOR Button PASTE PLAIN TEXT.
Any ideas?
Do you think it is a good solution or any others= thansk
Trap the keypress event and check for CTRL+V.

Removing default text from text box

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.

Open a new window with asp.net

Im new into that asp.net thing, but here goes.
I got at ImageButton, and when its clicked i want the image displayed in another window. If I can avoid using ajax i would like to do that.
If possible would like to make the window modal, but still avoid ajax, since Im not ready to mix more technolgies yet.
The existing answers with JavaScript are fine, but just to suggest an alternative - could you use a HyperLink (with an ImageUrl set so you still get an image) and set its Target property instead?
IMHO the best practice to show a picture is in the same page on the top of the content. I personally use Lightbox. You can find the documentation on their page, so it should be easy for you to integrate their JavaScript code.
Somewhat like this:
<asp:ImageButton ID="imbJoin" CssClass="btn-find" AlternateText="Find" ToolTip="Find" runat="server" ImageUrl="~/library/btn-find.gif" onClick="javascript:popUp("ServicesLocator.aspx")" />
Resource: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22832169.html
Using the ImageButton you need to use a JavaScript to open it in a new window. You can also look into the OnClientClick-event
You can use the ImageButton's OnClientClick property:
<asp:ImageButton ... OnClientClick="javascript:window.open('url_to_image');" >
But this popup window will not be modal.
The following javascript will do what you're looking for:
window.open('page.html','WindowTitle','width=400,height=200')
It might be worth pointing to a two relevant entries in the excellent EFNet's #javascript FAQ:
Correct Use of Popups - yay accessibility!
How do I make a popup window the same size as my image?
How do I create a custom 'OK' dialog or something similar? - modal windows are not that useful and something like the suggested Lightbox or similar scripts would be better "modal" options
Correct Use of Links - this one being only partly on-topic but the previous answers use of the "javascript:" pseudo protocol made it necessary: it is never required nor useful in a web page that should work across browsers. After all, JavaScript is the default (and only) scripting language.
Thank you for all the answers! I ended up using lightbox
I found this example
http://neutrongenious.wordpress.com/2007/09/08/lightbox-for-asp-net-2-0/
And it works perfectly

Categories