[英]Getting the value from asp:LinkButton's CommandArgument attribute using jquery/javascript
I need to get the value of the CommandArgument
attribute of a LinkButton, in an asp:Repeater. 我需要在asp:Repeater中获取LinkButton的CommandArgument
属性的值。
I have an asp:Repeater with 2 LinkButtons whose CommandArgument I set to a value: 我有一个带有2个LinkButton的asp:Repeater,其CommandArgument设置为一个值:
<ItemTemplate>
<tr class="odd">
<td><%#DataBinder.Eval(Container.DataItem, "batch_id")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "productId")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "serial_number")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "activation_card_number")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "transaction_amount","{0:C}")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "response_dt", "{0:M/d/yyyy HH:mm:ss}")%></td>
<td style="text-align:center;"><%#DataBinder.Eval(Container.DataItem, "resp_process_msg")%></td>
<td style="text-align:center;"><%#DataBinder.Eval(Container.DataItem, "resp_response_code")%></td>
<td style="text-align:center;"><asp:LinkButton ID="lnkBtnRestageAdd" CommandName="Add" CommandArgument='<%#Eval("activation_card_number")%>' runat="server" Text="stage" class="add" OnClientClick="return false;" /></td>
<td style="text-align:center;"><asp:LinkButton ID="lnkBtnRestageMinus" CommandName="Subtract" CommandArgument='<%#Eval("activation_card_number")%>' runat="server" Text="stage" class="minus" OnClientClick="return false;" /></td>
</tr>
</ItemTemplate>
I have suppressed the PostBack with OnClientClick="return false;" 我用OnClientClick =“ return false;”取消了PostBack。 so that I can pop a jQuery dialog modal when the link buttons get clicked: 这样,当单击链接按钮时,我可以弹出一个jQuery对话框模式:
if (btnAdd != null) {
$(".add").click(function() {
$("#<%=divDialogAdd.ClientID %>").removeAttr("style");
$("#<%=divDialogAdd.ClientID %>").dialog("open");
});
}
In the modal I have 2 other asp:LinkButtons, and when the 'Yes' button is clicked I do the postback like so: 在模式中,我还有另外两个asp:LinkButtons,当单击“是”按钮时,我像这样进行回发:
yesBtn.click(function() {
setTimeout('__doPostBack(\'btnAdd\',\'\')', 0); //need to add a param
});
What I need to do, is somehow grab the CommandArgument value from the LinkButton in the Repeater, so that I can pass that as a parametere or assign it to a hidden field. 我需要做的是,从中继器的LinkButton中以某种方式获取CommandArgument值,以便我可以将其作为参数传递或将其分配给隐藏字段。 I have tried jQuery's attr()
, but that only works when the attribute was set using that function as well. 我已经尝试过jQuery的attr()
,但这仅在使用该函数设置属性时才起作用。 How can I get this value, or what other way can I go about this? 我如何获得该价值,或者我可以通过其他什么方式实现这一价值?
I don't think you can get that property in javascript. 我认为您无法在javascript中获得该属性。 Because the command argument is passed as the the argument in the doPostBack function. 因为命令参数作为doPostBack函数中的参数传递。 But i think you can change your code like this to decrease the complexity. 但是我认为您可以像这样更改代码以降低复杂性。
<asp:LinkButton ID="lnkBtnRestageAdd"
CommandName="Add"
CommandArgument='<%#Eval("activation_card_number")%>'
runat="server"
Text="stage"
class="add"
OnClientClick='<%#Eval("activation_card_number","javascript:return YourFunction({0});")%>' />
do the stuff that you want to do in the function YourFunction
return true
if Yes is pressed and return false
做到这一点要在功能做的东西YourFunction
返回true
如果按YES,并返回false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.