Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem passing an asp.net control to my js-function 1

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
AN
Hi everyone,
I wrote some JS. I have an asp-imagebutton (within a formview)and js-function. On mouseover of the button the function will be called and it will get the src from the imagebutton. All works ok. But how could I pass the control dynamically into the function and then take its src (ImageUrl) so i can call it from any imagebutton?

Code:
<asp:ImageButton ID="ImageButton1" runat="server" Height="60px" ImageUrl='<%#Eval("ApartmentPhotoPath")%>' 
Width="90px" onmouseover="showPhoto1()" />


<script language="javascript" type="text/javascript">
<!-- 
function showPhoto1() 
{
    var imgOrg = document.getElementById('<%=FormView3.FindControl("ImageButton1").ClientID%>')
    var strPath = imgOrg.src
    var imgTest2 = document.getElementById("imgBigImage")
    imgTest2.src = strPath
}
-->
</script>

Pampers [afro]
Keeping it simple can be complicated
 
Code:
<asp:ImageButton ID="ImageButton1" runat="server" Height="60px" ImageUrl='<%#Eval("ApartmentPhotoPath")%>'
Width="90px" onmouseover="showPhoto1([COLOR=blue]this[/color]);" />
Code:
function showPhoto1(imgOrg)
{
    document.getElementById("imgBigImage").src = imgOrg.src;
}
if my js knowledge is correct you might even be able to write it like this.
Code:
<asp:ImageButton ID="ImageButton1" runat="server" Height="60px" ImageUrl='<%#Eval("ApartmentPhotoPath")%>'
Width="90px" onmouseover="showPhoto1();" />
Code:
function showPhoto1()
{
    document.getElementById("imgBigImage").src = this.src;
}
js passes the current control and event(?) automatically by default.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Hi jmeckley,
Thanks a lot for your reply and answers. First solution works fine. Second one doesnt work.

Pampers [afro]
Keeping it simple can be complicated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top