这是为什么?为什么啊!!为什么我在两个IMG对象间赋值后不能改变IMG的任何赋给的属性???帮帮我吧,我快死了!

timeryzh 2004-08-16 04:59:08
a.aspx:
private Image menuimg2 = new Image();
menuimg2.ImageUrl = img2off;
menuimg2.Attributes.Add("OnMouseover","this.src=" + img2on);
menuimg2.Attributes.Add("OnMouseout","this.src=" + img2off);
menuimg2.Attributes.Add("OnClick","location.href = " + img2URL);
public Image MenuImg2
{
get{return menuimg2;}
}
b.aspx:
protected System.Web.UI.WebControls.Image IMG2;
.....//调用a.aspx中的方法返回一个img对象赋给这个页面中放置的一个img控件
IMG2 = loadmenu.MenuImg2;

在menuimg中设置了所有需要的属性后赋给IMG2时没有一点反映,但在调试的时候可以看到每个属性的值都赋过去了就是在客户端生成后所有的属性都是空的。
各位帮帮我吧,我快死了~~
...全文
88 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
timeryzh 2004-08-17
  • 打赏
  • 举报
回复
end
moonewxp 2004-08-16
  • 打赏
  • 举报
回复
你这种方法不好,用你的页面中这些img空间的父控件的control.add方法,把你从loadmenu.MenuImg1;返回的控件加到父控件的集合中,你那样做不行的
rickjelly2004 2004-08-16
  • 打赏
  • 举报
回复
ImageButton1.Attributes.Add("onMouseOver", " return showm();")
ImageButton1.Attributes.Add("onMouseOut", "return shown();")
rickjelly2004 2004-08-16
  • 打赏
  • 举报
回复
<script language="javascript">
function showm()
{
var oment;
var id="ImageButton1";
oment=document.getElementById(id);
oment.src="/test4/Misc32.ico";
return false;
}
function shown()
{
var oment;
var id="ImageButton1";
oment=document.getElementById(id);
oment.src="ndpsetup.ico";
return false;
}
conghui 2004-08-16
  • 打赏
  • 举报
回复
将属性设为静态(static)的试,这只是我建议,希望对你所有帮助。
沈逸 2004-08-16
  • 打赏
  • 举报
回复
menuimg2.Attributes.Add("OnMouseover","this.src='" + img2on+"'");
加个单引号试下子呢
timeryzh 2004-08-16
  • 打赏
  • 举报
回复
a.aspx:
namespace NJKL.Control
{
/// <summary>
/// PowerController 的摘要说明。
/// </summary>
public class PowerController
{
private int _userid, _companyid, _companycategory;
private string _username;
private const int MENUNUM = 6;

private HtmlImage menuimg1 = new HtmlImage();
private HtmlImage menuimg2 = new HtmlImage();
private HtmlImage menuimg3 = new HtmlImage();
private HtmlImage menuimg4 = new HtmlImage();
private HtmlImage menuimg5 = new HtmlImage();
private HtmlImage menuimg6 = new HtmlImage();

private const string img1off = "../images/menubut1_off.gif";
private const string img1on = "../images/menubut1_on.gif";
private const string img1URL = "../ManageVehiclep.aspx";
private const string img2off = "../images/menubut2_off.gif";
private const string img2on = "../images/menubut2_on.gif";
private const string img2URL = "../ManageCorp.aspx";
private const string img3off = "../images/menubut3_off.gif";
private const string img3on = "../images/menubut3_on.gif";
private const string img3URL = "../ManageUser.aspx";
private const string img4off = "../images/menubut4_off.gif";
private const string img4on = "../images/menubut4_on.gif";
private const string img4URL = "../ModefiyPWD.aspx";
private const string img5off = "../images/menubut5_off.gif";
private const string img5on = "../images/menubut5_on.gif";
private const string img5URL = "../ManageDriver.aspx";
private const string img6off = "../images/menubut6_off.gif";
private const string img6on = "../images/menubut6_on.gif";
private const string img6URL = "../ServiceStatistical.aspx";
private const string img7off = "../images/menubut7_off.gif";
private const string img7on = "../images/menubut7_on.gif";
private const string img7URL = "../ManageLog.aspx";

public HtmlImage MenuImg1
{
get{
return menuimg1;
}
}

public HtmlImage MenuImg2
{
get
{
return menuimg2;
}
}

public HtmlImage MenuImg3
{
get
{
return menuimg3;
}
}

public HtmlImage MenuImg4
{
get
{
return menuimg4;
}
}

public HtmlImage MenuImg5
{
get
{
return menuimg5;
}
}

public HtmlImage MenuImg6
{
get
{
return menuimg6;
}
}

public PowerController(UserInfo currentUser)
{
//
// TODO: 在此处添加构造函数逻辑
//
_userid = currentUser.UserID;
_companyid = currentUser.Company;
_username = currentUser.UserName;
_companycategory = currentUser.CompanyCategory;
}

public void LoadMenu()
{

switch(_companycategory)
{
case 0://中心用户
{
//车辆管理
menuimg1.Src = img1off;
menuimg1.Attributes.Add("OnMouseover","this.src=" + img1on);
menuimg1.Attributes.Add("OnMouseout","this.src=" + img1off);
menuimg1.Attributes.Add("OnClick","location.href = " + img1URL);

//公司管理
menuimg2.Src = img2off;
menuimg2.Attributes.Add("OnMouseover","this.src=" + img2on);
menuimg2.Attributes.Add("OnMouseout","this.src=" + img2off);
menuimg2.Attributes.Add("OnClick","location.href = " + img2URL);

//用户管理
menuimg3.Src = img3off;
menuimg3.Attributes.Add("OnMouseover","this.src=" + img3on);
menuimg3.Attributes.Add("OnMouseout","this.src=" + img3off);
menuimg3.Attributes.Add("OnClick","location.href = " + img3URL);

//修改密码
menuimg4.Src = img4off;
menuimg4.Attributes.Add("OnMouseover","this.src=" + img4on);
menuimg4.Attributes.Add("OnMouseout","this.src=" + img4off);
menuimg4.Attributes.Add("OnClick","location.href = " + img4URL);

break;
}
case 1://总公司用户
case 2://子公司用户
{
//车辆管理
menuimg1.Src = img1off;
// menuimg1.Attributes.Add("OnMouseover","this.src=" + img1on);
// menuimg1.Attributes.Add("OnMouseout","this.src=" + img1off);
// menuimg1.Attributes.Add("OnClick","location.href = " + img1URL);

//公司管理
menuimg2.Src = img2off;
menuimg2.Attributes.Add("OnMouseover","this.src=" + img2on);
menuimg2.Attributes.Add("OnMouseout","this.src=" + img2off);
menuimg2.Attributes.Add("OnClick","location.href = " + img2URL);

//驾驶员管理
menuimg3.Src = img5off;
menuimg3.Attributes.Add("OnMouseover","this.src=" + img5on);
menuimg3.Attributes.Add("OnMouseout","this.src=" + img5off);
menuimg3.Attributes.Add("OnClick","location.href = " + img5URL);

//营运统计
menuimg4.Src = img6off;
menuimg4.Attributes.Add("OnMouseover","this.src=" + img6on);
menuimg4.Attributes.Add("OnMouseout","this.src=" + img6off);
menuimg4.Attributes.Add("OnClick","location.href = " + img6URL);

//日志统计
menuimg5.Src = img7off;
menuimg5.Attributes.Add("OnMouseover","this.src=" + img7on);
menuimg5.Attributes.Add("OnMouseout","this.src=" + img7off);
menuimg5.Attributes.Add("OnClick","location.href = " + img7URL);

//修改密码
menuimg6.Src = img4off;
menuimg6.Attributes.Add("OnMouseover","this.src=" + img4on);
menuimg6.Attributes.Add("OnMouseout","this.src=" + img4off);
menuimg6.Attributes.Add("OnClick","location.href = " + img4URL);

break;
}

default:
{

break;
}
}
}
}
}
b.ascx:
namespace NJKL.WebControl
{
using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using NJKL.Model;
using NJKL.Control;

/// <summary>
/// headmenu 的摘要说明。
/// </summary>
public class headmenu : System.Web.UI.UserControl
{

protected System.Web.UI.HtmlControls.HtmlImage IMG2;
protected System.Web.UI.HtmlControls.HtmlImage IMG3;
protected System.Web.UI.HtmlControls.HtmlImage IMG4;
protected System.Web.UI.HtmlControls.HtmlImage IMG5;
protected System.Web.UI.HtmlControls.HtmlImage IMG6;
protected System.Web.UI.HtmlControls.HtmlImage IMG1;

private const string DEFAULTURL = "default.aspx";

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
{
if(Session["ACCOUNT_KEY"] != null)
{
PowerController loadmenu = new PowerController((UserInfo)Session["ACCOUNT_KEY"]);

loadmenu.LoadMenu();
IMG1 = loadmenu.MenuImg1;
IMG2 = loadmenu.MenuImg2;
IMG3 = loadmenu.MenuImg3;
IMG4 = loadmenu.MenuImg4;
IMG5 = loadmenu.MenuImg5;
IMG6 = loadmenu.MenuImg6;
}
else
Response.Redirect(DEFAULTURL);
}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
moonewxp 2004-08-16
  • 打赏
  • 举报
回复
再多贴点程序,
timeryzh 2004-08-16
  • 打赏
  • 举报
回复
D

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧