日期:2014-05-18  浏览次数:20734 次

大家看看,没有什么办法可以在label 或者literal 控件上使用clieck 事情,或者有没有其他的解决方案,在线等,马上结贴,给分
老板叫我用label   或者literal   控件,可是这些控件没有click   事情,那要怎么办阿

------解决方案--------------------
晕倒,你不把你的具体需求说出来大家怎么帮你想解决方案啊!
为什么Label还要click事件?用imagebutton不行吗?
------解决方案--------------------
可以加上客户端事件
lable.Attributes.Add( "onclick ", "Javascript:Func() ");

------解决方案--------------------
楼上的应该可行,附加属性
------解决方案--------------------
JustLovePro(嘉鑫) ( ) 信誉:100 2007-09-04 08:56:05 得分: 0


可以加上客户端事件
lable.Attributes.Add( "onclick ", "Javascript:Func() ");



-----------------------------
正解,为其控件添加客户端事件
------解决方案--------------------
aspx:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeBehind= "WebForm1.aspx.cs " Inherits= "WebDemo.WebForm1 " %>

<!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 runat= "server ">
<title> 无标题页 </title>
<script type= "text/javascript ">
function myClick()
{
__doPostBack( "LinkButton1 ", " ");
}

</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<asp:Label ID= "Label1 " runat= "server " Text= "Label "> </asp:Label>
<asp:LinkButton ID= "LinkButton1 " runat= "server " OnClick= "LinkButton1_Click " style= "display:none "> LinkButton </asp:LinkButton>
</form>
</body>
</html>

//aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Label1.Attributes.Add( "onclick ", "javascript:myClick(); ");
}

protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Write( "Hello ");
}
------解决方案--------------------
用Label的click事件,听起来就不对劲,难道要点击个字就引发postback?
------解决方案--------------------
哈,这个想法没什么创意,不要也罢

BOSS 有叫让点一个字符就触发一个事件迈?
------解决方案--------------------
在pageload中加入
lable.Attributes.Add( "onclick ", "调用的js ");
------解决方案--------------------
没用过,学习了。。。
------解决方案--------------------
鼠标事件
------解决方案--------------------
标签能添加这个事件吗?
------解决方案--------------------
通过GetPostBackEventReference模拟PostBack:
.aspx:
<div id=dv runat=server />

.cs:
protected void Page_Load(object sender, EventArgs e)
{
dv.Attributes.Add( "onclick ", ClientScript.GetPostBackEventReference(dv, " "));