Hi, I'm a little confused about how i should approach this, i have a textbox in this area i want a user to be able to highlight a word in the area and then click a button which then captures that word, where i can then manipulate it in vb.net. anyone have any
approaches on how to blend the javascript and .net code?
I post a simple sample and you can try it. The idea is : 1. Use server HiddenField as a media to store the selected text in client side 2. After post back, server side can get the "value" from hiddenfield NOTE: 1. The client HTML tag can also be generated in
server code if you like 2. My sample page uses single page model and you can easily convert to code behind if you are using VS.net <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Page.IsPostBack Then Response.Write("Client
Choose:
" & Hidden1.Value & "
") End If End Sub </script> <script language="javascript" type="text/javascript"> </script> <form runat="server" id="form1"> <input type="submit" value="Select text in textbox and click to post back" id="Button1" language="javascript" onclick="return Button1_onclick()">
<input type="text">
<input id="Hidden1" type="hidden" name="Hidden1" runat="server"> </form>
thank you that helps although i'm still a little bit confused about how i would capture the value from the hidden1. i tried doing dim x as string = hidden1.text but that didn't work, not exactly sure what i should do now?
now i'm having a problem where the hidden field is not retaining the value (ie. when i highlight the text in the word it doesn't return a value when i do a response.write...this is the code i have... code behind.... If Page.IsPostBack = True Then Response.Write("Client
Chose:
" & HiddenText.Value & "
") End If aspx page <script language="javascript"> function getActiveText(e) { document.Form1.HiddenText.value = document.selection.createRange().text:document.Getselection(); } </script> <form id="Form1" runat="server"> <input language="javascript" id="btnGetValue"
onclick="return getActiveText" type="submit" value="Select text in textbox and click to post back"> <input type="text" name="text"> <input id="HiddenText" type="hidden" name="HiddenText" runat="server"> </form>
sorry people last reply, i got it figured out so in case anybody needed this in the future they could get it easily.... here is the final code aspx page... <script language="javascript"> function getActiveText() { text = (document.all) ? document.selection.createRange().text
: document.getSelection(); document.Form1.HiddenText.value = text; return true; } document.onmouseup = getActiveText; if (!document.all) document.captureEvents(Event.MOUSEUP); </script> <form id="Form1" runat="server"> <input language="javascript" id="btnGetValue"
onclick="return getActiveText" type="submit" value="Select text in textbox and click to post back"> <input type="text" name="text"> <input id="HiddenText" type="hidden" name="HiddenText" runat="server" > </form> code behind... Private Sub Page_Load(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Page.IsPostBack = True Then Response.Write("Client Chose:
kuruption208...
Member
225 Points
45 Posts
Capturing highlighted text from a textbox?
Aug 04, 2003 05:05 PM|LINK
YugangW
Participant
1149 Points
227 Posts
Microsoft
Re: Capturing highlighted text from a textbox?
Aug 04, 2003 08:11 PM|LINK
" & Hidden1.Value & "
") End If End Sub </script> <script language="javascript" type="text/javascript"> </script> <form runat="server" id="form1"> <input type="submit" value="Select text in textbox and click to post back" id="Button1" language="javascript" onclick="return Button1_onclick()"> <input type="text"><input id="Hidden1" type="hidden" name="Hidden1" runat="server"> </form>
kuruption208...
Member
225 Points
45 Posts
Re: Capturing highlighted text from a textbox?
Aug 05, 2003 12:06 AM|LINK
kuruption208...
Member
225 Points
45 Posts
Re: Capturing highlighted text from a textbox?
Aug 05, 2003 12:14 AM|LINK
kuruption208...
Member
225 Points
45 Posts
Re: Capturing highlighted text from a textbox?
Aug 05, 2003 12:42 PM|LINK
" & HiddenText.Value & "
") End If aspx page <script language="javascript"> function getActiveText(e) { document.Form1.HiddenText.value = document.selection.createRange().text:document.Getselection(); } </script> <form id="Form1" runat="server"> <input language="javascript" id="btnGetValue" onclick="return getActiveText" type="submit" value="Select text in textbox and click to post back"> <input type="text" name="text"> <input id="HiddenText" type="hidden" name="HiddenText" runat="server"> </form>kuruption208...
Member
225 Points
45 Posts
Re: Capturing highlighted text from a textbox?
Aug 05, 2003 01:00 PM|LINK
" & HiddenText.Value & "
") End If End Sub