我正在使用 ASP 中继器。在 和 中,除了其他标签等之外,还有 3 个 HTML 按钮 (),单击时进行不同的 javascript/jquery 调用。这工作正常。
现在,我想根据绑定到中继器的布尔值动态显示/隐藏这些按钮。我知道如果我使用的是 ASP 按钮,我可以简单地使用如下内容:
Visible='<%# Eval(bMyBoolean) %>'
我尝试将 HTML 按钮切换为 ASP 按钮,但随后我无法让 javascript 调用正常工作。我知道您可以在每个按钮的后面代码中连接 Javascript 调用(在 Repeater.ItemDataBound 事件中),但我不确定如何在我的场景的后面代码中执行此操作。下面是我的一个 HTML 按钮的示例:
I'm using an ASP Repeater. In the <ItemTemplate> and the <AlternatingItemTemplate> there are, among other labels, etc, 3 HTML buttons (<input type="button"...) that make different javascript/jquery calls when clicked. This is working fine.
Now, I want to dynamically show/hide these buttons based on a boolean that is bound to my Repeater. I know if I were using an ASP Button, that I could simply use something like:
Visible='<%# Eval(bMyBoolean) %>'
I tried switching my HTML buttons to ASP Buttons but then I couldn't get the javascript calls to work correctly. I know you can wire up the Javascript calls in the code behind for each button (in the Repeater.ItemDataBound event), but I'm not sure how to do that in the code behind with my scenario. Here is an example of one of my HTML buttons:
In the above example, I'm passing the FirstName value (which is a property of the class object I'm binding to the repeater) to my Javascript function.
To me, it seems like if I'm using an ASP Repeater, then it would make sense to use ASP Buttons, but I don't know if it really makes a difference?
So, my question is: How can I either dynamically show/hide an HTML Button inside an ASP Repeater based on a boolean value that is bound to the repeater? Or, if that is a bad practice, how can I make a javascript call with an ASP Button, like the call above (referencing a value from the Repeater)?
protected function getVisibility(isVisible as boolean) as string
if isVisible then
return "display:inline; "
else
return "display:none;"
end if
end function
现在,如果您想从 asp.net 控件执行 JavaScript 调用,您也可以选择:
最简单但绝不是最好的选择是内联 JS:
<itemTemplate>
<asp:button runat="server" onclientClick="return confirm('click to submit');"
text="Click!" />
</itemTemplate>
protected function getVisibility(isVisible as boolean) as string
if isVisible then
return "display:inline; "
else
return "display:none;"
end if
end function
Now, if you wanted to perform a JavaScript call from the asp.net control, you have options as well:
The simplest -- but by no means best option, is to do inline JS:
<itemTemplate>
<asp:button runat="server" onclientClick="return confirm('click to submit');"
text="Click!" />
</itemTemplate>
there are more complex options with the use of JQuery that would allow you to dynamically capture a click event, and determine the exact row of the repeater that you're selecting for. One example of this is:
发布评论
评论(1)
您可以根据布尔值动态输出样式信息。考虑一下:
然后在您的代码中,您将拥有:
现在,如果您想从 asp.net 控件执行 JavaScript 调用,您也可以选择:
最简单但绝不是最好的选择是内联 JS:
使用 JQuery 可以提供更复杂的选项,允许您动态捕获单击事件,并确定您要选择的转发器的确切行。一个例子是:
然后 jquery 代码:
you can dynamically output style information based on your boolean. Consider this:
Then in your code, you'd have:
Now, if you wanted to perform a JavaScript call from the asp.net control, you have options as well:
The simplest -- but by no means best option, is to do inline JS:
there are more complex options with the use of JQuery that would allow you to dynamically capture a click event, and determine the exact row of the repeater that you're selecting for. One example of this is:
Then the jquery code: