Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从另一页调用事件_C#_Asp.net_Design Patterns - Fatal编程技术网

C# 从另一页调用事件

C# 从另一页调用事件,c#,asp.net,design-patterns,C#,Asp.net,Design Patterns,我有两页:PageListAnimals和PageEditAnimal 在PageListAnimals中,有一个包含动物信息的gridview。我可以点击每只动物打开页面EditAnimal:在一个新窗口中打开另一个页面 当我编辑完动物信息后,我想保存并关闭窗口PageEditAnimal,然后,其他窗口PageListAnimals将被刷新,或者更新其中的网格视图 我知道javascript中存在解决方案,但我想在服务器端实现它 例如,我认为有可能有类似观察者模式的东西。当PageEditA

我有两页:PageListAnimals和PageEditAnimal

在PageListAnimals中,有一个包含动物信息的gridview。我可以点击每只动物打开页面EditAnimal:在一个新窗口中打开另一个页面

当我编辑完动物信息后,我想保存并关闭窗口PageEditAnimal,然后,其他窗口PageListAnimals将被刷新,或者更新其中的网格视图

我知道javascript中存在解决方案,但我想在服务器端实现它

例如,我认为有可能有类似观察者模式的东西。当PageEditAnimal关闭时,会通知PageListAnimals更新自己

请给我一个线索或什么帮助我解决那个问题

编辑-已解决:

解决方案是从子对象调用父对象的刷新,但我只是用javascript实现了这一点:

 window.onbeforeunload = function () {
      window.opener.refresh();
 }

然后在父级中,javascript函数方法必须更新内部的gridview。

为什么需要打开另一个页面进行编辑

而是在同一页面中打开,编辑完成后,重定向到PageListAnimages页面


如果您坚持让PageListAnimals保持打开状态,那么我认为唯一的方法就是使用javascript。只需创建一个对包含GridView.Databind方法的服务器端函数的调用。

您可以这样做:

将此脚本添加到页面的头部

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>

    $(window).focus(function () {
        document.getElementById('<%= Button3.ClientID %>').click();
    });
</script>
谨慎
无论何时进入PageListAnimals页面,都会调用此代码,因此请小心使用。

Ajax是处理此问题的最佳方法。另一个解决方案是在弹出窗口关闭时用javascript刷新浏览器。因为事件发生在客户端,所以您必须在客户端启动它。您也可以强制父级从子级内部刷新,但再次。你的项目是Web应用程序还是网站???这是一个Web应用程序!然后介绍如何实现,但必须使用javascript函数关闭窗口,并使用registerstartupscript在代码隐藏中调用此函数。可以吗?当PageListAnimals被聚焦时调用此代码。我只想在另一个窗口PageEditAnimal关闭时更新她:/Yes,但只有转到该页面时才能看到数据,如果这样做,该页面将有新数据。如果你不看数据,你就不会对刷新数据感兴趣。就像这样,我无法更改它。动物必须是一个新窗口
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>

    $(window).focus(function () {
        document.getElementById('<%= Button3.ClientID %>').click();
    });
</script>
<asp:Button ID="Button3" style="display:none"; runat="server" Text="Button" onclick="Button3_Click" />
protected void Button3_Click(object sender, EventArgs e)
{
    //This is how your data should be bind in GridView
    GridView1.DataBind(); //GridView1 -> name whatever your gridview is named
}