Re: User Control Event Handlers
- From: rn5a@xxxxxxxxxxxxxx
- Date: 7 Oct 2006 19:54:06 -0700
Gregory, this is what I came up with (in the ASCX page):
<script runat="server">
Public Event TextChanged(ByVal obj As Object)
Public Sub OnTextChanged(ByVal obj As Object, ByVal ea As
EventArgs) Handles txtAddress.TextChanged
RaiseEvent TextChanged(Me)
End Sub
</script>
Now how do I handle the event?
Please respond
rn5a@xxxxxxxxxxxxxx wrote:
Where should the event be bubbled up using RaiseEvent - in the ASCX
page?
Could you please link me to some articles on this topic?
Cowboy (Gregory A. Beamer) wrote:
If you need a control to fire an event on a parent: Bubble up the event to
the parent container using RaiseEvent.
1. Create an event
Public Event BubbleUpAlreadyRegistered As EventHandler(Of EventArgs)
2. Raise the event
RaiseEvent BubbleUpAlreadyRegistered(sender, e)
3. Handle the event
Protected Sub RegisterUnit1_BubbleUpUnitAlreadyRegistered(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
RegisterUnit1.BubbleUpAlreadyRegistered
If you need to do something on a control when the parent event is fired:
Fire the method on the control from code behind.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
*************************************************
Think outside of the box!
*************************************************
<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1160262681.709741.28640@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Consider the following user control which resides in Address.ascx:
<script runat="server">
Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property
Public Property Country() As String
Get
Country = txtCountry.Text
End Get
Set(ByVal value As String)
txtCountry.Text = value
End Set
End Property
</script>
<asp:TextBox ID="txtAddress" runat="server"/>
<asp:TextBox ID="txtCountry" runat="server"/>
This is how I am using the user control in a ASPX page:
<%@ Register TagPrefix="UC" TagName="UAddress" Src="Address.ascx" %>
<script runat="server">
Sub CopyAddress(obj As Object, ea As EventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<UC:UAddress ID="ud" runat="server">
<asp:CheckBox ID="chkAddress" OnCheckedChanged="CopyAddress"
AutoPostBack="true" Text="Copy Address" runat="server"/>
</form>
The above ASPX page will render the 2 TextBoxes (using the user
control) & a CheckBox. Note that when the CheckBox is checked/unchecked
by the user, the sub named 'CopyAddress' gets executed.
Now I want the 2 TextBoxes to also execute the 'CopyAddress' sub using
the OnTextChanged event of the 2 TextBoxes but since the 2 TextBoxes
actually reside in the user control, how do I fire the OnTextChanged
event handler of the 2 TextBoxes so that the 'CopyAddress' sub gets
executed?
.
- Follow-Ups:
- Re: User Control Event Handlers
- From: rn5a
- Re: User Control Event Handlers
- References:
- User Control Event Handlers
- From: rn5a
- Re: User Control Event Handlers
- From: Cowboy \(Gregory A. Beamer\)
- Re: User Control Event Handlers
- From: rn5a
- User Control Event Handlers
- Prev by Date: Re: GridView. Get value.
- Next by Date: "Unable to connect to SQL Server database" error when using profile
- Previous by thread: Re: User Control Event Handlers
- Next by thread: Re: User Control Event Handlers
- Index(es):
Relevant Pages
|