我在Usercontrol.ascx中有以下方法
public void Flasmessage()
{
popupmessage2.Visible = true;
string strScript = "HideCtrl('" + popupmessage2.ClientID + "','15000')";
Page.ClientScript.RegisterStartupScript(
this.GetType(),
Guid.NewGuid().ToString(),
strScript,
true);
}我需要从另一个页面和另一个Usercontrol.ascx调用以下方法
发布于 2012-11-08 17:38:24
您需要在页面上获取对UserControl实例的引用,然后调用该方法,如下所示:
void Page_Load() {
// do this if your control does not exist in your *.aspx file and needs to be manually added:
MyUserControl control = (MyUserControl)LoadControl("MyUserControl.ascx");
this.Controls.Add( control );
// do this if your control already exists in your page as a named control
MyUserControl control = (MyUserControl)FindControl("myUserControl");
// do this in both cases, or if your UserControl exists as a field in your *.aspx-generated page class.
control.MyMethod();
}https://stackoverflow.com/questions/13286217
复制相似问题