在 C# 中按“转义”键刷新页面/Web 部件

本文关键字:Web 部件 刷新 中按 转义 | 更新日期: 2023-09-27 18:32:38

我想在用户按下"Escape"键时触发刷新事件,或者希望在按下 Esc 键时触发图像单击事件实现这一目标的最佳方法是什么?谢谢

        $clone.click(function (e) { //action when magnified image is clicked on
        var $this = $(this)
        var imageinfo = $this.data('$relatedtarget').data('imgshell')
        jQuery.imageMagnify.refreshoffsets($(window), $this.data('$relatedtarget'), imageinfo) //refresh offset positions of original and warped images
        $this.stop().animate({ opacity: 0, left: imageinfo.attrs.x, top: imageinfo.attrs.y, width: imageinfo.attrs.w, height: imageinfo.attrs.h }, setting.duration,
        function () {
            $this.hide()
            $this.data('$relatedtarget').css({ opacity: 1 }) //reveal original image
        }) //end animate
    }) //end click

//This is what I put in, but I'd like it to not just refresh but actually perform the same         function as OnClick as above
$(document).keyup(function (e) { //action when magnified image is clicked on
 if (e.keyCode == 27) { //escape key 
     window.location.reload(); 
        }
}) //end click

 $clone.keyup(function (e) { //action when 'Esc' key is pressed after magnifying image 
        if (e.keyCode == 27) { //escape key 
        var $this = $(this)
        var imageinfo = $this.data('$relatedtarget').data('imgshell')
        jQuery.imageMagnify.refreshoffsets($(window), $this.data('$relatedtarget'), imageinfo) //refresh offset positions of original and warped images
        $this.stop().animate({ opacity: 0, left: imageinfo.attrs.x, top: imageinfo.attrs.y, width: imageinfo.attrs.w, height: imageinfo.attrs.h }, setting.duration,
        function () {
            $this.hide()
            $this.data('$relatedtarget').css({ opacity: 1 }) //reveal original image
        }) //end animate
                 }
    }) //end 

     }
    };

在 C# 中按“转义”键刷新页面/Web 部件

我会使用jQuery。实现非常简单:

$(document).keyup(function(e) {    
    if (e.keyCode == 27) { //escape key
        //trigger the image click logic
        $("img").trigger("click"); 
        //reload the page if you still need to
        window.location.reload();
    }
});

如果要触发回发,应该能够使用 __doPostBack 并重写代码隐藏中的 RaisePostBackEvent 方法:

$(document).keyup(function(e) {    
    if (e.keyCode == 27) { //escape key
        __doPostBack("<%= Page.ClientID %>", "argument");
    }
});    

在代码隐藏中:

protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)
{
    base.RaisePostBackEvent(source, eventArgument);
    if (source == Page)
    {
    }        
}