Cannot pass value to page through HtmlGenericControl Property

62 views Asked by At

Here is the .aspx file

<form id="form1" runat="server">            
    <input type="text" id="StringValue" runat="server"/>
    <datalist id="dataList" runat="server"></datalist>
    <% CreateContent(_sql)%>
</form>

And here is the .vb file (CreateContent)

Protected Sub CreateContent(ByVal sql As String)

    Dim optList As New List(Of String)
    optList = GetData(sql)

    Dim table As New DataTable()
    table.Columns.Add(New DataColumn("DataOptions"))
    For Each opt In optList
        table.Rows.Add(opt)
    Next
    For Each row In table.Rows
        dataList.InnerHtml = dataList.InnerHtml & vbCrLf & String.Format("<option value='{0}'>", row(0))
    Next
    MsgBox(dataList.InnerHtml)

End Sub

When I tested the page, the MsgBox could actually show all the <option> elements. However, these contents can only exist in server side. <datalist> is always empty in page source. Anyone can explain what prevent the content being passed to the page and how to solve it?

0

There are 0 answers