问题描述:

I have a page that has an unordered list on it. I am populating the list via javascript like this:

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:

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. So I looked through the local variables and found that my list had 5 elements all of which are 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]

More generally you can use Request.Form['clientID'] for dynamically created controls.

相关阅读:
Top