点击事件上的div asp.net [英] Click event on div in asp.net

查看:127
本文介绍了点击事件上的div asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Default.aspx的DIV与IMG内部如下

I have a div in default.aspx with img inside as follow

 <div id="sTab" class="tabs firsttab" runat="server">
     <asp:Image ID="sTabImg"  src="images/home.png" runat="server" />
 Activities
</div>

我想在ASP.NET对点击的div执行一些动作(在JavaScript)。

I want to perform some action on click of the div in ASP.NET (not in javascript).

我尝试了以下

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
    }

    sTabImg.Attributes["onclick"] = ClientScript.GetPostBackEventReference(this, "ClickDiv");
}

protected void ClickDiv()
{
    Label2.Text = "helo got it";
}

页面越来越刷新,当我调试的问题,它不是进入ClickDiv function..What错在这里。

The page is getting refreshed and when i debugged the issue, its not entering the ClickDiv function..What wrong here..

推荐答案

为什么不使用的的ImageButton

<%@ Page Language="C#" AutoEventWireup="True" %>
<!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>
    <title>ImageButton Sample</title>
<script language="C#" runat="server">

      void ImageButton_Click(object sender, ImageClickEventArgs e) 
      {
         Label1.Text = "You clicked the ImageButton control at the coordinates: (" + 
                       e.X.ToString() + ", " + e.Y.ToString() + ")";
      }

</script>

</head>
<body>
<form id="form1" runat="server">

  <h3>ImageButton Sample</h3>

  Click anywhere on the image.<br /><br />

  <asp:ImageButton id="imagebutton1" runat="server"
       AlternateText="ImageButton 1"
       ImageAlign="left"
       ImageUrl="images/pict.jpg"
       OnClick="ImageButton_Click"/>

      <br /><br />

      <asp:label id="Label1" runat="server"/>

   </form>

</body>
</html>

你可以看到一些例子这里

这篇关于点击事件上的div asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆