我有一个如下的方法来调用父页面中的方法。这个“DisplayMessage”函数接受一个字符串变量消息并在屏幕上显示它。在用户控件中,我放置了一个文本框和一个按钮。在按钮的单击事件中,我使用反射调用了我们上面讨论过的父页面方法,并将文本框的值传递给该方法,然后调用该方法并在屏幕上显示消息。
父页面:
父页面:
public void DisplayMessage(string message)
{
Response.Write(message);
}
用户控件:
protected void btnSend_Click(object sender, EventArgs e)
{
this.Page.GetType().InvokeMember("DisplayMessage",System.Reflection.BindingFlags.InvokeMethod, null, this.Page, new object[] { txtMessage.Text });
}
对我来说,它运行得很好。
现在我需要做的是,从父页面中调用存在于用户控件中的方法。
请给我建议。提前感谢。