|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Nested Child Control Events Not Firing1) Grandpa Control: Has web controls and a Panel control that has a Daddy Control in it. 2) Daddy Control: Has a textbox, a couple of buttons and an empty Panel control. 3) Grandson Control: Has a couple of labels and one button (Delete). On Page_Load, Granpda Control loads properly and all events are handled fine. Daddy Control is also loaded and all events are handled fine. In the empty Panel on the Daddy Control, several instances of the Grandson Control are added through code (LoadControl). Everything appears to be fine. I click the Delete button on Grandson Control #1, the event is handled and Grandson #1 is deleted. At the end of the Delete Grandson procedure, I bubble an event up to the Daddy Control signalling it to empty the Panel of all controls, and re-add the Grandson Controls. Everything looks fine, all of the Grandson Controls show up except the recently deleted Grandson Control. Here is the problem. If I click the Delete button on Grandson Control #2, the page posts back and all Page_Load procedures are executed... but the event which handles the Delete button click is not handled. After the PostBack completes, Grandson #2 is still in the Panel on the Daddy Control and still in the database. If I click the delete button again for Grandson #2, the Delete button click event is fired as expected. So, 3rd generation control events are handled on every other click. Why? I've run into this problem before in a much more complicated scenario. I never got it to work and so I redesigned everything to have only 2 generations of user controls and every thing worked fine. Please help! Thanks! -E > I click the Delete button on Grandson Control #1, the event is handled If you are are bubbling an event, I would recommend not to handle it.> and Grandson #1 is deleted. At the end of the Delete Grandson > procedure, I bubble an event up to the Daddy Control signalling it to > empty the Panel of all controls, and re-add the Grandson Controls. > Everything looks fine, all of the Grandson Controls show up except the > recently deleted Grandson Control. If an event is handled, it should not be marked for further bubbling up. Anyway... coming to your scenario... personally, I won't be able to comment unless I happen to see the code... may be at least in action. btw, the Grandson control is a user control? or a custom web-control? -- Happy Hacking, Gaurav Vaish | www.mastergaurav.com www.edujinionline.com http://articles.edujinionline.com/webservices ----------------------------------------- Gaurav,
I've pasted the appropriate code and HTML below. To answer your question, yes the Grandson control is a custom control made up of standard Web controls. I think I'm handling the bubble events properly. I built a custom eventargs class with custom parameters. If the OnBubbleEvent catches an event with my custom class, it checks the custom parameters to see if that particular control should handle it. If the control should not handle the event, it passes it on up. If the eventargs are not my custom type, it passes it up. If the event is handled, the function returns true and the event does not bubble up further. If this is not correct, please let me know. Here is the code & HTML. Obviously, watch for line wrap: Grandpa Control: ViewPhotoGallery.ascx <%@ Control Language="vb" Inherits="ViewPhotoGallery"CodeFile="ViewPhotoGallery.ascx.vb" AutoEventWireup="false" Explicit="True" %> <%@ Reference Control="~/DesktopModules/PhotoAlbum/PhotoGalleryCommentViewer.ascx" %> <asp:Label ID="lblPhotoTitle" runat="server"></asp:Label> <asp:Label ID="lblPhotoCaption" runat="server"></asp:Label> <asp:Panel ID="pnlTitleComments" runat="server"> <uc1:PhotoGalleryCommentViewer ID="PhotoGalleryCommentViewer1" runat="server" /> </asp:Panel> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Page.MaintainScrollPositionOnPostBack = True GenerateAlbumPreviews() End Sub Sub GenerateAlbumPreviews() PhotoGalleryCommentViewer1._IsEditable = IsEditable PhotoGalleryCommentViewer1._PhotoID = CPhoto.ItemID End Sub Daddy Control: PhotoGalleryCommentViewer.ascx <%@ Control Language="VB" AutoEventWireup="false" CodeFile="PhotoGalleryCommentViewer.ascx.vb" Inherits="PhotoGalleryCommentViewer" %> <%@ Reference Control="~/DesktopModules/PhotoAlbum/PhotoGalleryCommentItem.ascx" %> <asp:TextBox ID="txtComment" runat="server" Height="70px" TextMode="MultiLine" Width="150px"></asp:TextBox> <asp:TextBox ID="txtAuthor" runat="server" Width="150px"></asp:TextBox> <asp:LinkButton ID="lbClear" CssClass="CommandButton" runat="server">Clear</asp:LinkButton> <asp:LinkButton ID="lbSubmit" CssClass="CommandButton" runat="server">Submit</asp:LinkButton> <asp:Panel ID="pnlComments" runat="server" Width="150px"> </asp:Panel> Public _PhotoID As Integer Public _IsEditable As Boolean Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load GetComments() End Sub Sub GetComments() pnlComments.Controls.Clear() Dim CComment As New CommentInfo Dim Comments As List(Of CommentInfo) Comments = PGController.GalleryPhotoCommentByPhotoID_qry(_PhotoID) CRow = New TableRow CCell = New TableCell Dim CommentItem As PhotoGalleryCommentItem For Each CComment In Comments CommentItem = LoadControl("PhotoGalleryCommentItem.ascx") CommentItem._ItemID = CComment.ItemID CommentItem._CommentAuthor = CComment.Author CommentItem._CommentDate = CComment.PostDate CommentItem._CommentText = CComment.Comment CommentItem._IsEditable = _IsEditable CRow.Cells.Add(CCell) CTable.Rows.Add(CRow) Next pnlComments.Controls.Add(CTable) CTable = Nothing CRow = Nothing CCell = Nothing CommentItem = Nothing PGController = Nothing CComment = Nothing End Sub Protected Overrides Function OnBubbleEvent(ByVal source As Object, ByVal args As System.EventArgs) As Boolean If args.GetType.Equals(GetType(PhotoGalleryEventArgs)) Then 'This is a PhotoGallery specific event capture it and process or pass it up the food chain Dim PGArgs As PhotoGalleryEventArgs = CType(args, PhotoGalleryEventArgs) Select Case PGArgs.Action.ToUpper Case "REDRAWCOMMENTS" GetComments() 'Swallow this event Return True Case Else 'This is not an event for this procedure pass it on up the food chain Return False End Select Else 'This is not an event for this code. Pass it on up the food chain Return False End If End Function Grandson Control: PhotoGalleryCommentItem.ascx <%@ Control Language="VB" AutoEventWireup="false" CodeFile="PhotoGalleryCommentItem.ascx.vb" Inherits="PhotoGalleryCommentItem" %> <asp:Label ID="lblComment" runat="server"></asp:Label> <asp:Label ID="lblCommentDetails" runat="server"></asp:Label> <asp:ImageButton ID="ibDeleteComment" runat="server" ImageUrl="~/images/delete.gif"/> Public _ItemID As Integer Public _CommentText As String Public _CommentDate As Date Public _CommentAuthor As String Public _IsEditable As Boolean Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load lblComment.Text = _CommentText lblCommentDetails.Text = _CommentAuthor & "<br />" & _CommentDate ibDeleteComment.Visible = _IsEditable End Sub 'THIS PROC IS EXECUTED ON THE 1ST, 3RD, 5TH, CLICK, BUT NEVER THE 2ND, 4TH, 6TH, ETC. Protected Sub ibDeleteComment_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibDeleteComment.Click Dim PGController As New PhotoGalleryController If PGController.GalleryPhotoComment_del(_ItemID) > 0 Then Dim PGEventArgs As New PhotoGalleryEventArgs("RedrawComments", "", "") RaiseBubbleEvent(Me, PGEventArgs) Else Response.Write("<script language='javascript'>alert('An error occured. The comment was not deleted. Please try again.');</script>") End If End Sub
Javascript alert message problem
HTML can't find Caption property for datagrid Compiler Error Message: BC30456: 'btnGAT_onClick' is not a member of 'ASP.WebForm1_aspx' Confirm Message in gridview Object data source, setting parameter source to Page.Partner.Guid Paging In GridView bound to DataSet Calendar Web Control Search in .NET DataFormatString Date RowCommand Event of a nested Gridview |
|||||||||||||||||||||||