如何检测控件在ASP中单击OnClientClick.净c#

How to detected Control is clicked OnClientClick in ASP.NET C#?

本文关键字:ASP 单击 OnClientClick 控件 何检测 检测      更新时间:2023-09-26

我有一个图像按钮与OnClientClick事件加载Ajax。

我想检测我的图像按钮被点击。我很努力,但运气不好。

这是我的代码:

ImageButton imgbtn = new ImageButton();   
imgbtn.Height = 25;
imgbtn.CssClass = "light";
imgbtn.ID = "led" + i;
imgbtn.OnClientClick = "Turnon('" + table.Rows[i]["Url"].ToString() + "');";
//If i can detected that my imgbtn is clicked
//I will do something
如果我的问题不清楚,我很抱歉,但我会尽力向你展示我的想法。谢谢!

解决方案

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
        function Turnon(url)
        {
            alert(url);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

您需要对formaspx page上的任何place holder添加控制。
代码:

ImageButton imgbtn = new ImageButton();
imgbtn.Height = 25;
imgbtn.CssClass = "light";
imgbtn.ID = "led";
imgbtn.OnClientClick = "Turnon('" + "www.google.com" + "');";
form1.Controls.Add(imgbtn); //