473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1789
how about onClick on a html button ? or if you want a server control then

btnPassValue.Attributes.Add("onClick", "javascript:ReadVal(this);");

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

something like this should do the job

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.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="mytextbox1"> etc

hth

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
Guess more details are needed.

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

My button is defined:
<Button ID="btnAdjustment" OnClick="NeedSupervisor(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["txtAdjPoints"].item);
document.write("<br>");
return;
...

(The return is for testing purposes till I solve this problem). I've also
tried:
document.all["txtAdjPoints"].ToString()
I've tried getElementByName 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.HtmlControls.HtmlInputText TextBox1;

protected System.Web.UI.HtmlControls.HtmlTextArea TextArea1;

and then you can use them like anywhere in codebehind.

private void Page_Load(object sender, System.EventArgs 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**@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.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="mytextbox1"> etc

hth

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...

Nov 18 '05 #4

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

Similar topics

4
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"...
2
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...
2
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...
1
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...
11
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...
3
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...
2
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...
0
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...
4
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. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.