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>

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 %>');

}
Sign up to request clarification or add additional context in comments.

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

Comments

0

This has been discussed before at this thread.

Comments

Your Answer

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