1

我正在编写一个完全动态的网站。意味着所有控件都是由 Response.write 制作的,不,我有一个问题,在页面加载后我想获取在代码后面动态生成的文本框的值,但 Request.Form 没有收到它,这是我的代码:

Private Function userconf() As string
    Dim script As String

    Dim conString As String = ConfigurationManager.ConnectionStrings("sqlexpress").ConnectionString
    Using con As New System.Data.SqlClient.SqlConnection(conString)

        Dim com As New SqlCommand("SELECT * FROM clientamount WHERE Mode <> 1 ", con)


        con.Open()

        Dim resultid As String
        Dim reader As SqlDataReader = com.ExecuteReader()
        Try
            While reader.Read()

                RenderBuyForm = RenderBuyForm + "<div><input id='tx" & reader("ID") & "' type='text'  />" & reader("avrageamountunit") & "<input id='txd" & reader("ID") & "' type='text'/>"
            End While
        Finally

            reader.Close()
        End Try


    End Using


    Return RenderBuyForm
End Function

这个函数在 page_preload 事件中加载:

   Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad
    userconf()


    End If
End Sub

而且在我的html页面中

<form id="form1" runat="server">
   <%=RenderBuyForm%>

    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </form>

至少我现在尝试在 Button1_Click 事件中读取文本框值在 html 页面中:

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click



    For Each row As DataRow In tabel1.Rows

        Dim a As String = Request.Form("tx" & tabel1.Rows(0)("ID") & "")

      label1.text = a 


    Next
End Sub

但是 a 正在返回 Nothing 。我可以请你帮我解决这个问题吗?如何在后面的代码中从客户端读取这些文本框值?

4

1 回答 1

1

您还需要添加到

RenderBuyForm = RenderBuyForm + "<div><input id='tx" ....
RenderBuyForm = RenderBuyForm + "<div><input name='tx' & reader("ID") ..

在用户配置()中。

于 2013-08-12T14:11:30.557 回答