Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display a dynamic text on an imagebutton.
more specifically, I have a imagebutton list in a listview, then with mouseover, the corresponding information text (e.g. from a variable) will be displayed for this imagebutton.

Any suggestions?
I have searched website and could not find a suitable solution.
many thanks.
Posted

I'm giving solution which requires jQuery and scripting stuff. On server side on data bound event of listview you can add effect like this
    protected void lvVendors_DataBound(object sender, EventArgs e)
    {
        foreach (var item in lvVendors.Items)
        {
            string cid=((LinkButton)item.FindControl("lnkbtnEdit")).ClientID;                    ScriptManager.RegisterClientScriptBlock(this,GetType(),item.ToString(),"$('"+cid+"').hover(
  function () {
  	val=document.getElementById('"+cid+"').innerText;
	document.getElementById("abc").innerText="my new text";
  }, 
  function () {
	document.getElementById('"+cid+"').innerText=val;
  }
);
",true);
        }
    }


I had used link button instead of image button you can change it easily. And you need to add script to load jQuery on your page
 
Share this answer
 
I'm giving solution which requires jQuery and scripting stuff. On server side on data bound event of listview you can add effect like this
    protected void lvVendors_DataBound(object sender, EventArgs e)
    {
        foreach (var item in lvVendors.Items)
        {
            string cid=((LinkButton)item.FindControl("lnkbtnEdit")).ClientID;                    ScriptManager.RegisterClientScriptBlock(this,GetType(),item.ToString(),"$('"+cid+"').hover(
  function () {
  	val=document.getElementById('"+cid+"').innerText;
	document.getElementById("abc").innerText="my new text";
  }, 
  function () {
	document.getElementById('"+cid+"').innerText=val;
  }
);
",true);
        }
    }


I had used link button instead of image button you can change it easily. And you need to add script to load jQuery on your page. I had tried this on simple HTML but no luck with asp.net i had posted this just to give you idea of how it can be done.
 
Share this answer
 
Comments
Seraph_summer 27-Jun-12 15:03pm    
thanks, but I can not download JQuery for the moment.
it is strange in JQuery wetsite. I will try once I can download it.
Seraph_summer 28-Jun-12 12:37pm    
I have download JQuery library, but where should I add it, like the following?
<script src="Scripts/jquery-1.7.2.js" type="text/javascript"> </script>
it seems not correct, this is only correct when I want to write the script in the script page.
Can you give me a hint?
thanks a lot!
Seraph_summer 28-Jun-12 13:23pm    
one more thing,hover function takes two function as parameters?
I do not understand here.
Seraph_summer 28-Jun-12 14:05pm    
OK, now I understand it.
but one question:'"+cid+"', why here two quoate?
shah dipen 28-Jun-12 14:09pm    
sorry i'm out for vacation so not able to answer. single quotes are for jQuery and double to append dynamic id to function.

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