Sending asp:TextBox value to JavaScript

G

Guest

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
 
H

Hermit Dave

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)
 
H

Hermit Dave

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)
 
H

Hermit Dave

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top