来自客户端的文本框值在代码后面?

时间:2013-08-12 13:53:38

标签: javascript asp.net sql-server vb.net

我正在写一个充满活力的网站。表示所有控件都是由Response.write创建的,没有我有问题,在页面加载后我想得到文本框的值,这些文本框在代码后面动态生成,但是它没有被Request.Form接收,这里是我的代码:< / p>

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。我可以请你帮我解决这个问题吗?如何从代码后面的客户端读取这些文本框值?

1 个答案:

答案 0 :(得分:1)

您还需要添加到

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

在userconf()中。