在生成的按钮单击上保存表单

时间:2013-07-17 18:25:45

标签: vb.net

我正在尝试在动态生成的按钮事件上插入表单字段。表单也是动态生成的。但是,提交事件处理程序不会触发。这是我的代码:

Protected Sub BindForm()
    'select query for fetching record from database
    'dynamically generated button

    Dim btnSubmit As New Button()
    btnSubmit.ID = "btnSubmit"
    btnSubmit.Text = "Save"
    AddHandler btnSubmit.Click, AddressOf Me.btnSubmit_click
    form1.Controls.Add(btnSubmit)

End Sub

' Dynamic button click event
Protected Sub btnSubmit_click(ByVal sender As Object, ByVal e As EventArgs)
      Dim Query As String = "INSERT INTO table column values some_value"
End Sub

1 个答案:

答案 0 :(得分:4)

您需要在OnInit的{​​{1}}方法中创建,添加和连接事件。这样做后,它会在回发后绑定控件并触发事件。

Page