[英]VB.Net Handles button click event in code behind
Having an issue with my button click event. 我的按钮点击事件有问题。 I needed to add this button from one page to another so naturally it was copied and variables changed out within the click event method to match the new page.
我需要将此按钮从一页添加到另一页,因此很自然地将其复制并在click事件方法中更改了变量以匹配新页面。 in the HTML side I added the button there too (stating in case someone wonders if I forgot that part).
在HTML端,我也在该处添加了按钮(以防万一有人怀疑我是否忘记了该部分)。
Everything is identical to the other page... The issue is... when I try to run it to test the button I get a build error with no errors being displayed. 一切都与另一页相同...问题是...当我尝试运行它以测试按钮时,我得到一个构建错误,没有显示任何错误。 One time I managed to get an error that stated "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."
有一次我设法得到一个错误,指出“ Handles子句需要在包含类型或其基本类型之一中定义一个WithEvents变量”。 So I commented out the handles portion of the method and it runs yay!
因此,我注释掉了该方法的handles部分,它可以运行! except... the button doesn't work.
除了...按钮不起作用。 I have tried a few suggestions that stated to restart the IDE, and where someone also mentioned to comment out the handles portion.
我尝试了一些建议来重新启动IDE,以及有人提到注释掉句柄部分的建议。 Is there something I am missing?
我有什么想念的吗?
<tr>
<td style="width: 209px" valign="middle" align="left"></td>
<td style="width: 7px;" valign="middle"></td>
<td valign="bottom" align="left">
<br>
<asp:Button ID="btnSaveAsExcel" runat="server" Width="264px" Text="Export to Excel"></asp:Button>
</td>
<td valign="middle" align="left"></td>
</tr>
Private Sub btnSaveAsExcel_Click(sender As Object, e As EventArgs) Handles btnSaveAsExcel.Click
If dgFacilitySummary.Visible Then
Dim DummydgFacilitySummary As New DataGrid
DummydgFacilitySummary.DataSource = Session("dsFacilitySummary").tables(0)
DummydgFacilitySummary.DataBind()
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" & "Faci+lity Summary Report" & ".xls")
HttpContext.Current.Response.Charset = ""
EnableViewState = False
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
DummydgFacilitySummary.RenderControl(hw)
HttpContext.Current.Response.Write(sw.ToString())
HttpContext.Current.Response.End()
ElseIf dgFacilities.Visible Then
Dim DummydgFacilities As New DataGrid
DummydgFacilities.DataSource = Session("dsFacilityMatches").tables(0)
DummydgFacilities.DataBind()
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" & "Facility Summary Report" & ".xls")
HttpContext.Current.Response.Charset = ""
EnableViewState = False
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
DummydgFacilities.RenderControl(hw)
HttpContext.Current.Response.Write(sw.ToString())
HttpContext.Current.Response.End()
End If
End Sub
both of that is exactly how it is on another page and it works there. 两者正是在另一页上的方式,并在那里工作。
Try deleting the btnSaveAsExcel_Click() method from your code behind file. 尝试从文件后面的代码中删除btnSaveAsExcel_Click()方法。 Then select btnSaveAsExcel in the drop down list on the upper left of the IDE just above your code.
然后在代码上方IDE左上方的下拉列表中选择btnSaveAsExcel。 That will populate the drop down list on the upper right with all the events for the btnSaveAsExel button.
这将使用btnSaveAsExel按钮的所有事件填充右上角的下拉列表。 Select the OnClick event and that will create a btnSaveAsExcel_Click() method.
选择OnClick事件,它将创建一个btnSaveAsExcel_Click()方法。
It would probably be a good idea to only copy the markup and then use the method I just described to create the event handlers in the code behind file. 仅复制标记,然后使用我刚刚描述的方法在文件背后的代码中创建事件处理程序可能是一个好主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.