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
MotimMotim
3 Answers 3
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
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
This has been discussed before at this thread.
answered Aug 29, 2009 at 11:50
Comments
default