0

Possible Duplicate:
How to pass text in a textbox to javascript function?

I need to pass the text box value as parameter of javascript method which will be fired on button click.

<asp:TextBox ID="rowID" runat="server"> </asp:TextBox>
        <asp:Button runat="server" ID="Click" OnClientClick="PassValue(Textboxvaluehere)"/>

PassValue is JavaScript method.

Thanks in Advance.

1

3 Answers 3

1
<asp:TextBox ID="rowID" runat="server"> </asp:TextBox>
<asp:Button runat="server" ID="Click" OnClientClick="GetTextBoxValue('<%= rowID.ClientID %>')"/>



function GetTextBoxValue(textBoxID){
   var value = window.document.getElementById(textBoxID).value; }
Sign up to request clarification or add additional context in comments.

Comments

1

Or for cleaner mark-up, bind the event in code-behind at PageLoad like this

if (!IsPostBack)
{
    string script = String.Format("GetTextBoxValue('{0}')", rowID.ClientID);
    Click.Attributes.Add("onclick", script);
}

Now your mark-up can be like this.

<asp:TextBox ID="rowID" runat="server"> </asp:TextBox>
<asp:Button ID="Click" runat="server" />

Comments

0
<asp:Button runat="server" ID="Click" OnClientClick="GetTextBoxValue('<%= rowID.ClientID %>'.value)"/>

3 Comments

If i use above code its giving error like Control 'rowID' of type 'TextBox' must be placed inside a form tag with runat=server.
all asp.net server side controls much be in a `form with runat="server"'. Your textbox isnt?
No.. now added the form. But while debugging the script the rowID value is undefined. if i remove the .value from '<%= rowID.ClientID %>'.value then the debugging result of parameter is <%= rowID.ClientID %>. its not returning the actual id but retuning the statement

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.