![](/img/trans.png)
[英]Calling a click event or JQuery function from the code behind VB.NET
[英]VB.Net Handles button click event in code behind
我的按鈕點擊事件有問題。 我需要將此按鈕從一頁添加到另一頁,因此很自然地將其復制並在click事件方法中更改了變量以匹配新頁面。 在HTML端,我也在該處添加了按鈕(以防萬一有人懷疑我是否忘記了該部分)。
一切都與另一頁相同...問題是...當我嘗試運行它以測試按鈕時,我得到一個構建錯誤,沒有顯示任何錯誤。 有一次我設法得到一個錯誤,指出“ Handles子句需要在包含類型或其基本類型之一中定義一個WithEvents變量”。 因此,我注釋掉了該方法的handles部分,它可以運行! 除了...按鈕不起作用。 我嘗試了一些建議來重新啟動IDE,以及有人提到注釋掉句柄部分的建議。 我有什么想念的嗎?
<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
兩者正是在另一頁上的方式,並在那里工作。
嘗試從文件后面的代碼中刪除btnSaveAsExcel_Click()方法。 然后在代碼上方IDE左上方的下拉列表中選擇btnSaveAsExcel。 這將使用btnSaveAsExel按鈕的所有事件填充右上角的下拉列表。 選擇OnClick事件,它將創建一個btnSaveAsExcel_Click()方法。
僅復制標記,然后使用我剛剛描述的方法在文件背后的代碼中創建事件處理程序可能是一個好主意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.