Is it possible to set the ClientID
of any asp.net server control? How can I do this?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
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.But as others have noted, you can't do it from outside.
For VS 2010, .NET 4.0:
If you just try to set
ctrl.ClientID="stringID"
you will get an Error, saying that ClientID is read only. You can control the value of ClientID using ClientIDMode - which defines the algorithm with which ClientID is set:The html markup will mark your control's html with the control's ID. Thus you have some degree of control from the code-behind.
ASP.NET 4 has ClientIDMode property on each control for that. If you want to turn off ClientID completely you can use this trick - it works for any non-postback control
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
That's not possible. The ClientID is generated by ASP.NET. From MSDN:
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: