My buttons don't work!
<div id="addCompany">
<h1 class="addLink">Add a Company</h1>
<div id="addCompanyForm">
<asp:CheckBoxList ID="cbxAddCompany" runat="server"
DataSourceID="dsNewCompanies" DataTextField="CompanyName"
DataValueField="CompanyID">
</asp:CheckBoxList>
<asp:Button ID="SubmitCompanies" runat="server" Text="Submit" />
<input type="button" value="Cancel" class="addLink" />
</div>
</div>
Protected Sub SubmitCompanies_Click(sender As Object, e As System.EventArgs)
Handles SubmitCompanies.Click
Dim SqlConnection As New SqlConnection("Server=off- db1;uid=productsDB_admin;pwd=@password;database=Products")
For Each company As ListItem In cbxAddCompany.Items
If company.Selected Then
SqlConnection.Open()
Dim sqlAddCompany As String = "INSERT INTO CompanyLink (ProductID, CompanyID) VALUES (" & Produ开发者_C百科ctID.Value & ", " & company.Value & ")"
Dim sqlCommand As New SqlCommand(sqlAddCompany, SqlConnection)
sqlCommand.ExecuteNonQuery()
SqlConnection.Close()
End If
Next
Response.Redirect(Request.RawUrl)
End Sub
This is in Visual Studio 2010 VB not C#, and I can't figure out how to make the button do anything! All of the buttons on this site are set up like this and it was done by someone who is no longer with the company so I can't ask anyone for help except forums. Can anyone help me figure out why my buttons aren't firing?
Set the onClick property in the Button control:
<asp:Button ID="SubmitCompanies" runat="server" Text="Submit" onClick="SubmitCompanies_Click" />
Based on your code sample provided, my bet is that the problem is your event handler being on a seperate line.
While VB.NET allows you to specify your event handlers directly on the method, you must make sure the handler part is on the same line as the method signature OR that you preceed it with an underscore.
If you replace
Protected Sub SubmitCompanies_Click(sender As Object, e As System.EventArgs)
Handles SubmitCompanies.Click
With:
Protected Sub SubmitCompanies_Click(sender As Object, e As System.EventArgs) _
Handles SubmitCompanies.Click
You'll likely find it starts working.
Somehow the fancybox plugin will not work with checkboxes and textareas. I am going to have to redo the entire site because the guy that made this site wasn't aware that it was never going to work. :(
You are missing event on button, register onclick event for button.
if there are any validations written on button please check that first.
Otherwise i don't see any issue in click fire event.
Thanks
精彩评论