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

G

gonzal kamikadze

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top