views:

59

answers:

3
<img src ="~/UserControls/Vote/Images/Arrow Up.png" id = "vote-up-off" 
        runat = "server" alt ="vote up" 
class="voteupImage" style="height: 45px; width: 44px"/>

here i want to change src of image for certain condition like

if ( a==4)
{
src  url  shuld be ......
}
else
{ 
src  url should be...
}
+1  A: 

You'll want to change the id to something without hyphens, but then it would be

voteUpOff.Attributes["src"] = "myImage.png";
jarrett
+2  A: 

First you need to give an id name which can be used as variable:

<img src="~/UserControls/Vote/Images/Arrow Up.png" 
     id="VoteUpOff" 
     runat="server" alt ="vote up" 
     class="voteupImage" 
     style="height: 45px; width: 44px"
/>

And in your code behind you could use this variable:

if (someCondition)
{
    VoteUpOff.Attributes["src"] = ResolveUrl("~/UserControls/foo.png");
}
Darin Dimitrov
+1  A: 

HTML

<img src="~/UserControls/Vote/Images/Arrow Up.png" 
         id="VoteUpOff" 
         runat="server" alt ="vote up" 
         class="voteupImage" 
         style="height: 45px; width: 44px"
    />

Server-Side

if (someCondition)
{
    VoteUpOff.Attributes["src"] = ResolveUrl("~/UserControls/foo.png");
}

Keep In mind to see the changes you have to place the "img" in UpdatePanel After doing the changes Update the UpdatePanel if its UpdateMode=Conditional otherwise it'll update automatically if its Property ChildAsTriggers=True

KhanZeeshan