I have a USerControll in which i have a textbox. I use the usercontrol in my form, I want to do something when somebody presses enter on the textbox. how can I do it? if you
What you describe is called event bubbling. Here's an example:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="MyUserControl" %>
public partial class MyUserControl : UserControl
{
public event EventHandler UserControlTextBoxChanged;
protected void TextBox1_TextChanged(object sender, EventArgs e) {
if (UserControlTextBoxChanged != null)
UserControlTextBoxChanged(sender, e);
}
}
<%@ Page Language="C#" AutoEventWireup="True" Inherits="Default" CodeBehind="Default.aspx.cs" %>
<%@ Register Src="~/MyUserControl.ascx" TagName="MyUserControl" TagPrefix="uc1" %>
public partial class MyPage : Page {
protected void ucMyUserControl_UserControlTextBoxChanged(object sender, EventArgs e) {
// sender is ucMyUserControl.TextBox1
}
}