【发布时间】:2013-08-30 07:44:58
【问题描述】:
我在两种不同的 aspx 表单中使用 asp.net 用户控件。如何根据调用表单自定义用户控件的事件处理?
void ComboboxCountry_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
if it is form1 that called the User-control => do process 1
if it is form2 that called the User-control => do process 2
}
谢谢。
【问题讨论】:
-
您可以使用
(Control)sender.Parent访问呼叫表单 -
我没有对象 "sender" 的属性 "Parent" 。也许我错过了什么?
-
((Control)sender).Parent- 我的错误,错过了大括号。 -
确实如此。我可以检索调用表单 ID 以将表单标识到用户控件中吗? IF ((Control)sender).Parent.ID = "xxxx" ),那么我在哪里可以获得 ID?或者也许我应该使用 ID 以外的其他属性。
-
您可以通过 .Name 属性访问它
标签: c# asp.net user-controls