Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

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


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


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??
Posted
Updated 16-Jul-13 5:52am
v2
Comments
ZurdoDev 16-Jul-13 11:42am    
You would have to post your relevant code. Normally, to cancel the click event you just return false in the JavaScript onclick event. However, from what you have described it doesn't sound like that is your issue.

Please use the improve question link and post relevant code.
frostcox 16-Jul-13 12:50pm    
improved
ZurdoDev 16-Jul-13 12:57pm    
You still seem to be missing the relevant part. However, to prevent the postback return false in javascript.
frostcox 16-Jul-13 11:52am    
Improved :)
Thanks7872 16-Jul-13 12:24pm    
Always post comment using reply button because by that way,the one will get notified. Like in this case,he will not get any notification about the code you updated.

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.
 
Share this answer
 
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.

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900