calling an event on a button in a userControl (ASP.NET)

Discussion in 'ASP .Net Web Controls' started by gonzal kamikadze, Sep 17, 2005.

  1. Hi.

    For the last couple of days I'm truing to find out a way of having a button
    with a sub function for that button in a userControl without success.
    Any help would be much appreciated, thanks.

    Code that I have so far (that does not work, I think the raise event is not
    executing because the button clicks OK (no errors) but nothing is happening)


    Code:
    
    --- begining of {MasterPage.aspx}
    <%@ Page Language="VB" ContentType="text/html"
    ResponseEncoding="iso-8859-1" Debug="true" %>
    <%@ Import Namespace="FPB" %>
    ...
    <script runat="server">
    Sub Page_Load()
    Dim myControl1 As ResultsHeaderPlaceHolder =
    CType(LoadControl(Request.ApplicationPath &
    "/userControls/searchHeader.ascx"), ResultsHeaderPlaceHolder)
    plhResultsHeader.Controls.Add(myControl1)
    End Sub
    </script>
    ...
    <asp:PlaceHolder ID="plhResultsHeader" runat="server" />
    --- end of {MasterPage.aspx}
    
    
    --- begining of {codeBehindMasterPage.vb}    (NOTE: compiled code location
    in BIN directory)
    ...
    Namespace FPB
    
    Public Class ResultsHeaderPlaceHolder
    Inherits UserControl
    Protected WithEvents btnNewSearch As Button
    End Class
    
    End Namespace
    --- end of {codeBehindMasterPage.vb}
    
    
    --- begining of {userControls\searchHeader.ascx} (NOTE: I require to load a
    different userControl for different users, that's way I have to have the sub
    in the userControl)
    <%@ Control Language="VB" AutoEventWireup="false"
    Inherits="FPB.ResultsHeaderPlaceHolder" %>
    <%@ Import Namespace="System.Web.UI.HtmlControls" %>
    <script runat="server">
    Public Event btnNewSearchX(ByVal sender As Object, ByVal e As
    System.EventArgs)
    
    Public Sub btnNewSearch_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnNewSearch.Click
    Response.Redirect("somePage.aspx")
    RaiseEvent btnNewSearchX(Me, New System.EventArgs)
    End Sub
    </script>
    
    <asp:Button ID="btnNewSearch" text="New Search"
    onClick="btnNewSearch_Click" runat="server" /
    --- end of {userControls\serchHeader.ascx}
    
    [end of code]
    
    
    Walking thru the code:
    1. The master page is executing and loading the userControl linking it to a
    placeHolder on the page.
    2. Code behind page is declaring the button with WithEvents
    3. The user control displays the button on the page and it also contain the
    code to execute when the button is clicked.
    
    
    
    If anybody have any idea what is wrong with the code... much appreciated
    
    Regards,
     
    gonzal kamikadze, Sep 17, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    4
    Views:
    3,981
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jul 29, 2004
  2. moi
    Replies:
    2
    Views:
    14,362
    =?Utf-8?B?RFdT?=
    Mar 8, 2006
  3. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    187
  4. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    189
    vatech1993
    Dec 11, 2004
  5. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    159
Loading...

Share This Page