简体   繁体   English

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

[英]How do I trigger an update panel postback from a child page?

I have an update panel in a cell for each row within a gridview. 我在gridview中的每一行的单元格中都有一个更新面板。 The user clicks a link button from this update panel to display (using window.open()) a popup. 用户单击此更新面板上的链接按钮以显示(使用window.open())弹出窗口。 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. 我正在研究捕获window.close事件,并以某种方式传递一个值,该值指示从何处调用弹出窗口,然后在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. 如果有什么不同(至少会-在我的JavaScript代码中会这样),我使用的是母版页,并且仅针对IE进行编码。

Found this: http://forums.asp.net/p/1166328/1941797.aspx which uses the window.opener.document... Again, using a master page complicates matters. 发现了这一点: http : //forums.asp.net/p/1166328/1941797.aspx ,它使用window.opener.document ...再次,使用母版页会使事情变得复杂。

You can use javascript function __doPostBack('eventTarget','eventArgument'). 您可以使用javascript函数__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. 在服务器端,您应该使用Update Panel并带有UpdateMode = Conditional和隐藏按钮,如rick schott所说。 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. 如果将OnClick链接为hiddenbutton,则在调用__doPostBack时将触发该事件。 You can access Request.Form["__EVENTARGUMENT"] from server side to access value that __doPostBack sent. 您可以从服务器端访问Request.Form [“ __ EVENTARGUMENT”]以访问__doPostBack发送的值。 You can play with this value for instance which cell that need to update. 例如,您可以使用此值进行操作,以更新需要更新的单元格。

I have done this from a Flash application. 我已经从Flash应用程序完成了此操作。 My "hack" if you will was to hide a real ASP:Button with CSS. 我的“ hack”方法是用CSS隐藏真正的ASP:Button。 The button was inside the UpdatePanel. 该按钮位于UpdatePanel内部。 I passed the Button.ClientId to the external resource(Flash, new window...etc). 我将Button.ClientId传递给外部资源(Flash,新窗口等)。 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. 当外部资源(在我的情况下为Flash)完成时,它调用一个接受ClientId的JavaScript函数,并在按钮上调用.Click()。

JavaScript: 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" />

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. 弹出窗口可以使用window.opener将值存储在这些隐藏字段中。

You can expand your window.open function to update a javascript variable on the page with a reference to the caller: 您可以展开window.open函数,以使用对调用者的引用来更新页面上的javascript变量:

<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. 如果您将隐藏字段设置为asp控件,则可以在更新面板的回发中访问它们。

Edit: 编辑:

Consider a modalpopup to eliminate issues around people clicking on the calling page while you're expecting them to use the popup. 考虑一个模式弹出窗口,以消除人们在期望他们使用弹出窗口时单击呼叫页面的问题。

The simpler (and working) solution I chose was to implement this using the ModalPopupExtender within a user control in the gridview cell. 我选择的更简单(且可行)的解决方案是使用gridview单元中用户控件内的ModalPopupExtender来实现此目的。 The user control contains the read-only results grid and the ModalPopupExtender. 用户控件包含只读结果网格和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 在更新面板中包装PopupControlId属性中引用的面板的内容
  • Hide and show the modal popup in code behind 在后面的代码中隐藏和显示模式弹出窗口
  • A simple and good example of a gridview using multiple ModalPopupExtenders 一个使用多个ModalPopupExtenders的gridview的简单示例

These Both ways works for me 这两种方式都对我有效

(1) Via referencing ChildPage from MasterPAge (1)通过从MasterPAge引用ChildPage

  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. 这段代码在母版页中,然后在我的按钮上单击“我正在使用contentplaceholder在其中查找控件的引用”。 Here dvwOrder is my DataView and "upOrders" is my UpdatePanel. 这里dvwOrder是我的DataView,“ upOrders”是我的UpdatePanel。

(2) Via Delegates (2)通过代表

Put this delegate and eventhandler on Master Page outside any method 将此委托和事件处理程序放在任何方法之外的母版页上

  public delegate void RefreshButtonClickHandler(object 

sender, EventArgs e); 发送者,EventArgs e); public event RefreshButtonClickHandler onRefreshButtonClick; 公共事件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 然后在子页面的Page_Load方法中将此事件与本地处理程序联系起来

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

Child .RefreshButtonClickHandler(reports_onRefreshButtonClick); 子.RefreshButtonClickHandler(reports_onRefreshButtonClick);

Here Child is my codebehind file's name 这里的孩子是我的代码隐藏文件的名称

create 创造

    void child_onRefreshButtonClick(object sender, EventArgs e)
    {

    }

and you are done 你完成了

I abandoned my efforts to do this in a seperate window and developed the solution instead using an AJAX ModalPopupExtender. 我放弃了在单独的窗口中执行此操作的精力,而是使用AJAX ModalPopupExtender开发了解决方案。 Matt Berseth's example was very helpful. Matt Berseth的例子非常有帮助。

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. 为了更新父网格内更新面板中包含的子网格,我将单击按钮的行的值存储在会话变量中,然后在用户完成操作后使用称为子网格的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();
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在异步回发期间更新页面? - How do I update a page during an asynchronous postback? 如何在使用回发触发器时查找子页面控件 - How to find child page control while using postback trigger 更新面板内的异步文件上传和触发回发的下拉菜单不起作用 - Asynchronous file upload inside a update panel and a dropdown to trigger postback not working 如何在不重新加载页面的情况下触发更新面板 - How to trigger an Update Panel without Page Loading all again 如何在单击按钮时阻止更新面板刷新? - How do I stop an update panel from refreshing on button click? 如何从另一个子表单更新一个子表单 - How do I update a child form from another child form RegisterStartupScript似乎不在更新面板中的页面回发上工作 - RegisterStartupScript doesn't appear to be working on page postback within update panel 当按钮位于更新面板内时,如何从内容页面调用母版页方法? - How do you call master page methods from a content page when the button is inside an update panel? 如何避免每次回发后页面跳动? - How do I keep my page from jumping around after every postback? 当用户从页面回发的下拉列表中选择任何项时,我想立即调用函数吗? - I want to call a function immediately as the user select any item from dropdown on page postback how to do it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM