我repeater控件里面嵌套的ImageButton控件(控件名称是imgReply)添加客户端事件,在浏览页面点击ImageButton控件,没有反应。
我在.aspx里面的javascrip函数如下:
<script type="text/javascript" language="javascript">    function show()
    {       
        eval(showReply).style.display="none";
    }
    </script>showReply是Repeater控件ItemTemplate里在面tr的名称,代码(截取主要部分代码)如:
   <tr id="showReply">
                                <td>
                                显示/不显示
                                </td>
                            </tr>
                        </table>我在.cs里面的代码如下:
 ImageButton imgReply = (ImageButton)item.FindControl("imgReply");
            imgReply.Attributes.Add("onclick", "show()");请高手帮我看一下,怎样才能使我这个客户端事件起作用,我需要实现的功能是:当用户点击imgReply控件时<tr id="showReply">所在的这一行内容就隐藏起来。

解决方案 »

  1.   

    你的这个tr在客户端的id肯定不能再是showReply了,看看html源代码就知道了
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <script type="text/javascript">
        function show(id)
        {       
            if(document.getElementById(id).style.display=="none")
                document.getElementById(id).style.display="block";
            else
                document.getElementById(id).style.display="none"
            return false;
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    <table>
                        <tr id="showReply" runat="server"><td>显示/不显示</td></tr>
                    </table>
                    <asp:ImageButton ID="ImageButton1" runat="server" OnClientClick='<%# "return show(\"" +  Container.FindControl("showReply").ClientID  + "\")" %>' />
                </ItemTemplate>
            </asp:Repeater>
            
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="select top 2 productid from products"></asp:SqlDataSource>
        </div>
        </form>
    </body>
    </html>