Raiseevent user control in user control

 Hi there,

I am working on a project in which a user control (BedrijfMasterDatagrid.ascx) is creating an other user control (BedrijfDatagrid.ascx).
The user control BedrijfDatagrid.ascx is correctly created, but the clicked event of the created image control (BedrijfDatagrid.ibImageButtonClicked ) is not fired. (see BedrijfDetail.aspx)
When I place BedrijfDatagrid.ascx directly on the page the event is correctly fired.

Summary:
BedrijfMasterDatagrid.ascx:       Datagrid with 1 row in which BedrijfDatagrid is dynamically created
BedrijfDatagrid.ascx                  Datagrid with 1 row including a imagebuton which clicked event should be fired
BedrijfDetail.aspx                      aspx webpage in which BedrijfMasterDatagrid.ascx is placed. In this page I want to use the event BedrijfDatagrid.ibImageButtonClicked, but this event is not fired!!!

Does anybody have a clue what I do wrong?

Many thanx for you help!


Below the code I use:

 BedrijfmasterDatagrid.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="BedrijfMasterDatagrid.ascx.vb" Inherits="Bedrijf.BedrijfMasterDatagrid" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
  <link href="../../../RSDHome.css" type="text/css" rel="stylesheet" />
 </head>
 <body>
  <table cellspacing="0" cellpadding="0" width="100%">
   <tr>
    <td><asp:datagrid id="dgBedrijfMaster" AutoGenerateColumns="False" PageSize="50" AllowCustomPaging="True" ShowHeader="false" OnItemDataBound="dgBedrijfMaster_ItemDataBound" runat="server">
         <HeaderStyle CssClass="datagridHeader"></HeaderStyle>
         <ItemStyle CssClass="datagridRow"></ItemStyle>
         <AlternatingItemStyle CssClass="datagridAlternating"></AlternatingItemStyle>
         <Columns>
          <asp:TemplateColumn HeaderText="KOLOM 1" HeaderStyle-Width="130" ItemStyle-VerticalAlign="Top">
           <ItemTemplate>
            <asp:Label id="laKolom1" runat="server" Text='<%#Container.DataItem("Kolom1")%>'>
            </asp:Label>
           </ItemTemplate>
          </asp:TemplateColumn>
         </Columns>
        </asp:datagrid>
    </td>
   </tr>
  </table>
 </body>
</html>

Partial Public Class BedrijfMasterDatagrid

    Inherits System.Web.UI.UserControl

    Public Event ibImageButtonClicked(ByVal sender As Object, ByVal e As ImageClickEventArgs)

    Public Sub BEDRIJFMASTERDATAGRID_MAIN_PROC()

        'initialise datatable
        Dim BedrijfMasterTable As New DataTable
        BedrijfMasterTable.Clear()
        BedrijfMasterTable.Columns.Clear()
        BedrijfMasterTable.Columns.Add("Kolom1", System.Type.GetType("System.String"))

        'fill 1 row for placement BedrijfDatagrid
        Dim BedrijfMasterRow As DataRow = BedrijfMasterTable.NewRow
        BedrijfMasterTable.Rows.Add(BedrijfMasterRow)

        'fill datagrid
        dgBedrijfMaster.DataSource = BedrijfMasterTable
        dgBedrijfMaster.DataBind()

    End Sub

    Public Sub dgBedrijfMaster_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

            'creeer bedrijf en plaats binnen datagrid
            e.Item.Cells(0).Controls.Add(setBedrijfDatagrid())

        End If

    End Sub

    Private Function setBedrijfDatagrid() As BedrijfDatagrid

        'fill machineindeling machine
        Dim BedrijfDatagrid As BedrijfDatagrid = LoadControl("~/User controls/BedrijfDatagrid.ascx")
        AddHandler BedrijfDatagrid.ibImageButtonClicked, AddressOf ibImageButton_Click

        Call BedrijfDatagrid.BEDRIJFDATAGRID_MAIN_PROC()

        Return BedrijfDatagrid

    End Function

    Public Sub ibImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

        RaiseEvent ibImageButtonClicked(sender, e)

    End Sub

End Class

BedrijfDatagrid.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="BedrijfDatagrid.ascx.vb" Inherits="Bedrijf.BedrijfDatagrid" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
  <link href="../../../RSDHome.css" type="text/css" rel="stylesheet" />
 </head>
 <body>
  <table cellspacing="0" cellpadding="0" width="100%">
   <tr>
    <td><asp:datagrid id="dgBedrijf" AutoGenerateColumns="False" PageSize="50" AllowCustomPaging="True" OnItemDataBound="dgBedrijf_ItemDataBound" runat="server">
      <HeaderStyle CssClass="datagridHeader"></HeaderStyle>
      <ItemStyle CssClass="datagridRow"></ItemStyle>
      <AlternatingItemStyle CssClass="datagridAlternating"></AlternatingItemStyle>
      <Columns>
       <asp:TemplateColumn HeaderText="MEDEWERKER NAAM" HeaderStyle-Width="130">
        <ItemTemplate>
            <!--Medewerker naam -->
         <asp:Label id="laMedewerkerNaam" runat="server" Text='<%#Container.DataItem("Medewerker naam")%>'>
         </asp:Label>
        </ItemTemplate>
       </asp:TemplateColumn>
       <asp:TemplateColumn ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
         <!--Save/delete (2) -->
        </ItemTemplate>
       </asp:TemplateColumn>
      </Columns>
     </asp:datagrid>
    </td>
   </tr>
  </table>
 </body>
</html>

Partial Public Class BedrijfDatagrid

    Inherits System.Web.UI.UserControl

    Public Event ibImageButtonClicked(ByVal sender As Object, ByVal e As ImageClickEventArgs)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Sub BEDRIJFDATAGRID_MAIN_PROC()

        'initialise datatable
        Dim BedrijfTable As New DataTable
        BedrijfTable.Clear()
        BedrijfTable.Columns.Clear()
        BedrijfTable.Columns.Add("Medewerker naam", System.Type.GetType("System.String"))

        'fill row
        Dim BedrijfRow As DataRow = BedrijfTable.NewRow
        BedrijfRow.Item("Medewerker naam") = "TEST"
        BedrijfTable.Rows.Add(BedrijfRow)

        'fill datagrid
        dgBedrijf.DataSource = BedrijfTable
        dgBedrijf.DataBind()

    End Sub

    Public Sub dgBedrijf_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

        'add imagebutton delete
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            e.Item.Cells(1).Controls.Add(setImageButton("DELETE"))
        End If

    End Sub

    Private Function setImageButton(ByVal ACTIE As String) As ImageButton

        Dim ibImageButton As New ImageButton

        ibImageButton.ImageUrl = "~\Images\Delete.gif"
        ibImageButton.ToolTip = "Verwijder medewerker"
        ibImageButton.CommandName = "Delete"

        ibImageButton.ID = "ibDelete"
        ibImageButton.CommandArgument = ACTIE
        AddHandler ibImageButton.Click, AddressOf ibImageButton_Click

        Return ibImageButton

    End Function

    Public Sub ibImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

        RaiseEvent ibImageButtonClicked(sender, e)

    End Sub

End Class

BedrijfDetail.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="BedrijfDetail.aspx.vb" Inherits="Bedrijf.BedrijfDetail" %>

<%@ Register TagPrefix="uc1" TagName="BedrijfMasterDatagrid" Src="User controls/BedrijfMasterDatagrid.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <uc1:BedrijfMasterDatagrid id="BedrijfMasterDatagrid" runat="server"></uc1:BedrijfMasterDatagrid>
    </div>
    </form>
</body>
</html>

Partial Public Class BedrijfDetail

    Inherits System.Web.UI.Page

    Protected WithEvents BedrijfMasterDatagrid As Global.Bedrijf.BedrijfMasterDatagrid

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Call BedrijfMasterDatagrid.BEDRIJFMASTERDATAGRID_MAIN_PROC()

    End Sub

    Private Sub ibImageButtonClicked_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BedrijfMasterDatagrid.ibImageButtonClicked

        'THIS EVENT IS NOT FIRED

    End Sub

End Class

0
minds999
1/25/2009 8:08:36 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

1 Replies
817 Views

Similar Articles

[PageSpeed] 3
Get it on Google Play
Get it on Apple App Store

Hi,

Based on my knowledge, if you want to fire a child control event, you need to know the event bubbling mechenism in user control, the event fired from child control can continue to pass through layers, starting at the bottom (the user control) and perhaps reaching the top level.

For more details on how to pass your child control events to top layer, see:

http://www.odetocode.com/code/94.aspx

Thanks.


Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Nai
1/28/2009 3:25:53 AM
Reply:

Similar Artilces:

User Control in a User Control
I have a first user control that contain a second user control. If I cahe the first user control can I still dynamically control the second one or it is cached with the first one therefore can not control it anymore? Thanks When your first control is cached, its rendered out and its output is stored in the cache. On every request to the page containing your control that can satisfy it from cache, the output will just simply be inserted - your first control will never be instantiated or run in that case, so the second one wont be either. Hope this helps,Mike VolodarskyProgram Manager...

user control to user control
I have an aspx page that have a "Register" directive to two usercontrol called rptMaster.ascx and rptDetail.ascx. I'm trying to set up a Master-Detail relationship and wish for the rptMaster.ascx to trigger and event from a dropdownlist and for the rptDetail to be listening for DropDownList event. I believe I have gotten the events part okay with help from this articel http://codeproject.com/aspnet/Page_UserControl.asp but my declaration for a private statement to my rptMaster class is producing an error. I'm using beta 2 of asp.net and I 'm having trouble getting a reference TO ...

User Controls in User Controls?
I have the follow set up and it is throwing an error "Unhandled error loading module" ... is there some trick to this that I don't know?I have a project A that uses controls from project B (project B is just a project with all my user controls used through out other modules).  project A uses user control 1 from project B with out any issues at all - great.  But then I wanted to add user control 2 to user control 1 and that is when I get my error.  In fact I don't even have the user control 2 in user control 1, just when I put the register part into user control 1 is when it al...

User control in a user control
Hello all, I have created a user control with some checkboxes, and public properties to get the values of these checkboxes. I have also created a second user control using the first user control; this second control also access the public properties of the first one. My problem is when I implement the second control in an aspx page, if I click at runtime the checkboxes in the first control, I am able to access its public properties from the methods of the second control but the values of these properties are wrong. while at design time, I do not have this problem. Than...

User Control controls not created when dynamically creating user control
  Have created a user control for displaying and editing a dynamically number of values. The user control contains two labels and an edit box. When dynamically loading the user control I get an error when the control itself tries to change setting on the fields within the user control.   Why doesnt this work? It works okay if I dont load it dynamically but create a user-control-instance in the aspx-page but thats no solution.   Thankyou!     Here is my code:   ucDataValue.ascx   <%@ Control Language="C#" AutoEventWireup="true&...

User Controls not working if I put Validation controls in user control
Hi           I have validation controls(RequiredField Validator,RegularExpressionValidator)  in user controls.User controls are not posting back like the events are not wiring up.If I remove Validation controls in User controls page,user controls are working fine.Can anyone please help me out in getting it fixed. In the Validation controls, make sure you are setting the ControlToValidate property to the control that it links to.  If you're in .NET 2.0, it's also a good idea to put all the validation controls in the same Valid...

How to access a user control from another user control in a Wizard control
My page has a wizard control and each step is a user control.  I could find the value of a control in step1 user control in the wizard page but not in step2 user control.From wizard.aspx.vb – it worksDim m_title As DropDownList = CType(Me.PersonalBox1.FindControl("ddlTitle1"), DropDownList) Question:How can I find the value of a control(textbox or dropdownlist)in step1 user control from step2 user control? I want to find “PersonalBox1.FindControl("ddlTitle1")” from Step2 AddressBox1. I have tried several ways to access it but no luck. From AddressBox.ascx.vb –...

load user control from server custom control
hi all,i have a 3rd party menu control that consists of a bunch of HyperLinks and a PlaceHolder control (C# v1.1.4) . links to .ascx files are retrieved from a data source, and when the page containing the control is loaded or a link clicked, the control uses this.Page.LoadControl(strLink) to add the .ascx to the PlaceHolder. fine and dandy, probably wouldnt have done it that way myself, but i'm stuck with it :)the problem is events: i can't raise 'em :( if i have for example a Button control on one of the .ascx pages, the Button.Click will go by unnoticed on the post-back. stran...

Using a user control in a custom server control.
I've created a custom server control and am trying to add a user control to the rendering of the server control.  Is this possible?  If so, hints as to how this is done would be GREATLY appreciated!  Thanks in advance for considering an answer to this question. Wendi Use the LoadControl method. For example:   Controls.Add(LoadControl("~/controls/login.ascx"))Steven BeyRecursion: see Recursion My server control renders a table with x number of rows.  I want to add a user control to each row of the table, last column.  I do not know how ...

Updating a Label control in one user control from another user control
Hi all, I have a main page in my music store site that has 5 user controls on it with 1 always showing main content and the others being things like a shopping cart, "best sellers", genre list etc (a la amazon). From the main content control I want to be able to set some label controls in my shopping basket control but I just can't seem to work out the syntax for how to do this: Here's the code I'm using - I'm trying to go to the 4th user control on the page (my shopping basket) then find the appropraite label, cast it locally as a Label then update the value: Label _so...

user control or custom control ?
i have datagrid which shows monthyear user control for each row. The month year user control has two drop down list. one is for year and other one is for month. So for each row in particular column i'll have that user control loaded. it works fine but ut takes lot of time in rendering when there are 200 rows. what would be the solution. will custom control help? Hi,Lax4u: Some tips i am not quite sure. First, you can disable the viewstate of the userControl to make it not load so many information in each postback and store the necessary in the global range. Second, Caching porting of th...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

User Controls and Custom Controls
what is Diff between User Controls and Custom Controls? User controls are asmx files, you can use them as a webpage, drag and drop as many controls you want and still user the user control to drop it into a form.Custom Controls are inherit from the control or used as composite control. You need to write the control by hand and override all the properties. They can be added into your toolbar.Hope this helpsCheersAlMy BlogMapStats.NETPlease click on 'Mark as Answer' if this post answered your question! Also... User Controls are generally application specific.  If you want...

user control and custom control
What is different between Web User Control and Web Custom Control? http://support.microsoft.com/kb/893667Thanks, EdMicrosoft MVP - ASP/ASP.NET I would suggest you to google the word "different between Web User Control and Web Custom Control" to get more informations and results...Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET Web custom controls are compiled components that run on the server and that encapsulate user-interface and other related functionality into reusable pack...

Web resources about - Raiseevent user control in user control - asp.net.custom-server-controls

Wikipedia talk:AutoWikiBrowser/Bugs - Wikipedia, the free encyclopedia
Only use this page to report bugs in the current version of the software. Update to the most recent version, check to make sure your bug has ...

netframework - moredotnet
.NET - is the Microsoft Web services strategy to connect information, people, systems, and devices through software. Integrated across the Microsoft ...

Resources last updated: 12/4/2015 11:08:41 AM