如何通过onclick事件发送值?

发布于 2024-07-13 05:19:54 字数 385 浏览 5 评论 0原文

我有以下按钮

   <asp:ImageButton ID="button1" runat="server" 
   ImageUrl="~/image.jpg"
   CommandName = "id"
   CommandArgument = "1"
   onclick="button1_Click"
   />

,并且在后面的代码中

protected void button1_Click(object sender, ImageClickEventArgs e)
{
    Response.Write(e.commandName);
}

不起作用!!,所以我的问题是如何从按钮控件获取值?

I have the following button

   <asp:ImageButton ID="button1" runat="server" 
   ImageUrl="~/image.jpg"
   CommandName = "id"
   CommandArgument = "1"
   onclick="button1_Click"
   />

and in code behind

protected void button1_Click(object sender, ImageClickEventArgs e)
{
    Response.Write(e.commandName);
}

this does not work!!, So my question is how to get value frombutton control?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如此安好 2024-07-20 05:19:54

为此,您需要订阅 命令事件而不是单击事件。 当遵循 ASP.NET 中的命令模式时使用此选项

For this to work you need to subscribe to the Command event instead of the Click event. This is used when following the command pattern in ASP.NET

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文