vb中完全相同的代码是什么?
using System.Web.UI.WebControls;
.
.
.
protected virtual void CheckFavorite(object sender, EventArgs e) {
if (Session["favorite"] != null) {
if ((!string.IsNullOrEmpty((string)Session["favorite"])) && ((string)Session["favorite"] == Request.RawUrl)) {
Image img = (Image)sender;
img.ImageUrl = img.ImageUrl.Replace("/favoritetransparent.png", "/unfavoritetransparent.png");
}
}
}
我已经制作了以下vb代码,其中包含了' Image'是Type,不能用作表达式错误。
Imports System.Web.UI.WebControls
.
.
.
Protected Overridable Sub CheckFavorite(ByVal sender As Object, ByVal e As System.EventArgs)
If Not String.IsNullOrEmpty(Session("favorite")) Then
If Not String.IsNullOrEmpty(Session("favorite").ToString()) AndAlso (Session("favorite").ToString() = Request.RawUrl) Then
Dim img As Image
Image img = (Image)sender
img.ImageUrl = img.ImageUrl.Replace("/favoritetransparent.png", "/unfavoritetransparent.png")
End If
End If
End Sub
我在'图片img =(图片)发件人'
上收到错误提前致谢。
答案 0 :(得分:2)
尝试更改这些行:
Dim img As Image
Image img = (Image)sender
到此:
Dim img As Image = CType(sender, Image)