asp.net按钮使用javascript返回函数
我有一个 asp:button 控件,并在 .aspx 文件中使用“CommandName”和“CommandArgument”参数。 CommandName 通过 <%# Eval("Name") %> 找到,但 CommandArgument 必须通过 JavaScript 函数找到。但是,我不太确定如何内联执行此操作。该函数返回一个数字(整数),该数字将用作 CommandArgument 的值。可以这样做吗? 感谢
编辑添加代码 我添加了一个示例代码(无法访问 atm 的真实代码)。然而,基本上,CommandArgument 应该是函数CalculateLength() 返回的值。
function CalculateLength(a,b) {
return a*b;
}
<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName=<%# Eval("Name") %> CommandArgument= ??? //Should be result of CalculateLength(a,b).
I have an asp:button control and am using the "CommandName" and "CommandArgument" parameters in the .aspx file. The CommandName is found with <%# Eval("Name") %>, but the CommandArgument has to be found via a javascript function. However, I'm not quite sure how to do this inline. The function returns a number (integer), which is to be used as the value of the CommandArgument. Is it possible to do this?
Thanks
EDITED TO ADD CODE
I've added an example code (don't have access to the real code atm). However, basically, the CommandArgument should be the value returned by the function CalculateLength().
function CalculateLength(a,b) {
return a*b;
}
<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName=<%# Eval("Name") %> CommandArgument= ??? //Should be result of CalculateLength(a,b).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你将如何让 javascript 工作,因为 aspx 代码正在服务器端运行并为你的按钮构建输出。当 javascript 运行时,页面代码已经构建完毕,按钮的 html 和附加的 javascript 也已经构建完成。
无论如何,是否有计算服务器端的函数,然后执行以下操作:
您不需要只使用绑定到的数据,您可以调用任何服务器端函数。
编辑:尝试将存储数量的标签切换到文本框并将其设置为只读,这样使用时就不会弄乱它。单击按钮后,您应该能够找到文本框控件并读出发布的值。
I am not sure how you are going to get the javascript to work because the aspx code is running server side and building the output for your button. By the time the javascript runs the page code has already been built and the button's html and attached javascript as well.
Is there anyway to calculate the function server side and then just do:
You don't need to just use the data your binding to, you can call any server side function.
Edit: Try switching your label that stores the quantity to a textbox and making it read only so uses will not mess with it. After the button is clicked, you should be able to find the textbox control and read out the posted value.