【问题标题】:How can I get the ID of ImageButton for javascript, if the ImageButton was created in code behind?如果 ImageButton 是在后面的代码中创建的,如何获取 javascript 的 ImageButton 的 ID?
【发布时间】:2014-05-10 15:55:33
【问题描述】:

我在代码 buhind 中创建了一个 ImageButton-

var img = new ImageButton();
img.ID = "Del" + i.ToString();
img.ImageUrl = "images/1395958363_meanicons_57.png";
img.Width = 48;
img.Height = 38;
img.OnClientClick = "javascript:void(DeleteBook())";

Label1.Controls.Add(img);

现在我需要获取 ImageButton 的 ID。谁能帮我解决这个问题?

P.S ImageButton 是在“for”中创建的,所以我不知道我的 ImageButton 有多少以及它们的 ID 是什么

【问题讨论】:

  • 请更正标题中的拼写法

标签: c# javascript visual-studio-2010 code-behind imagebutton


【解决方案1】:
【解决方案2】:

您可以将 img.ID 直接传递给 javascript DeleteBook() 函数。

或者更好的是,您可以直接传递它,例如:OnClientClick ="DeleteBook(this)"

【讨论】:

    猜你喜欢
    • 2014-05-09
    • 1970-01-01
    • 2013-10-06
    • 2017-05-18
    • 2019-02-13
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多