vb.net按钮单击事件问题

时间:2015-11-09 14:37:01

标签: asp.net vb.net

`                                           

注册

                                                          
            

注册


                       

                 

               </div>
                  <table style="width: 100%;" align="center">
                      <tr>
                          <td>Name</td>
                          <td class="text-left">
                              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                              <asp:TextBox ID="vreg_name_txt" runat="server"></asp:TextBox>
                          </td>
                        </tr>
                      <tr>
                          <td>Contacct No.</td>
                          <td class="text-left">
                              <asp:TextBox ID="vreg_con_txt" runat="server"></asp:TextBox>
                          </td>

                      </tr>
                       <tr>
                          <td>Email</td>
                          <td class="text-left">
                              <asp:TextBox ID="vreg_email_txt" runat="server"></asp:TextBox>
                           </td>

                      </tr>
                      <tr>
                          <td>State</td>
                          <td class="text-left">
                              <asp:DropDownList ID="vreg_state_dl" runat="server">
                                  <asp:ListItem>gujrat</asp:ListItem>
                              </asp:DropDownList>
                          </td>

                      </tr>
                      <tr>
                          <td>City</td>
                          <td class="text-left">
                              <asp:DropDownList ID="vreg_city_dl" runat="server">
                                  <asp:ListItem>surat</asp:ListItem>
                              </asp:DropDownList>
                          </td>

                      </tr>
                      <tr>
                          <td>Location</td>
                          <td class="text-left">
                              <asp:DropDownList ID="vreg_loc_dl" runat="server">
                                  <asp:ListItem>katargam</asp:ListItem>
                                  <asp:ListItem>adajan</asp:ListItem>
                                  <asp:ListItem>piplod</asp:ListItem>
                                  <asp:ListItem>chok</asp:ListItem>
                              </asp:DropDownList>
                              <br />
                              <asp:TextBox ID="vreg_area_txt" runat="server"></asp:TextBox>
                          </td>

                      </tr>
                      <tr>
                          <td>Username</td>
                          <td class="text-left">
                              <asp:TextBox ID="v_user_txt" runat="server"></asp:TextBox>
                          </td>

                      </tr>
                      <tr>
                          <td>Password</td>
                          <td class="text-left">
                              <asp:TextBox ID="v_pass_txt" runat="server" TextMode="Password"></asp:TextBox>
                          </td>

                      </tr>
                      <tr>
                          <td class="auto-style2">Confirm password</td>
                          <td class="auto-style3">
                              <asp:TextBox ID="v_conf_pass_txt" runat="server" TextMode="Password"></asp:TextBox>
                          </td>

                      </tr>


                      <tr>
                          <td colspan="2">
                              <asp:Button ID="reg_btn" runat="server" Text="register" />
                          </td>

                      </tr>


                  </table>
              </div>
          </div>
        </div>
    </section>`

我正在编写一个程序,在按钮点击事件中在数据库中插入值。 。该程序正在使用vb.net如果我运行该应用程序,当我单击该按钮时,它不会触发该按钮的单击事件。帮我纠正。这是我的代码: &#39;&#39;

Imports System.Data
Imports System.IO
Imports System.Data.SqlClient

Partial Class main
Inherits System.Web.UI.Page
Dim command As SqlCommand
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim i As Integer
Dim str As String = ConfigurationManager.ConnectionStrings("con").ConnectionString
Dim con As New SqlConnection(str)

'Protected Sub REGISTER_Click(sender As Object, e As EventArgs) Handles REGISTER.Click

'End Sub

Protected Sub Login_Click(sender As Object, e As EventArgs) Handles Login.Click
    If (Page.IsValid) Then

        Dim intusercount As SqlDataReader
        Dim a, b As String
        Using connection As New SqlConnection("Data Source=DESKTOP-LHSLB8R;Initial Catalog=temp_db;Integrated Security=True")
            Using command As New SqlCommand("SELECT [v_id],[v_name] FROM [vendor_mstr] WHERE [v_user]=@Username AND [v_pass]=@Password", connection)
                command.Parameters.Add("@Username", Data.SqlDbType.VarChar, 50).Value = username_txt.Text
                command.Parameters.Add("@Password", Data.SqlDbType.VarChar, 50).Value = password_txt.Text
                connection.Open()
                intusercount = command.ExecuteReader
                'Dim red As SqlDataReader =command.ExecuteReader
                If intusercount.HasRows Then
                    While intusercount.Read()
                        MsgBox(intusercount.Item(0))
                        a = intusercount.Item(0)
                        b = intusercount.Item(1)
                    End While
                    Session("uid") = a
                    Session("user") = b
                    Response.Redirect("v_h.aspx")
                Else
                    MsgBox("invalid username or password")
                End If
                connection.Close()
            End Using
        End Using

    End If

End Sub

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Session.Remove("uid")
    Session.Remove("user")

End Sub


Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles reg_btn.Click
    MsgBox("click")
    Try
        con.Open()
        command = New SqlCommand("INSERT INTO vendor_mstr(v_name,v_area,v_contact,v_email,v_loc,v_user,v_pass,v_city,v_state)VALUES('" & vreg_name_txt.Text & "','" & vreg_area_txt.Text & "','" & vreg_con_txt.Text & "','" & vreg_email_txt.Text & "','" & vreg_loc_dl.SelectedValue & "','" & v_user_txt.Text & "','" & v_pass_txt.Text & "','" & vreg_city_dl.SelectedValue & "','" & vreg_state_dl.SelectedValue & "')")
        command.Connection = con
        command.ExecuteNonQuery()
        con.Close()
        MsgBox("registered :)")
    Catch ex As Exception
        MsgBox("not registered :(")
    End Try


End Sub

结束班

1 个答案:

答案 0 :(得分:0)

更改此

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles reg_btn.Click

用这个:

 Protected Sub reg_btn_Click(sender As Object, e As EventArgs) Handles reg_btn.Click