473,753 Members | 7,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hyperlink a selected text from a specific textbox

3 New Member
Hello,

In my page i have two textboxes and a html button. I'm using vb.net 2.0 . what i need is i want whatever text selected in the textbox1 to be hyperlinked when clicked the button... this is no problem.. i'm getting it easily.. But my problem is , if i select some text from the textbox2 and click the button it is also hyperlinked. i want only whatever text selected in the textbox1 to be hyperlnked and not in textbox2. Please tell me how to achieve this. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="SwapnaTestpage.aspx.vb" Inherits="SwapnaTestpage" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8.  
  9.     <script type="text/javascript" >
  10.     function InsertLink()
  11.     {
  12.         var    txt= document.getElementById("<%=textbox1.ClientID%>");
  13.  
  14.         if ((document.selection.createRange().text.length)>0)
  15.         {
  16.                 txt = document.selection.createRange();
  17.             txt.text = '<a href="http://www.google.com" target=_blank >' + txt.text + '</a>';             
  18.         }
  19.         else
  20.         {
  21.             alert("Please select text from textbox1 to insert hyperlink.");
  22.         }    
  23.     }
  24.     </script>
  25. </head>
  26. <body>
  27.     <form id="form1" runat="server">
  28.     <table>
  29.     <tr id="rwBody" runat="server">
  30.             <td  align="left" colspan="2" style="width: 550px" >
  31.                 <asp:TextBox ID="textbox1" runat="server" Height="216px" TextMode="MultiLine" Width="527px" CausesValidation="True"></asp:TextBox>
  32.  
  33.             </td>
  34.         </tr>
  35.         <tr id="rwHPHeading" runat="server">
  36.             <td align="left" colspan="2" style="height: 40px; width: 550px;">
  37.                 <asp:TextBox ID="textbox2" runat="server" CausesValidation="True" Height="30px"
  38.                     MaxLength="100" TextMode="MultiLine" Width="527px"></asp:TextBox></td>
  39.         </tr>
  40.         <tr runat="server">
  41.             <td align="left" colspan="2" style="width: 550px; height: 40px">
  42.                 <input type="button" id="btnInsertLink" onclick="InsertLink()" value='Insert Link'  name="btnInsertLink" runat="server" /></td>
  43.         </tr>
  44.     </table>
  45.     </form>
  46. </body>
  47. </html>
  48.  
Dec 29 '08 #1
2 3279
s2008
3 New Member
I got the Answer myself...

function InsertLink()
{
var txt= document.getEle mentById("<%=te xtbox1.ClientID %>");
txt.focus();
if ((document.sele ction.createRan ge().text.lengt h)>0)
{
newRange = document.select ion.createRange ();
newRange.text = '<a href="http://www.google.com" target=_blank >' + newRange.text + '</a>';
}
else
{
alert("Please select text from textbox1 to insert hyperlink.");
}
}
Dec 31 '08 #2
shivarajece
1 New Member
Thanks, but once I added the hyperlink, I want to show the text ie., Rich TExt with Hyperlink.

Is there any way to show rich text in Asp.net text box with out using third party component like Telerik etc.,?

Thanks.
Nov 1 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4897
by: hermawih | last post by:
Please help . I want to load the contents of another rtf document by double-clicking the words . Chapter1.rtf Chapter2.rtf Chapter3.rtf ....
9
2329
by: RA | last post by:
While dynamically creating the table; I am adding a hyperlink as a TableCell where text is "Delete". Initially it is disabled and if a checkbox is selected from a table then it gets enabled. Even though it is disabled, if I click on that cell it fires onClick event. The other concern is it does not show Hand as its cursor; which we would expect from a hyperlink. (NOTE: I am also adding hyperlinks to few other TableCells, which are not...
4
5848
by: wrytat | last post by:
I have a form with a textbox for the user to enter a quantity and another textbox for the delivery date. I disabled this delivery date textbox such that the user has to press a calendar link next to the textbox, then a calendar will pop up for him to choose the date. The dates that the user can pick depends a lot on the quantity that he enters in the quantity field. Is there any way that I can parse the quantity field to the calendar page...
3
6849
by: Wayne Wengert | last post by:
I am trying to impliment the extensions to the Club Starter kit as described at: http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/extendclubwebsitesk.asp but when I build the hyperlinks in the Gridview Column template as described at the end of the article I am getting two errors on each of the hyperlinks ("Characer is not valid" and "Expression Expected"). I've included the code from one of these instances...
4
6487
by: sulemanzia | last post by:
I have a form with a Command button. i have a text box also which is bound to my Button. i have created a standard module and created an onclick event for my button which is something like this ( if a user clicks on the button it will give an option to the user to add a file. The Path of that file will be copied to the textbox which is associated to my control or button.) i changed the data type also for my textbox to
3
1727
by: Ruth Sanders | last post by:
VB 6: I need to provide a text box that allows a user to enter working hyperlinks without typing the html code. I currently send the text box contents (textbox.text) as an email message...I need the user entered hyperlink to work within the sent email message body. How can I make this happen? From http://www.developmentnow.com/g/38_2004_11_0_4_0/dotnet-languages-vb.htm Posted via DevelopmentNow.com Groups http://www.developmentnow.com
1
2503
by: abertay | last post by:
Hi friends...I need our help.I'm stuck with this code... can some one tell me how can pass a javascript variable into hyperlink along with a php varaible? Here is my code.. <html> <head> <script type="text/javascript"> function favBrowser()
13
42981
ADezii
by: ADezii | last post by:
Recently, there have been several questions and much confusion concerning the Topic of Hyperlinks. Specifically, Users wanted to know how to retrieve a File Name from a FileDialog Box, copy the Name to a Bound Text Box on a Form, and save the Hyperlink to the underlying Table. The code demos below will do just that: retrieve the Absolute Path of of File from a FileDialog Box, use the Base Name (no extension) as the Display Text for the...
10
3006
by: sierra7 | last post by:
I'm trying to create a form where a user enters a document reference number and then clicks a command button to add a hyperlink to the document, via a file picker. Thanks to Adezii's excellent article http://bytes.com/topic/access/answers/725778-inserting-hyperlink-into-table I can manage to create a hyperlink to the document and store it in the table, but it is the full hyperlink path not the reference number of the document that is...
0
9072
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8896
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4771
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3395
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2872
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2284
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.