如何从子页面触发更新面板回发?

发布于 2024-08-08 13:10:39 字数 467 浏览 4 评论 0原文

我在网格视图中的每一行的单元格中都有一个更新面板。用户单击此更新面板中的链接按钮以显示(使用 window.open())弹出窗口。在该弹出窗口中采取操作来更新上述更新面板中包含的数据。我只想在弹出窗口关闭时触发该更新面板的更新。

最好的方法是什么?我正在研究捕获 window.close 事件并以某种方式传递一个值来指示从何处调用弹出窗口,然后在 JavaScript 中调用该更新面板的回发。如果它有所作为(至少它会 - 呃 - 在我的 javascript 代码中),我正在使用母版页并且仅针对 IE 进行编码。

发现这个: http://forums.asp.net/p/1166328/1941797.aspx 使用 window.opener.document... 同样,使用母版页会使事情变得复杂。

I have an update panel in a cell for each row within a gridview. The user clicks a link button from this update panel to display (using window.open()) a popup. Action is taken in that popup that updates the data contained within the aforementioned update panel. I want to trigger an update only for that update panel when the popup is closed.

What is the best way to do this? I'm researching capturing the window.close event and somehow passing a value that indicates where the popup was called from and then calling a postback for that update panel in javascript. If it makes a difference (in the least it will - ugh - in my javascript code), I am using a master page and only coding for IE.

Found this: http://forums.asp.net/p/1166328/1941797.aspx which uses the window.opener.document... Again, using a master page complicates matters.

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

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

发布评论

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

评论(6

有木有妳兜一样 2024-08-15 13:10:39

您可以使用 JavaScript 函数 __doPostBack('eventTarget','eventArgument')。
在客户端也许看起来像这样。

function showPopup()
{
 var return = window.showModalDialog('someurl','','');
 if(return)
 {
  // do postback for update
  __doPostBack('<%= hiddenButton.ClientID %>','eventArgument');
 }
}

在服务器端,您应该使用带有 UpdateMode=Conditional 和隐藏按钮的更新面板,如 rick schott 所说。棘手的部分是知道哪个单元格需要更新。如果您为隐藏按钮连接了 OnClick,那么当调用 __doPostBack 时,它将触发该事件。您可以从服务器端访问Request.Form["__EVENTARGUMENT"]来访问__doPostBack发送的值。您可以使用此值来确定需要更新哪个单元格。

You can use javascript function __doPostBack('eventTarget','eventArgument').
In Client side perhaps looks like this.

function showPopup()
{
 var return = window.showModalDialog('someurl','','');
 if(return)
 {
  // do postback for update
  __doPostBack('<%= hiddenButton.ClientID %>','eventArgument');
 }
}

in server side you should use Update Panel with UpdateMode=Conditional and hidden button like rick schott says. The tricky part is to know which cell that needs to update. If you wired OnClick for hiddenbutton then it will fired that event when __doPostBack called. You can access Request.Form["__EVENTARGUMENT"] from server side to access value that __doPostBack sent. You can play with this value for instance which cell that need to update.

夕色琉璃 2024-08-15 13:10:39

我是通过 Flash 应用程序完成此操作的。如果你愿意的话,我的“黑客”是用 CSS 隐藏真正的 ASP:Button。该按钮位于 UpdatePanel 内。我将 Button.ClientId 传递给外部资源(Flash、新窗口...等)。当外部资源(在我的例子中是 Flash)完成时,它会调用一个接受 ClientId 的 JavaScript 函数,并在按钮上调用 .Click() 。

JavaScript:

function CallASPNETClick(id) {  
    var elmt = document.getElementById(id);   
    elmt.click();

}

标记:

!--this is uses for capture an event from Flash with javascript, do not remove--->
<asp:Button ID="hiddenButton" runat="server" Text="Button" style="visibility:hidden" OnClick="hiddenButton_Click" />

I have done this from a Flash application. My "hack" if you will was to hide a real ASP:Button with CSS. The button was inside the UpdatePanel. I passed the Button.ClientId to the external resource(Flash, new window...etc). When the external resource(Flash in my case) was finished, it calls a JavaScript function that accepts the ClientId and it calls .Click() on the button.

JavaScript:

function CallASPNETClick(id) {  
    var elmt = document.getElementById(id);   
    elmt.click();

}

Markup:

!--this is uses for capture an event from Flash with javascript, do not remove--->
<asp:Button ID="hiddenButton" runat="server" Text="Button" style="visibility:hidden" OnClick="hiddenButton_Click" />
凤舞天涯 2024-08-15 13:10:39

您可以使用调用页面上的隐藏字段来存储回调所需的任何值。弹出窗口可以使用 window.opener 来存储这些隐藏字段中的值。

您可以扩展 window.open 函数来更新页面上的 javascript 变量,并引用调用者:

<asp:button onclientclick="buttonClicked(this)" />

var lastButton;
function buttonClicked(button) {
lastButton = button;
window.open(x);
return false;
}

如果您将隐藏字段设置为 asp 控件,那么您将可以在更新面板的回发中访问它们。

编辑:

考虑使用模式弹出窗口来消除人们在您希望他们使用弹出窗口时单击调用页面的问题。

You could use hidden fields on the calling page to store any values you need for your callback. The pop-up can use window.opener to store the values in these hidden fields.

You can expand your window.open function to update a javascript variable on the page with a reference to the caller:

<asp:button onclientclick="buttonClicked(this)" />

var lastButton;
function buttonClicked(button) {
lastButton = button;
window.open(x);
return false;
}

If you make the hidden fields asp controls then you'll have access to them on the postback of the update panel.

Edit:

Consider a modalpopup to eliminate issues around people clicking on the calling page while you're expecting them to use the popup.

等待圉鍢 2024-08-15 13:10:39

我选择的更简单(且可行)的解决方案是使用 gridview 单元格中的用户控件内的 ModalPopupExtender 来实现此功能。用户控件包含只读结果网格和 ModalPopupExtender。弹出窗口允许您在父网格的单元格中编辑该网格的内容。单击“添加”按钮后,迷你网格将异步更新。

最终让我找到一个可行的解决方案的几个关键项目...

The simpler (and working) solution I chose was to implement this using the ModalPopupExtender within a user control in the gridview cell. The user control contains the read-only results grid and the ModalPopupExtender. The popup allows you to edit the contents of that grid within the cell of the parent grid. Upon clicking the Add button, the mini grid is updated asynchronously.

A few key items that finally got me to a working solution...

  • Wrap the contents of the panel referenced in the PopupControlId property in an update panel
  • Hide and show the modal popup in code behind
  • A simple and good example of a gridview using multiple ModalPopupExtenders
烟酉 2024-08-15 13:10:39

这两种方法都适合我

(1)通过从 MasterPAge 引用 ChildPage

 ContentPlaceHolder_content.FindControl("dvwOrder").Controls.Clear();
    ((UpdatePanel)this.ContentPlaceHolder_content.FindControl("upOrders")).Update();

此代码位于母版页内,在我的按钮上单击我正在使用 contentplaceholder 来查找其中控件的引用。这里 dvwOrder 是我的 DataView,“upOrders”是我的 UpdatePanel。

(2) 通过委托

将此委托和事件处理程序放在任何方法之外的母版页上

 public delegate void RefreshButtonClickHandler(object)

发送者,EventArgs e);
公共事件 RefreshButtonClickHandler
onRefreshButtonClick;

在按钮单击事件的类中执行此操作

 if(null == onRefreshButtonClick)
        {
            返回;                
        }

        onRefreshButtonClick(发送者, e);

然后在子页面的 Page_Load 方法中将此事件与本地处理程序联系起来

 子child = (child) this.Master;
        reports.onRefreshButtonClick += 新

儿童
.RefreshButtonClickHandler(reports_onRefreshButtonClick);

这里 Child 是我

创建的

    void child_onRefreshButtonClick(object sender, EventArgs e)
    {

    }

代码隐藏文件的名称,你就完成了

These Both ways works for me

(1) Via referencing ChildPage from MasterPAge

    ContentPlaceHolder_content.FindControl("dvwOrder").Controls.Clear();
    ((UpdatePanel)this.ContentPlaceHolder_content.FindControl("upOrders")).Update();

This code is inside Master Page and on my button click I am using contentplaceholder to find the reference for control inside it. Here dvwOrder is my DataView and "upOrders" is my UpdatePanel.

(2) Via Delegates

Put this delegate and eventhandler on Master Page outside any method

    public delegate void RefreshButtonClickHandler(object

sender, EventArgs e);
public event RefreshButtonClickHandler
onRefreshButtonClick;

inside the class inyour button click event do this

        if(null == onRefreshButtonClick)
        {
            return;                
        }

        onRefreshButtonClick(sender, e);

Then In Child page's Page_Load Method tie this event with local handler

        Child child = (child) this.Master;
        reports.onRefreshButtonClick += new

Child
.RefreshButtonClickHandler(reports_onRefreshButtonClick);

Here Child is my codebehind file's name

create

    void child_onRefreshButtonClick(object sender, EventArgs e)
    {

    }

and you are done

一枫情书 2024-08-15 13:10:39

我放弃了在单独的窗口中执行此操作的努力,而是使用 AJAX ModalPopupExtender 开发了该解决方案。 Matt Berseth 的示例非常有帮助。

为了更新父网格内更新面板中包含的子网格,我将单击按钮的行的值存储在会话变量中,然后在用户创建后使用该值(称为子网格的 databind 方法)他们的选择并单击“保存”。

protected void btnShowSkillsetPopup_Click(object sender, EventArgs e)
{
    // get the gridviewrow from the sender so we can get the datakey we need
    Button btnAddSkillsetsFromRow = sender as Button;
    GridViewRow row = (GridViewRow)btnAddSkillsetsFromRow.NamingContainer;

    Session["CapRes_ResourceRequestID"] = Convert.ToString(this.grdResources.DataKeys[row.RowIndex].Value);
    Session["CapRes_SkillsetUpdatePanel_Row"] = Convert.ToString(row.RowIndex);
    ModalPopupExtender.Show();
}

保存代码...

int nUpdatePanelID = Convert.ToInt32(Session["CapRes_SkillsetUpdatePanel_Row"].ToString());
UpdatePanel pnlSkillsetsMain = grdResources.Rows[nUpdatePanelID].FindControl("pnlSkillsetsMain") as UpdatePanel;
GridView grdSkillsets = pnlSkillsetsMain.Controls[0].FindControl("CascadingSkillsets1").FindControl("grdSkillsets") as GridView;
grdSkillsets.DataBind();

ModalPopupExtender.Hide();

I abandoned my efforts to do this in a seperate window and developed the solution instead using an AJAX ModalPopupExtender. Matt Berseth's example was very helpful.

To update the child grid contained in an update panel within the parent grid, I stored the value of the row from which the button was clicked in a session variable and then using that value called the databind method of the child grid once the user had made their selections and clicked save.

protected void btnShowSkillsetPopup_Click(object sender, EventArgs e)
{
    // get the gridviewrow from the sender so we can get the datakey we need
    Button btnAddSkillsetsFromRow = sender as Button;
    GridViewRow row = (GridViewRow)btnAddSkillsetsFromRow.NamingContainer;

    Session["CapRes_ResourceRequestID"] = Convert.ToString(this.grdResources.DataKeys[row.RowIndex].Value);
    Session["CapRes_SkillsetUpdatePanel_Row"] = Convert.ToString(row.RowIndex);
    ModalPopupExtender.Show();
}

Save code...

int nUpdatePanelID = Convert.ToInt32(Session["CapRes_SkillsetUpdatePanel_Row"].ToString());
UpdatePanel pnlSkillsetsMain = grdResources.Rows[nUpdatePanelID].FindControl("pnlSkillsetsMain") as UpdatePanel;
GridView grdSkillsets = pnlSkillsetsMain.Controls[0].FindControl("CascadingSkillsets1").FindControl("grdSkillsets") as GridView;
grdSkillsets.DataBind();

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