473,788 Members | 2,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending asp:TextBox value to JavaScript

I have a button that calls a JavaScript. I need to get the value in an
asp:TextBox field to the javascript, either as a parameter or via some
mechanism within the JavaScript itself.

Any Ideas?

TIA,
Dave
Nov 18 '05 #1
3 1814
how about onClick on a html button ? or if you want a server control then

btnPassValue.At tributes.Add("o nClick", "javascript:Rea dVal(this);");

on aspx page you can have a javascript like
<script language=Javasc ript>
function ReadVal(f)
{
var valueBeingRead = f.Value;
}
</script>

something like this should do the job

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:81******** *************** ***********@mic rosoft.com...
I have a button that calls a JavaScript. I need to get the value in an
asp:TextBox field to the javascript, either as a parameter or via some
mechanism within the JavaScript itself.

Any Ideas?

TIA,
Dave

Nov 18 '05 #2
my bad.. .my bad..
sorry onClick button and this would pass reference to the button and not the
text box.

another problem would be the actual ids of the textbox in the rendered html.
have a look at those. you might have to do it the hard way ie ur the names
as rendered not the ids as in designer. (do a vew >> source )
if this is too messed up consider using plain old html control <input
type=text maxlength=50 name="mytextbox 1"> etc

hth

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:7D******** *************** ***********@mic rosoft.com...
Guess more details are needed.

My text field is defined:
<asp:TextBox ID="txtAdjPoint s" Width="65" Runat="server"> </asp:TextBox>

My button is defined:
<Button ID="btnAdjustme nt" OnClick="NeedSu pervisor(this)" >Process
Adjustment</Button>

The top of JavaScript looks like:
function NeedSupervisor( val)
{
document.write( "First line ");
document.write( "<br>");
document.write( val.value);
document.write( "<br>");
document.write( document.all["txtAdjPoin ts"].item);
document.write( "<br>");
return;
...

(The return is for testing purposes till I solve this problem). I've also
tried:
document.all["txtAdjPoin ts"].ToString()
I've tried getElementByNam e and getElementById (The name property doesn't
apply to an ASP:TextBox, so not surprised that returns an empty list).

When I use getElementById and try to print the className iget a blank. I
tried printing the className for the object being passed in and also got a
blank.

Nov 18 '05 #3
well you can do something like this

<TEXTAREA cols="20" id="TextArea1" >
</TEXTAREA>
<br>
<INPUT type="text" id="TextBox1">

in your code behind at reference to the html objects
protected System.Web.UI.H tmlControls.Htm lInputText TextBox1;

protected System.Web.UI.H tmlControls.Htm lTextArea TextArea1;

and then you can use them like anywhere in codebehind.

private void Page_Load(objec t sender, System.EventArg s e)

{

// Put user code to initialize the page here

string textBoxVal = TextBox1.Value;

string textAreaVal = TextArea1.Value ;

}

also if you are looking for modal dialog then you might want to check
www.asp.net site... and go to control gallery
--

Regards,
Hermit Dave
(http://hdave.blogspot.com)
"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:EF******** *************** ***********@mic rosoft.com...
Actually I'm doing all my work in the HTML source. And I've considered using a plain text field, however, the entire scenario is:

User enters value in text box. Then presses button to post the adjustment.
The JavaScript tests the value to see if its less than 200. When its less,
the code action is to proceed straight to an ASP C# event handler (via the
fireEvent method). When its greater (and this is the real need for
JavaScript) the showModalDialog function is called to collect a username
password. These values are then returned via parameters and inserted into
hidden fields so that my C# handler can pick up and verify those fields.

Now if I knew how to initiate a Modal Dialog box server side, I might (given what a pain this is turning out to be) just reconsider using JavaScript.

Since I'm still a rookie with ASP.net, I would need to know how I can bind a standard input text box to the server side ASP web control.

Thanks So Much for your help so, far.
Dave

"Hermit Dave" wrote:
my bad.. .my bad..
sorry onClick button and this would pass reference to the button and not the text box.

another problem would be the actual ids of the textbox in the rendered html. have a look at those. you might have to do it the hard way ie ur the names as rendered not the ids as in designer. (do a vew >> source )
if this is too messed up consider using plain old html control <input
type=text maxlength=50 name="mytextbox 1"> etc

hth

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:7D******** *************** ***********@mic rosoft.com...

Nov 18 '05 #4

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

Similar topics

4
6491
by: Chumley the Walrus | last post by:
I'm using this sql parameter: MyCommand.Parameters("@Sport").value = Server.HtmlEncode(sport) to get a value from a textbox control: <asp:TextBox Name="sport" id="sport" runat="server"></asp:TextBox> but i cannot see why I get "Value of type 'System.Web.UI.WebControls.TextBox' cannot be converted to 'String'"
2
17531
by: Matthew Wieder | last post by:
Hi - I'm trying to do client-side validation of the text in a Asp.Net textbox control using javascript. My page has the following: <form id="Form1" method="post" runat="server" onsubmit="return validateName(this);"> and <script language="JavaScript"><!-- function validateName(theForm) {
2
1405
by: Eph0nk | last post by:
Hi, I don't know a lot about javascript - and i'm stuck on a certain problem. I need to put a value in an <asp:textbox> control from a javascript. The textbox is called "txtThumb" - and the name stays the same once rendered to html. I've tried txtthumb.text & txtthumb.value, but both do nothing. I'm sure it must be quite simple :/ ---
1
1816
by: Solitus | last post by:
I have a form for a customer to edit his customer information. It has several textboxes that I will populate with some existing data from the database before displaying the form to the user. I populate each of the textboxes inside Page_Load using (1) TextBox1.Text = "some value" After changing some of the text in the textboxes and pressing submit button, when I tried to get the edited text in the submit_button handler using
11
7764
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
3
3304
by: NH | last post by:
How can I check the value of a textbox has no more than 2 decimal places? I already check that the value is numeric, but how do I check that it is not 0.223 or .022 etc. I only want to allow up to 2 decimal places...
2
2077
by: alanliang | last post by:
I want to be able to populate an asp textbox with logitude and lattitude values whenever a user selects a point or creates a marker on google maps. Simply, how do I change an asp's textbox value through javascript? Thanks, Alan
0
1809
by: bigmaddaz | last post by:
Right I have a table on a page containing a recordset showing various records, when they click add button it add the information from that table into another one successfully. But now on that table ive added a text box in another column because I need them to type in a quantity then click add and for it too take the value in the textbox and put it into the table. private sub add() if iupdate = "true" then 'response.write "update"...
4
2019
by: Sean | last post by:
I have a situation whereby I need to modify the text string appearing on an ASP button with some text derived from a Javascript function. But I am unsure of the correct syntax to do so. Currently the I am just modifying the text in a SPAN next to the button as opposed to change the button text itself. But it's not ideal really. Currently I am have this: <div id="section2">
0
10364
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
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
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
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.