How can a control in an asp.net page tell its cont

2019-09-05 00:38发布

It is difficult to explain but here it goes

I have a custom control in my asp.net page, i have two files which i pass page by page to the control, the user does some editing on that file's page (loaded in the control) and when it reaches the end i want the control to some how let the page know that the end of the page has been reached, now load a new page in the control,

How should i achieve this and which is the best practice?

1条回答
不美不萌又怎样
2楼-- · 2019-09-05 01:10

You can bubble up the event from user control to the parent.

ParentAddUser.aspx

<uc1:AddUser ID="AddUser1" runat="Server" OnUserCreated="AddUser1_UserCreated"></uc1:AddUser>

ParentAddUser.aspx.cs

protected void AddUser1_UserCreated(object sender, CommandEventArgs e)
{
    // User was created successfully. Do Something here.
}

AddUser.ascx.cs

public event CommandEventHandler UserCreated;
protected void Button_Click(object sender, EventArgs e)
{
    // User was created successfully. Bubble up the event to parent. 
        UserCreated(this, new CommandEventArgs("UserId", userId.ToString()));

}
查看更多
登录 后发表回答