Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There is not such an option of getelementbyid that I found in asp.net.
How can I change imagebutton's imageurl by it's id
and not by foreach to check al the images..?
Posted
Comments
[no name] 18-Jul-11 2:16am    
write down what you are doing in code
KUFIKU 18-Jul-11 2:21am    
string ClickedImage = img.ID;
Now I try to change the imagebutton's imageurl just by 'ClickedImage'
Al Moje 18-Jul-11 2:54am    
Hi,

getelementbyid is use in Client code not in Code behind.

1 solution

Here comes the solution my friend.

C#
function ChangeImage() {

        var img = document.getElementById('<%=ImageButton1.ClientID%>');
        img.src = 'Images/drag.gif';
        
    }


XML
<asp:ImageButton ID="ImageButton1" runat="server" />
    <asp:Button ID="Button1" runat="server" OnClientClick=" ChangeImage()"
        Text="Button" />


Here what i am doing is that when i click on the button i called the function changeImage to change the source of the image button image.

Good Luck !
 
Share this answer
 
v2
Comments
KUFIKU 18-Jul-11 2:37am    
but man I am using c#
mhamad zarif 18-Jul-11 2:44am    
so what ? this is not a vb code.This is java script which is unified ! try it and see it working.
Sergey Alexandrovich Kryukov 18-Jul-11 2:44am    
You apparently have no idea what are you using! This is ASP.NET with Javascript. You C# is irrelevant here. If you don't understand it, read on ASP.NET from the very beginning.
--SA
Sergey Alexandrovich Kryukov 18-Jul-11 2:45am    
My 5 for this answer. OP apparently does not understand the very basics of ASP.NET, so I don't know how else to help.
--SA
mhamad zarif 18-Jul-11 3:00am    
Thanks for voting.I appreciate it.!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900