Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set ClientID in asp.net

Is it possible to set the ClientID of any asp.net server control? How can I do this?

like image 772
ebattulga Avatar asked Sep 15 '09 17:09

ebattulga


2 Answers

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>
like image 127
Michael La Voie Avatar answered Nov 03 '22 09:11

Michael La Voie


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.

like image 37
Chetan S Avatar answered Nov 03 '22 09:11

Chetan S