前台.aspx<html>
 <head>
  <title> New Document </title>
 </head> <body>
    <img alt=""/>
 </body>
</html>后台.cs      
 protected void Button_Click(object sender, EventArgs e)
  {
//代码
}前台的img怎么加个点击事件调用后台的Button_Click方法不要说换成<asp:ImageButton ID="ImageButton1" runat="server" />控件

解决方案 »

  1.   


    http://blog.csdn.net/porschev/archive/2010/10/15/5943579.aspx
      

  2.   

    通过ajax传值到ashx等实现数据添加或
    实现ICallbackEventHandler接口
    public partial class _Callback : System.Web.UI.Page,ICallbackEventHandler
    {
    }  
     
      

  3.   

    <img alt=""/ Onclick=Btn();runat=server>
      

  4.   

    function test(name)
    {
      ajax请求url="xx.aspx?name=" + name}
      

  5.   

    一种是ajax,一种js直接触发事件如:onclick=document.getElementById("Button").click();
      

  6.   

    <img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" onclick="alert(1);" onkeypress="if(event.keyCode=='13') alert(1);" tabindex="0" />用jquery的话,完整代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="jquery.js"></script><script>$(function() { $("img").click(function() { alert(1); }).keypress(function(e) { //其他按键自己把keyCode加上就行 if(e.keyCode==13) $(this).trigger('click'); });});</script></head><body><img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" tabindex="0" /><a href="javascript:alert(2);">click me</a><input type="button" value="点我" onclick="alert(3);"></body></html>
      

  7.   

    <img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" onclick="alert(1);" onkeypress="if(event.keyCode=='13') alert(1);" tabindex="0" />用jquery的话,完整代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="jquery.js"></script><script>$(function() { $("img").click(function() { alert(1); }).keypress(function(e) { //其他按键自己把keyCode加上就行 if(e.keyCode==13) $(this).trigger('click'); });});</script></head><body><img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" tabindex="0" /><a href="javascript:alert(2);">click me</a><input type="button" value="点我" onclick="alert(3);"></body></html>
      

  8.   

    <img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" onclick="alert(1);" onkeypress="if(event.keyCode=='13') alert(1);" tabindex="0" />用jquery的话,完整代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="jquery.js"></script><script>$(function() { $("img").click(function() { alert(1); }).keypress(function(e) { //其他按键自己把keyCode加上就行 if(e.keyCode==13) $(this).trigger('click'); });});</script></head><body><img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" tabindex="0" /><a href="javascript:alert(2);">click me</a><input type="button" value="点我" onclick="alert(3);"></body></html>
      

  9.   

    jayinIT  没看懂你在干嘛  LZ要的好像不是这样的吧!
      

  10.   


    补充说明:还有一种就是在<img>外面套一个<a>标签,设置属性href="/xxx.aspx?canshu="+你的参数,然后到一个新的页面xxx.aspx去处理,然后返回操作结果。,这个就是得新建一个专门的处理页面。个人觉得onclick=document.getElementById("Button").click();最简单,只要设置个隐藏按钮就行了。
      

  11.   

    前台调用后台的方法,不就是AJAX吗