onClientClick for asp:element within a listview
onClientClick for asp:element within a listview
我有这些asp:ImageButton
:这是在一个列表视图
<asp:ImageButton ID="profile" runat="server" Width="60px" Height="60px" ImageUrl='<%# Eval("photo") %>' OnClientClick="photoFrame()" CssClass="Frame" />
<asp:ImageButton ID="basic" runat="server" Width="60px" Height="60px" ImageUrl='<%# Eval("photo") %>' OnClientClick="photoFrame()"/>
现在,当我点击它,我想改变它的边框和其他的asp:ImageButtons
的边框。
这里是photoFrame()
:
<script type="text/javascript">
function photoFrame() {
document.getElementById("basic").setAttribute("CssClass", "Frame");
document.getElementById("profile").removeAttribute("CssClass");
}
</script>
,但却报错:
无效的回发或回调参数。事件验证在配置中启用或在页面中使用<%@ Page EnableEventValidation="true" %>。出于安全目的,此功能验证回发或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据是有效且预期的,则使用ClientScriptManager。RegisterForEventValidation方法,以便注册回发或回调数据进行验证。
我已经环顾四周寻找解决方案,我出来了添加enableEventValidation="false"
到页面的<% %>
,但不是做错误,它只是做回发,那就是它。
我该如何修复它?谢谢你的帮助
*我需要List的ItemDataBound函数的asp控件
所以我可以这样写:
var profile = e.Item.FindControl("profile") as ImageButton;
var basic = e.Item.FindControl("basic") as ImageButton;
编辑:这个问题解决了,我所做的就是将其改为asp:image并添加返回false;.
<asp:Image ID="profile" runat="server" Width="60px" Height="60px" ImageUrl='<%# Eval("photo") %>' OnClick="photoFrame();return false" CssClass="Frame"/>
<asp:Image ID="basic" runat="server" Width="60px" Height="60px" OnClick="photoFrame();return false"/>
,但现在我猜,命令在功能photoFrame()
不工作,因为它不做任何事情,但当我把它改为警报(某些东西),例如,它确实工作。
你知道在javascript中改变asp:元素属性的其他方法吗?
我试着
document.getElementById('basic').className='Frame';
document.getElementById('profile').className='';
它也没有做任何事情。
也许我不能getElementById一个元素,是在一个列表视图?
将return false
添加到您的on OnClientClick
声明中:
OnClientClick="photoFrame();return false"
将取消回发,但仍然执行客户端函数。
但在现实中,因为你真的不需要一个实际的按钮,你可以用asp:Image
代替asp:ImageButton
,只使用onclick
属性。
也-因为你的JS函数是处理客户端元素的属性,你要设置或删除的是"类",而不是"CssClass"(这是由服务器端控件使用)
您需要在您的ImageButton
asp控件上使用ClientIDMode="Static"
。
这将使控件的ID
s保持静态,以便您的函数能够针对预期的元素,否则.net
将根据您的标记结构更改ID
s,并且您的脚本将无法针对元素。
您似乎不希望imagebuttons触发服务器请求,而只希望调用photoFrame函数。将imagebutton替换为img标签,并为它们提供onclick事件处理程序。
无论你选择哪种解决方案,我认为你需要改变你的javascript函数为:
document.getElementById('basic').className='Frame';
document.getElementById('profile').className='';
添加:
<asp:Literal id="basic" text="<img src='"photo'" width='"60'" height='"60'" onclick='"photoFrame();'"/>" runat="server"/>
- 使用Jquery选择或取消选择ListView中的所有复选框
- React Native Listview留有余地
- 在ListView中添加JSON数组中存储的图像-ReactNative
- 如何在ListView项模板中获取按钮来执行不同的操作
- ListView没有'当基础对象更改时不会更新
- ListView的ItemTemplate内的自定义HtmlControl的数据绑定失败
- 如何将WinJS ListView绑定到web服务
- 什么'是删除WinJS ListView中所有项目的最快方法
- JSON & Dynamic jQuery Mobile Listview
- Ui-view within ui-view
- Fancybox within Jquery Cycle Slide
- jQuery Mobile Listview,里面有文本视图
- JQuery, Java Servlet Examplet within Eclipse WTP
- 在ListView中显示包含3列的标题
- 如何使用javascript将asp.net中的listview中的数据导出为pdf
- ASP.NET ListView选项卡事件触发验证按钮
- 在windows8中,将“从文件选择器中拾取的文件”定义为Listview数据源
- 如何在React Native中为ListView中的每个元素绑定函数
- 可以检查Listview(jQuery Mobile)是否包含Collapsible
- onClientClick for asp:element within a listview