asp.net页中的控件如何告知其容器页已完成处理? [英] How can a control in an asp.net page tell its container page that it finished processing?

查看:60
本文介绍了asp.net页中的控件如何告知其容器页已完成处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很难解释,但是在这里

我在asp.net页面中有一个自定义控件,我有两个文件,我逐页将其传递给控件,​​用户在该文件的页面上进行一些编辑(加载到控件中),并在文件到达末尾时进行编辑我希望控件以某种方式让页面知道到达页面的末尾,现在在控件中加载新页面,

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?

推荐答案

您可以将事件从用户控件扩展到父控件.

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

ParentAddUser.aspx

ParentAddUser.aspx

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

ParentAddUser.aspx.cs

ParentAddUser.aspx.cs

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

AddUser.ascx.cs

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()));

}

这篇关于asp.net页中的控件如何告知其容器页已完成处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆