使用 ASP.NET ModalPopup 控件时回发父页面

发布于 2024-10-07 10:58:20 字数 184 浏览 7 评论 0原文

我有一个自定义 UserControl,它显示模式弹出窗口(来自 Ajax 工具包)。该控件允许用户向父页面在 GridView 中显示的客户记录添加注释。

用户单击模式弹出窗口上的“添加注释”按钮并关闭它后,我无法强制父页面重新加载网格。该注释已正确添加到数据库中,但我必须手动刷新页面才能显示它,而不是在保存+关闭弹出窗口时自动刷新。

I have a custom UserControl that displays a modal popup (from the Ajax Toolkit). The control allows the user to add a note to a customer record which the parent page displays in a GridView.

I'm unable to force the parent page to reload the grid after the user clicks the "Add Note" button on the modal popup and closes it. The note is added to the database correctly, but I have to manually refresh the page to get it to display instead of it automatically refreshing when I save+close the popup.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2024-10-14 10:58:20

将注释添加到数据库后,您可以使用委托在父页面中触发事件。

// Declared in Custom Control.
// CustomerCreatedEventArgs is custom event args.
public delegate void EventHandler(object sender, CustomerCreatedEventArgs e);
public event EventHandler CustomerCreated;

添加注释后,触发父页面事件。

    // Raises an event to the parent page and passing recently created object.
    if (CustomerCreated != null)
    {
        CustomerCreatedEventArgs args = new CustomerCreatedEventArgs(objCustomerMaster.CustomerCode, objCustomerMaster.CustomerAddress1, objCustomerMaster.CustomerAddress2);
        CustomerCreated(this, args);
    }

在父页面中,实现重新填充grdiview所需的事件。

protected void CustomerCreated(object sender, CustomerCreatedEventArgs e)
{
    try
    {
        BindGridView();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

在您的情况下,您不能使用任何自定义事件参数,而应使用 EventArgs 类本身。

You can use a delegate to fire an event in parent page after note is added to the database.

// Declared in Custom Control.
// CustomerCreatedEventArgs is custom event args.
public delegate void EventHandler(object sender, CustomerCreatedEventArgs e);
public event EventHandler CustomerCreated;

After note is added, fire parent page event.

    // Raises an event to the parent page and passing recently created object.
    if (CustomerCreated != null)
    {
        CustomerCreatedEventArgs args = new CustomerCreatedEventArgs(objCustomerMaster.CustomerCode, objCustomerMaster.CustomerAddress1, objCustomerMaster.CustomerAddress2);
        CustomerCreated(this, args);
    }

In parent page, implement required event to re-fill grdiview.

protected void CustomerCreated(object sender, CustomerCreatedEventArgs e)
{
    try
    {
        BindGridView();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

In your case, you can not use any custom event args, and use EventArgs class itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文