How do I force the re-transmission of the refresh panel from the child page?

I have an update panel in a cell for each row in a gridview. The user clicks a link button on this refresh bar to display (using window.open ()) a popup. In this pop-up window, an action is taken that updates the data contained in the aforementioned refresh panel. I want to trigger an update for this update bar only when the popup is closed.

What's the best way to do this? I am looking into capturing the window.close event and somehow passing in a value indicating where the popup is called from and then triggering a postback for that refresh bar in javascript. If it matters (at least it will be - ugh - in my javascript code), I am using the master page and only the encoding for IE.

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

+2


source to share


6 answers


You can use javascript function __doPostBack ('eventTarget', 'eventArgument'). On the client side, it might look like this.

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

      



on the server side you have to use the update bar with UpdateMode = conditional and hidden button as Rick Schott says. The hard part is knowing which cell needs to be updated. If you hooked OnClick on hiddenbutton then it will fire this event when __doPostBack is called. You can access Request.Form ["__ EVENTARGUMENT"] from the server side to access the value that __doPostBack sent. You can play with this value, for example a cell that needs to be updated.

+1


source


I did it from a Flash application. My hack if you want to hide the real ASP: Button with CSS. The button was inside the UpdatePanel. I have passed Button.ClientId to an external resource (Flash, new window ... etc). When the external resource (Flash in my case) has finished, it calls a JavaScript function that takes a 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" />

      

0


source


You can use hidden fields in the calling page to store any values ​​your callback needs. The popup can use window.opener to store the values ​​in these hidden fields.

You can extend your window.open function to update the 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 create hidden asp controls then you will have access to them on postback of the refresh panel.

Edit:

Let's take a look at modalpopup to fix issues for people clicking on the calling page while you expect them to use the popup.

0


source


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

A few key elements that finally led me to a working solution ...

  • Wrap the content of the pane referenced by the PopupControlId property in the update pane
  • Hide and show modal popup in code
  • Simple and good gridview example using multiple ModalPopupExtenders
0


source


These both sides work for me

(1) Via the ChildPage link from MasterPAge

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

      

This code is inside the homepage and on my button click I am using content site to find the control link inside it. Here dvwOrder is my DataView and "upOrders" is my UpdatePanel.

(2) Through delegates

Place this delegate and event handler on the master page outside of any method

    public delegate void RefreshButtonClickHandler(object

      

sender, EventArgs e); public event RefreshButtonClickHandler onRefreshButtonClick;

inside a class in your button click click do this

        if(null == onRefreshButtonClick)
        {
            return;                
        }

        onRefreshButtonClick(sender, e);

      

Then in the Children section of the Page_Load Method bind this event to a local handler

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

      

Child .RefreshButtonClickHandler (reports_onRefreshButtonClick);

Here Child is my codebehind file name

to create

    void child_onRefreshButtonClick(object sender, EventArgs e)
    {

    }

      

and you're done

0


source


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

To update the child grid contained in the update pane in the parent grid, I saved the value of the row from which the button was clicked in a session variable, and then using that value, called the child grid binding method, after the user made their selection and hit 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();

      

0


source







All Articles