我正在尝试将翻转图像添加到我正在处理的测试 DotNetNuke 页面,但似乎无法正确使用语法(对于 c# 来说完全是新的)。我敢肯定,对于有任何经验的人来说,这应该是一个简单的过程。
到目前为止,我已经尝试了几种不同的方法,其中大多数都会导致对象引用错误。这是我尝试的最后一件事(请注意下面我放置此代码的代码,该行简单地放在此处,因为这是添加其他属性的地方,我想有一个更合乎逻辑的地方放置该行?):
loginLink.Attributes.Add(" onmouseover", "this.src=(http://localhost/portals/_default/skins/BSAVA/Images/Nav/log_in_link_h.png);");
页面加载没有错误,但翻转不起作用。链接使用此属性呈现:
onmouseover="this.src=(http://localhost/portals/_default/skins/BSAVA/Images/Nav/log_in_link_h.png);"
显然不正确。
整个页面代码如下:
using System;
using System.Web;
using System.Web.UI;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Modules;
namespace DotNetNuke.UI.Skins.Controls
{
public partial class Login : SkinObjectBase
{
private const string MyFileName = "Login.ascx";
public string Text { get; set; }
public string CssClass { get; set; }
public string LogoffText { get; set; }
public string login_link_img = "http://localhost/portals/_default/skins/BSAVA/Images/Nav/log_in_link.png";
public string login_link_img_hover = "http://localhost/portals/_default/skins/BSAVA/Images/Nav/log_in_link_h.png";
public string logout_link_img_hover = "http://localhost/portals/_default/skins/BSAVA/Images/Nav/logout_link_h.png";
public string logout_link_img = "http://localhost/portals/_default/skins/BSAVA/Images/Nav/logout_link.png";
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
try
{
if (Request.IsAuthenticated)
{
loginLink.CssClass = "logoutLink";
loginLink.ImageUrl = logout_link_img;
if (!String.IsNullOrEmpty(LogoffText))
{
if (LogoffText.IndexOf("src=") != -1)
{
LogoffText = LogoffText.Replace("src=\"", "src=\"" + PortalSettings.ActiveTab.SkinPath);
}
loginLink.Text = LogoffText;
}
else
{
loginLink.Text = Localization.GetString("Logout", Localization.GetResourceFile(this, MyFileName));
}
loginLink.NavigateUrl = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Logoff");
}
else
{
loginLink.CssClass = "loginLink";
loginLink.ImageUrl = login_link_img;
if (!String.IsNullOrEmpty(Text))
{
if (Text.IndexOf("src=") != -1)
{
Text = Text.Replace("src=\"", "src=\"" + PortalSettings.ActiveTab.SkinPath);
}
loginLink.Text = Text;
}
else
{
loginLink.Text = Localization.GetString("Login", Localization.GetResourceFile(this, MyFileName));
}
string returnUrl = HttpContext.Current.Request.RawUrl;
if (returnUrl.IndexOf("?returnurl=") != -1)
{
returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?returnurl="));
}
returnUrl = HttpUtility.UrlEncode(returnUrl);
loginLink.NavigateUrl = Globals.LoginURL(returnUrl, (Request.QueryString["override"] != null));
if (PortalSettings.EnablePopUps && PortalSettings.LoginTabId == Null.NullInteger)
{
loginLink.Attributes.Add(" onclick", "return " + UrlUtils.PopUpUrl(loginLink.NavigateUrl, this, PortalSettings, true, false, 200, 550));
loginLink.Attributes.Add(" onmouseover", "this.src=(http://localhost/portals/_default/skins/BSAVA/Images/Nav/log_in_link_h.png);");
}
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
}
}
我已经做了大量的搜索,似乎有几种方法使用 JavaScript,而另一些则没有。非常感谢您对此的任何帮助,谢谢。