Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将onclick事件添加到在C#代码隐藏中创建的div中?_Javascript_C#_.net_Master Pages - Fatal编程技术网

Javascript 如何将onclick事件添加到在C#代码隐藏中创建的div中?

Javascript 如何将onclick事件添加到在C#代码隐藏中创建的div中?,javascript,c#,.net,master-pages,Javascript,C#,.net,Master Pages,在这里,我在循环中创建了一个div(该div由数据库中的标签/数据填充): 下面是我试图调用的函数: protected void divClick(object sender, EventArgs e) { Response.Redirect("CreateMeeting.aspx"); } 该函数从未被调用,且div不可单击 此外,我还需要获取div和div中其他元素的id。代码中的方法调用是实现这一点的最佳方法吗?我可以为您提供一般示例,因为您没有

在这里,我在循环中创建了一个div(该div由数据库中的标签/数据填充):

下面是我试图调用的函数:

    protected void divClick(object sender, EventArgs e)
    {
        Response.Redirect("CreateMeeting.aspx");
    }
该函数从未被调用,且div不可单击


此外,我还需要获取div和div中其他元素的id。代码中的方法调用是实现这一点的最佳方法吗?

我可以为您提供一般示例,因为您没有询问任何特定的问题,但可以这样说:

_myButton.Attributes.Add("onclick", "return confirm_delete();");

javascript:
function confirm_delete()
{
  if (confirm("Are you sure you want to delete the custom search by pressing button on div?")==true)
    return true;
  else
    return false;
}
div.Attributes.Add("onclick", DoSomething);
基本语法如下所示:

_myButton.Attributes.Add("onclick", "return confirm_delete();");

javascript:
function confirm_delete()
{
  if (confirm("Are you sure you want to delete the custom search by pressing button on div?")==true)
    return true;
  else
    return false;
}
div.Attributes.Add("onclick", DoSomething);
还有一个例子:

Button divButton = new Button();
divButton.Attributes["style"] = "display:none;";
divButton.ID = "divBtn_" + id;
divButton.Text = id;
divButton.Click += divButton_Click;
Add(“onclick”,“return divclick();”


函数divclick()
{
var button=document.getElementById('divBtn_');
按钮。单击();
返回false;
}
我希望这足以让你理解如何在你的div上附加click事件