获取http模块中gridview中图片按钮点击事件的引用
我们如何将GridView
内的ImageButton
的Click
事件传递给httpmodule 对于链接按钮,我这样做:
if (request.Form.GetValues("__EVENTTARGET") != null)
{
//If it's a link button execute we can directley check for the params
if (request.Params.Get("__EVENTTARGET").Contains("xyz"))
{
//some Code
}
这不适用于ImageButton
。
How do we pass the Click
event of ImageButton
inside a GridView
to httpmodule
for linkbutton's i am doing this way:
if (request.Form.GetValues("__EVENTTARGET") != null)
{
//If it's a link button execute we can directley check for the params
if (request.Params.Get("__EVENTTARGET").Contains("xyz"))
{
//some Code
}
This is not working for ImageButton
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试将事件附加到 gridview 中的按钮,我可能会建议您在预渲染事件的基页中解析页面上的所有 gridview(使用递归 findcontrol 算法)并查找任何图像按钮(如果找到)然后您应该能够向其附加一个事件。
编辑:
我在下面使用类似的东西:
编辑: .All() 是一个定义如下的扩展方法(从 此处)
If you're trying to attach an event to a button within a gridview might I suggest in your base page on the prerender event parse through all gridviews on the page (use a recursive findcontrol algorithm) and look for any imagebuttons, if you find one you should then be able to attach an event to it.
EDIT:
I use something similar in the following:
EDIT: The .All() is an extension method defined as follows (stolen from here)
ImageButtons 的名称中有一个附加的准属性,用于标识鼠标坐标(X 和 Y)。
因此,要查找 ImageButton 的名称,您应该迭代发布的参数并找到以
.x
或.y
结尾的参数:您还可以查找 这个答案很有用。它包含一个更通用的方法来确定哪个控件导致了回发。
ImageButtons have an additional quasi-property in their names which identifies the mouse-coordinates (X and Y).
So to find the ImageButton's name your should iterate through posted parameters and found those which end with
.x
or.y
:You could also cound this answer useful. It contains a more generic method to determine which control caused a postback.