简体   繁体   English

在codebehind中添加一个表,使用javascript来获取它的getElementById? asp.net

[英]Add a table in codebehind, getElementById it using javascript? asp.net

If you create a table and add it, the ClientID property in the code behind doesn't reflect the ID in the actual file, so document.getElementById doesn't work. 如果创建表并将其添加,则后面代码中的ClientID属性不会反映实际文件中的ID,因此document.getElementById无效。

How can I add a control, and be able to access it using Javascript, with only its ID (such as 'table1')? 如何添加仅具有ID(例如“ table1”)的控件,并能够使用Java脚本访问它?

You will have to render the "ClientId" out to the browser and then grab that value to be able to use it via Javascript. 您必须将“ ClientId”呈现给浏览器,然后获取该值才能通过Javascript使用它。

Starting with .NET 4.0, this will no longer be an issue as you can change the behavior of the iNamingContainer and the id structures. 从.NET 4.0开始,这不再是问题,因为您可以更改iNamingContainer和id结构的行为。

您可以动态地将javascript变量设置为新表的ClientID,然后在getElementById中使用其值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM