Is it possible to set the ClientID
of any asp.net server control? How can I do this?
The good news is that in VS 2010 .Net 4, you'll have complete control over Client IDs!
Still for the current versions of .Net, you can make due. I assume you need the ID for JavaScript. If so, just get the ID like so:
<script type="text/javascript">
var myTextBox = $('#<%=TextBox1.ClientID%>');
</script>
I would advice against doing this unless you are sure you want to do it, but there is a way. You can override the ClientID
property from within the server control.
public override string ClientID
{
get { return "whatever"; }
}
But as others have noted, you can't do it from outside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With