visual-studio 我怎样才能得到按钮的命令参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1567949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:05:35  来源:igfitidea点击:

how can i get the button's command argument?

c#.netasp.netjavascriptvisual-studio

提问by Eric

Is it possible to get a button's command argument in javascript. I don't want to manipulate it, i just want to read it.

是否可以在 javascript 中获取按钮的命令参数。我不想操纵它,我只想阅读它。

If possible - how?

如果可能 - 如何?

回答by rick schott

Make your own attribute and get it with standard JavaScript:

创建您自己的属性并使用标准 JavaScript 获取它:

Markup:

标记:

<asp:LinkButton ID="LinkButton1" cmdname="test" CommandName="test" CommandArgument="1" 
    runat="server" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>

Script:

脚本:

//however you choose to get the element, jQuery...etc
document.getElementById('<%=LinkButton1.ClientID %>').cmdname

回答by J.W.

You can put command argument into some hidden field, then retrieve the value of the hidden field in javascript after page loads such as $(document).ready() in JQuery.

您可以将命令参数放入某个隐藏字段中,然后在页面加载后在 javascript 中检索隐藏字段的值,例如 JQuery 中的 $(document).ready() 。

回答by Raúl Roa

The short answer is NO if you are ONLY using javascript. Butyou could retrieve it with an ajax call to the server or using a hidden field like J.W. suggested. This property is not even accessible from themes. For more info read the documentation in msdn

如果您只使用 javascript,简短的回答是否定的。但是您可以通过对服务器的 ajax 调用或使用 JW 建议的隐藏字段来检索它。甚至无法从主题访问此属性。有关更多信息,请阅读msdn 中的文档