473,500 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass client selected text to the server

How can I best pass user selected text to the server on a button click?
I could use javascript document.selected and add javascript to a
asp:button using Attributes.Add. Ideally I would fill the button's
CommandArgument with the client selected text, but I don't know how.
What is the best way to get client side document.selected to the server
code? Please provide sample code, thanks

Nov 19 '05 #1
5 1520
"use selected text" ???
Is this an asp:TextBox? If so the info is there, what you do with it at the
server is up to you.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"ma*************@hotmail.com" wrote:
How can I best pass user selected text to the server on a button click?
I could use javascript document.selected and add javascript to a
asp:button using Attributes.Add. Ideally I would fill the button's
CommandArgument with the client selected text, but I don't know how.
What is the best way to get client side document.selected to the server
code? Please provide sample code, thanks

Nov 19 '05 #2
In a hidden input control. Populate it on client side and read on server
side.

Eliyahu

<ma*************@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
How can I best pass user selected text to the server on a button click?
I could use javascript document.selected and add javascript to a
asp:button using Attributes.Add. Ideally I would fill the button's
CommandArgument with the client selected text, but I don't know how.
What is the best way to get client side document.selected to the server
code? Please provide sample code, thanks

Nov 19 '05 #3
Do you see what I am doing wrong here? If I uncomment the alert I
don't see the alert, so there is a problem in the javascript setting
the hidden value. Below is the html and the code behind. Thanks

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Test16.aspx.vb" Inherits="wave.Test16"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Test16</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function aaa()
{
Hidden1.value = document.selection();
//alert("hi");
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<P></P>
<asp:Label id="Label1" runat="server">Label1</asp:Label>
<P></P>
<input type="hidden" id="Hidden1" runat="server">
</form>
</body>
</HTML>

Public Class Test16
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Hidden1 As
System.Web.UI.HtmlControls.HtmlInputHidden

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add("onclick", "aaa()")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Text = Hidden1.Value
End Sub
End Class

Nov 19 '05 #4
ma*************@hotmail.com wrote in news:1129044434.383053.48240
@f14g2000cwb.googlegroups.com:
Hidden1.value = document.selection();


Since Hidden1 is a server side control (with a runAT) tag... you need to
write out the javascript dynamically... replacing Hidden1 with the
controlname . The controlname can be retrieved server side using
Hidden1.ClientID(). Or you can just hardcode the name ... view the HTML
generated and note the controlname.

Take a look at some articles on using Javascript with ASP.NET
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
Nov 19 '05 #5
This worked...

document.Form1.Hidden1.value = document.selection.createRange().text;

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6428
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
2
4899
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
3
2118
by: Joao Batista | last post by:
Hi all, I have a MasterPage with a menu, populated from a database, my problem now is when i chose an option , how can i pass (catch) the value to my products page??? Thanks Joao Batista
10
2237
by: Paul | last post by:
Hi I am using the HtmlInputFile control to upload a file from a client to a server. I have a browse to find the file on the server but need to create the path dynamically as to were it will go...
0
7134
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,...
0
7014
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...
0
7180
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,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4609
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...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
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 ...
0
311
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...

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.