[英]Can't access Dynamically created html elements from code behind
I have a page that has an unordered list on it. 我的页面上有无序列表。 I am populating the list via javascript like this:
我通过javascript这样填充列表:
var vidList = document.getElementById("vidList");
var li = document.createElement("li");
li.id = "videoPlayer" + count;
var runat = document.createAttribute("runat");
runat.value = "server";
li.setAttributeNode(runat);
// Here I insert a flash video stream into li
vidlist.appendChild(li);
This works as far as creating the elements and rendering them to the page. 就创建元素并将其呈现到页面而言,这是可行的。 The issue is accessing them later.
问题是稍后再访问它们。 Since they are video streams I want to remove them when they are no longer valid streams.
由于它们是视频流,因此我想在它们不再有效时将其删除。 In my Visual Basic code behind I have the following code:
在后面的Visual Basic代码中,我有以下代码:
For videoNumber As Integer = 1 to numVideos
Dim li = vidList.FindControl("videoPlayer" & videoNumber.toString())
// Check if the stream is valid and delete it if it isn't
Next
When I debug the call to FindControl
returns Nothing
. 当我调试时,对
FindControl
的调用将返回Nothing
。 So I looked through the local variables and found that my list had 5 elements all of which are Nothing
. 因此,我通过本地变量看了看,发现我的名单有5个元素所有这些都
Nothing
。 I looked at both this question and this one , but neither quite worked for my needs. 我看着都这个问题与这一个 ,但我既不需要相当的工作。 Is there a reason that the list items are coming into the code behind as null values?
列表项是否作为空值进入代码背后是否有原因?
Request.Form['videoPlayer' + count]
通常,您可以将Request.Form['clientID']
用于动态创建的控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.