简体   繁体   English

有没有办法在JavaScript中设置asp.net按钮的CommandArgument?

[英]Is there a way to set a asp.net button's CommandArgument in javascript?

I have a GridView that lists a bunch of items and one of the columns has a link that displays a modal (AjaxToolkit ModalPopupExtender). 我有一个列出一堆项目的GridView,其中一个列有一个显示模态的链接(AjaxToolkit ModalPopupExtender)。 Let's call that link "Show". 我们称之为“显示”链接。 In that modal, I have a asp:button for saving the data entered in that modal. 在那个模态中,我有一个asp:按钮,用于保存在该模态中输入的数据。 Let's call that button "Save" 我们称之为“保存”按钮

So when the user clicks on a "Show" link in a certain row, I'd like write some javascript that sets something in the "Save" button, so that in my code-behind, I can handle "Save".Command and use the CommandEventArgs parameter to get the value. 因此,当用户点击某一行中的“显示”链接时,我想写一些在“保存”按钮中设置内容的javascript,这样在我的代码隐藏中,我可以处理“保存”。命令和使用CommandEventArgs参数获取值。

Is this possible, or do I just need to use a hidden input tag and set its value? 这是可能的,还是我只需要使用隐藏的输入标记并设置其值?

Not a direct answer to your question, but another possible way of solving the problem: 不是您问题的直接答案,而是另一种解决问题的可能方法:

Place a HiddenField control on the page. 在页面上放置一个HiddenField控件。 In your code-behind, before displaying the modal popup, set the value of that control to the ID of the row that was clicked (or the row number, or some identifying value). 在代码隐藏中,在显示模式弹出窗口之前,将该控件的值设置为单击的行的ID(或行号或某个标识值)。 Then in the code-behind of your Save button, you can just read the value of the HiddenField . 然后在Save按钮的代码隐藏中,您只需读取HiddenField的值即可。

Well, after continuing the research, it looks like it cannot be done. 好吧,继续研究后,看起来似乎无法完成。 The CommandArgument property might reside in the ViewState, but for this case, it is completely server side and cannot be changed using javascript. CommandArgument属性可能驻留在ViewState中,但对于这种情况,它完全是服务器端,无法使用javascript进行更改。

If you are using Updatepanel, you need to place the Hiddenfield inside the Updatepanel . 如果您使用的是Updatepanel,则需要将Hiddenfield放在Updatepanel中 Otherwise you will not be able to get/set the value stored in hiddenfield. 否则,您将无法获取/设置存储在hiddenfield中的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM