Reputation: 377
I have the following 2 elements: DropDownList
<asp:DropDownList id="DropPoke1" Width="80" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropPoke1_SelectedIndexChanged">
<asp:ListItem Value="1">Test</asp:ListItem>
<asp:ListItem Value="2">asd</asp:ListItem>
<asp:ListItem Value="3">FF</asp:ListItem>
</asp:DropDownList>
Image
<asp:Image ID="imgPoke1" Height="80" Width="80" runat="server" ImageUrl="../Images/orderedList0.png"/>
In the codebehind, I want to change the image:
protected void DropPoke1_SelectedIndexChanged(object sender, EventArgs e)
{
imgPoke1.ImageUrl = "~/Images/HomePicture.png";
}
Unfortunately, this doesn't seem to do anything.
Upvotes: 0
Views: 573
Reputation: 187
Are you using updatepanel? If yes, put image control inside the updatepanel.
Upvotes: 1
Reputation: 1656
Try to do next:
Your design page:
<asp:DropDownList id="DropPoke1" Width="80" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropPoke1_SelectedIndexChanged">
<asp:ListItem Value="1">Test</asp:ListItem>
<asp:ListItem Value="2">asd</asp:ListItem>
<asp:ListItem Value="3">FF</asp:ListItem>
</asp:DropDownList>
<asp:Image ID="imgPoke1" Height="80" Width="80" runat="server" />
Your code behind:
protected void Page_Load(object sender, EventArgs e){
if(!IsPostBack)
imgPoke1.ImageUrl = "~/Images/orderedList0.png";
}
protected void DropPoke1_SelectedIndexChanged(object sender, EventArgs e)
{
imgPoke1.ImageUrl = "~/Images/HomePicture.png";
}
Upvotes: 2