我试图在后面的代码中获取添加到 asp:button 的参数,但出现错误:
无法将“System.EventArgs”类型的对象转换为“System.Web.UI.WebControls.CommandEventArgs”类型
此按钮是普通表单的一部分,而不是 gridview 等。
我可能做错了什么?问候。
<form><asp:Button ID="btnPrint" runat="server" Text="Print" CommandArgument="" /></form>
Imports System.Web
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim String AS String = "MyValue"
btnPrint.CommandArgument = String
End Sub
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As CommandEventArgs) Handles btnPrint.Click
Dim ID as String = e.CommandArgument.toString
'Have also tried
'Dim btn As Button = sender
'Dim ID As String = btn.CommandArgument
Response.Redirect("Print.aspx?tid=" & ID)
End Sub