拥有这段代码:
<asp:LinkButton runat="server" OnClick="ChangeImage_Click" >
<img src="imagethatshouldbechanged" />
</asp:LinkButton>
而且:
protected void ChangeImage_Click(object sender, EventArgs e)
{
//Code here
}
单击链接按钮时如何更改图像。
答案 0 :(得分:0)
您需要制作img runat="server"
并为其分配ID才能在ChangeImage_Click
中访问或使用asp:Image代替img
HTML
<asp:LinkButton runat="server" OnClick="ChangeImage_Click" >
<img id="img1" runat="server" src="imagethatshouldbechanged" />
</asp:LinkButton>
代码bahind
protected void ChangeImage_Click(object sender, EventArgs e)
{
img1.Src = "url";
}
答案 1 :(得分:0)
试试这种方式
<asp:LinkButton runat="server" OnClick="ChangeImage_Click" >
<img runat="server" id="myImage" src="imagethatshouldbechanged" />
</asp:LinkButton>
protected void ChangeImage_Click(object sender, EventArgs e)
{
myImage.Src="YourImagePath";//Like App/app1/image1.jpeg
}