为什幺服务器端button的客户端onclick事件不能直接在html代码中加
如
<asp:Button id=”Button1” Text=”Button” runat=”server”></asp:Button>
将改为
<asp:Button id=”Button1” onclick=”alert(‘ok’)” Text=”Button” runat=”server”></asp:Button>运行时就出错﹐我想请问为什幺?
谢绝告诉我 在c#代码里加 Button1.Attributes.Add("onlick","<script>alert('ok')</script>")可以达到效果﹐我只想知道为什幺服务器端button的客户端onclick事件不能直接加
如
<asp:Button id=”Button1” Text=”Button” runat=”server”></asp:Button>
将改为
<asp:Button id=”Button1” onclick=”alert(‘ok’)” Text=”Button” runat=”server”></asp:Button>运行时就出错﹐我想请问为什幺?
谢绝告诉我 在c#代码里加 Button1.Attributes.Add("onlick","<script>alert('ok')</script>")可以达到效果﹐我只想知道为什幺服务器端button的客户端onclick事件不能直接加
他的OnClick 是对应服务端的onclick,回到*.cs里寻找这个事件
1 onClick事件是可以放在服务器控件上的,不过那是在前台编码的情况下,
由于后台编码提供了很好的代码分离,所以事件放在.cs里更合情合理。
2 onclick=”alert(‘ok’)”,这个还是asp的习惯吧?
他会自动找服务器上的
解决方法,换成html button 加上 runat="server"
就ok了
如﹕服务器端TextBox也沒有onmouseover這個客戶事件﹐但是可以<asp:TextBox id="TextBox1" onmouseover="over()" runat="server"></asp:TextBox>
“over()”是自已寫 的javascript 函數,卻沒有問題
請思歸再看一下
http://community.csdn.net/Expert/topic/3382/3382132.xml?temp=.9286157