gpt4 book ai didi

javascript - ASP.NET - 使用 Javascript 在 LinkBut​​ton 上编辑 CommandName

转载 作者:行者123 更新时间:2023-11-30 23:43:28 24 4
gpt4 key购买 nike

我的中继器中有一系列用于切换页面的链接按钮

<asp:Repeater ID="rptPageLinks" runat="server"><ItemTemplate>
<asp:LinkButton ID="lnkNewPage" runat="server" Text='<%# Eval("Page") %>'
OnCommand="SomeEventHandler" CommandArgument='<%# Eval("Page") %>' CommandName="Redirect"
OnClientClick="return confirm('Do you want to save your chanes before you navigate to a new page?');" />
</ItemTemplate></asp:Repeater>

我想要做的是将 OnClientClick 的结果传递到 EventHandler 中,理想情况下通过更改 CommandName (即,如果他们在确认上单击"is",则将 CommandName 更改为“SaveAndRedirect”,如果他们单击“不”,它保留为“重定向”)。

有人可以帮忙吗?如果可以的话谢谢。

最佳答案

不幸的是,你所要求的那样是不可能的。 OnCommand 是 ASP 控件的 ASP.Net 服务器端属性。在客户端上渲染后,您只能使用客户端 html。

但是,解决方案是将确认对话框的值保存到命令事件的隐藏字段中,然后在命令中读取该值。为此,我建议如下:

<script type="text/javascript">
function confirmSave() {
document.getElementById('confirmChoice').value=confirm("Do you want to save your changes...");
}
</script>
<input type='hidden' id='confirmChoice' runat="server" />

然后,在命令事件调用的代码后面的页面中,您可以访问设置到隐藏字段中的值。

关于javascript - ASP.NET - 使用 Javascript 在 LinkBut​​ton 上编辑 CommandName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3871371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com