Asp.net 我能';似乎无法获得css或以编程方式更改图像按钮图像

Asp.net 我能';似乎无法获得css或以编程方式更改图像按钮图像,asp.net,css,Asp.net,Css,这是一个由两部分组成的问题,一部分是CSS,另一部分是codebehind。。 这是我的按钮导航代码。。。 当我注释掉response.redirect时,它可以工作,但我需要能够使用response.redirect,因为它在母版页中,我需要这些按钮重定向到其他页面,当我使用response.redirect方法运行时,图像不会改变。同样,当我第一次在没有response.redirect的情况下运行它时,当我单击按钮时,它会快速跳转并返回到它应该在的位置,但之后每次都可以正常工作 因此,在

这是一个由两部分组成的问题,一部分是CSS,另一部分是codebehind。。 这是我的按钮导航代码。。。

当我注释掉response.redirect时,它可以工作,但我需要能够使用response.redirect,因为它在母版页中,我需要这些按钮重定向到其他页面,当我使用response.redirect方法运行时,图像不会改变。同样,当我第一次在没有response.redirect的情况下运行它时,当我单击按钮时,它会快速跳转并返回到它应该在的位置,但之后每次都可以正常工作

因此,在第二部分中,我也尝试使用css更改imagebuttons图像,但无法使其正常工作,我在网上搜索并阅读了教程,但即使在使用代码时,它也无法正常工作,并且我的按钮不断跳动。 我试图模仿母版页中选项卡的外观


谢谢

我会在click事件中的会话中保存一个标志,并在重定向页面预呈现中检索它:

protected override void OnPreRender(EventArgs e)
{
    if (!IsPostBack)
    {
        PaintButtons();
    }
    base.OnPreRender(e);
}
我的方法是:

private void PaintButtons()
{
    if(Session["ImageButton_Toggled"] == null )
    {               
        ImageButton1.ImageUrl = "Buttons/upviewassets.png";
        ImageButton2.ImageUrl = "Buttons/upaddassets.png";
    }
    else
    {
        int toggleId = 1;
        int.TryParse(Session["ImageButton_Toggled"].ToString(), out toggleId);

        if (toggleId == 1)
        {
            ImageButton1.ImageUrl = "Buttons/dnviewassets.png";
            ImageButton2.ImageUrl = "Buttons/upaddassets.png";
        }
        else
        {
            ImageButton1.ImageUrl = "Buttons/upviewassets.png";
            ImageButton2.ImageUrl = "Buttons/dnaddassets.png";
        }
    }
}
单击我的母版页中的事件方法:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    Session["ImageButton_Toggled"] = 1;
    Response.Redirect("~/WebForm1.aspx");
}

protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
    Session["ImageButton_Toggled"] = 2;
    Response.Redirect("~/WebForm1.aspx");        
}

现在我可以重定向到我想要的任何页面,我的母版页将按预期工作

谢谢,我也要试试这个。我试了你的答案,另一个答案基本上是一样的。但是,当它第一次加载并单击其中一个按钮时,它们似乎跳出并返回,这是什么原因呢?我需要一个流畅的转换,就像使用ajax选项卡容器时一样。我将代码从页面加载移动到预渲染以停止闪烁。它可能是我的浏览器,因为我没有得到与您相同的效果。它看起来仍然像是一个页面加载的按钮,它只在第一次点击两个按钮时才这样做,然后它将自己平衡出来,而不进行页面加载。这里有一个答案:。
private void PaintButtons()
{
    if(Session["ImageButton_Toggled"] == null )
    {               
        ImageButton1.ImageUrl = "Buttons/upviewassets.png";
        ImageButton2.ImageUrl = "Buttons/upaddassets.png";
    }
    else
    {
        int toggleId = 1;
        int.TryParse(Session["ImageButton_Toggled"].ToString(), out toggleId);

        if (toggleId == 1)
        {
            ImageButton1.ImageUrl = "Buttons/dnviewassets.png";
            ImageButton2.ImageUrl = "Buttons/upaddassets.png";
        }
        else
        {
            ImageButton1.ImageUrl = "Buttons/upviewassets.png";
            ImageButton2.ImageUrl = "Buttons/dnaddassets.png";
        }
    }
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    Session["ImageButton_Toggled"] = 1;
    Response.Redirect("~/WebForm1.aspx");
}

protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
    Session["ImageButton_Toggled"] = 2;
    Response.Redirect("~/WebForm1.aspx");        
}