Javascript onclick事件不工作c# asp.net 4.0

本文关键字:asp net 工作 onclick 事件 Javascript | 更新日期: 2023-09-27 17:49:21

动态超链接点击事件在c# asp.net中不工作。有谁能帮我这个忙吗?

                HyperLink h1 = new HyperLink();
                h1.NavigateUrl = "javascript:void(0)";
                h1.Attributes.Add("onclick", "edit(" + rd[0].ToString() + "," +                    rd["column1"].ToString() + "," + rd["column2"].ToString() + "," + Convert.ToString(rd["existance"]) + "," + rd[4].ToString() + "," + Convert.ToString(deldate) + "," + rd["modifier"].ToString() + ")");
                h1.Text = "Edit";
                Table1.Rows[rw].Cells[7].Controls.Add(h1);
                h1 = new HyperLink();
                h1.NavigateUrl = "rulesuploading.aspx?type=D&id=" + rd[0].ToString();
                h1.Text = " | Delete";
                Table1.Rows[rw].Cells[7].Controls.Add(h1);

//Javascript
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <script type="text/javascript">
        function edit(id, col1, col2, ex, ef, del, mod) {
            document.getElementById('id').value = id;
            document.getElementById('coltxt1').value = col1;
            document.getElementById('coltxt2').value = col2;
            document.getElementById('extxt').value = ex;
            document.getElementById('efftxt').value = eff;
            document.getElementById('deltxt').value = del;
            document.getElementById('modtxt').value = mod;
        }
</script>
</asp:Content>

Javascript onclick事件不工作c# asp.net 4.0

我建议你在网页上查看你的源代码,这样你就可以看到你的事件是否被很好地附加,如果你的调用"edit"与脚本标签中的编辑功能具有相同的签名。

我猜最后少了一个分号。

 h1.Attributes.Add("onclick", "edit(" + rd[0].ToString() + "," +                      rd["column1"].ToString() + "," + rd["column2"].ToString() + "," +  Convert.ToString(rd["existance"]) + "," + rd[4].ToString() + "," + Convert.ToString(deldate) +  "," + rd["modifier"].ToString() + ");");