Is is possible to set clientID of any asp.net server control?
How can i do?
Or any idea ?
Is is possible to set clientID of any asp.net server control?
How can i do?
Or any idea ?
That's not possible. The ClientID is generated by ASP.NET. From MSDN:
The ClientID value is generated by concatenating the ID value of the control and the UniqueID value of its parent control. If the ID value of the control is not specified, an automatically generated value is used.
Even i think it is not possible in Visual studio 2008 . Because Control.ClientID Property has only get method
Edit :But in Visual studio 2010(.Net 4.0) it is possible
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.