取消点击事件ASP.Net [英] Canceling click events ASP.Net

查看:116
本文介绍了取消点击事件ASP.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计我有一个小问题,我希望得到一些帮助。

基本上我有一个带有几个复选框的网格,当用户检查这些框时我称之为自定义事件处理程序执行得很好,问题是用户检查复选框但关闭页面(在这种情况下关闭按钮)。



如何取消复选框事件和跳转到关闭按钮的点击事件?



先谢谢你们。



Hey guys I have a small issue which I was hoping for some help with.
Basically I have a grid with a few checkboxes, when the user checks these boxes I call a custom event handler which executes just fine, the problem is when the user checks the checkbox but then closes the page (close button in this case).

How do I cancel the checkbox events and jump to the click event of the close button?

Thanks in advance guys.

<ItemTemplate>	
      <asp:CheckBox id="chkPermission" runat="server" OnCheckedChanged="CheckPermissions" />
                                                </ItemTemplate>







Protected Sub CheckPermissions(ByVal sender As Object, ByVal e As EventArgs)
Logic here..............
End Sub





问题是我不希望每次都有复选框导致回复,因为可能有一百个复选框网格。如果用户单击关闭按钮,如何取消对CheckPermissions的调用?或者可以这样做吗?



The problem is that I don't want the checkbox to cause a post back everytime as there could be a hundred checkboxes in the grid. How do I cancel the call to the CheckPermissions if the user clicks the close button?? Or can it be done??

推荐答案

简单。从复选框中删除OnCheckChanged = ...。只是不要处理这个事件,它也不会被接通。



听起来,你提到的百复选框,你真的不喜欢选中复选框时需要执行CheckPermissions,而是在用户提交表单时开始检查它们。
Simple. Remove the "OnCheckChanged=..." from the Checkbox. Just don't handle the event and it won't get wired up.

It sounds as though, with the "hundred" checkboxes you mentioned, that you really don't need to execute CheckPermissions when a checkbox is checked, but rather start checking them when a user submits the form.


嘿谢谢你的帮助,但我找到了一个更好的解决方案适合页面编码的方式。如果我按照上面的建议进行结构,这将是一个相当大的变化。



所以在Page_Load中我添加了这段代码...



所以我只是检查关闭按钮是否导致回发,如果是这样,我重定向到另一个页面,从而阻止其他事件被触发,而不是最干净的代码,但作为我说它解决了这个问题。



Hey thanks for all your help but I found a solution to this that better suits the way the page is coded. It would have been a pretty big change to the structure if I went with the suggestions above.

So in the Page_Load I added this piece of code...

So im just checking if the close button caused the postback, if so I redirect to a different page thus preventing the other events from firing, not the cleanest of code but as I say it solves this paticular problem.

If Page.IsPostback Then

  Dim control As Control = Nothing
                Dim sControlName = Page.Request.Params.Get("__EVENTTARGET")

                If (Not IsNothing(sControlName) And sControlName <> String.Empty) Then
                    control = Page.FindControl(sControlName)
                Else
                    For Each ctrl As String In Page.Request.Form
                        Dim myControl As Control = Page.FindControl(ctrl)
                        If (TypeOf myControl Is System.Web.UI.WebControls.Button) Then
                            If (myControl.ID = "cmdClose") Then
                                Response.Redirect("~\Welcome.aspx")
                            End If
                            control = myControl
                            Exit For
                        End If
                    Next

                End If
End If





再次感谢



Thanks Again


这篇关于取消点击事件ASP.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆