1

I need to pass the TextBox control to the JavaScript function. How do I do it

ASP.NET

OnClick="PassVal('<%= TextBox1.ClientID %>')"

JavaScript

<script type="text/javascript">
 function PassVal(ctrl, e) {
 alert(ctrl);
 }
</script>
asked Aug 29, 2009 at 11:19

3 Answers 3

2

If you are using Ms Ajax:

function Blablabla(){
 var ctrl = $get('<%= TextBox1.ClientID %>');
}

If you are using jQuery:

function Blablabla(){
 var ctrl = $('#<%= TextBox1.ClientID %>');
}

but basically it is:

function Blablabla(){
 var ctrl = document.getElementById('<%= TextBox1.ClientID %>');
}
answered Aug 29, 2009 at 11:38

Comments

0

you may modify the html that is output by accessing the Response.Body or similar. I'm not remembering the exact name.

you can then put a piece of script to it:

Response.Body += "<script type=\"text/javascript\">";
Response.Body += " PassVal(" + myControl + "," + myE + ");"
Response.Body += "</script>"

hope this helped you a bit. you have to look up the name of the property, don't got any VS here currently.

regards

answered Aug 29, 2009 at 11:26

Comments

0

This has been discussed before at this thread.

answered Aug 29, 2009 at 11:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.