简体   繁体   中英

Updating textbox within UpdatePanel from codebehind of another page that is in an iframe in asp.net C#

I have a web application that I'm working on. On the parent page I have a status text box within an UpdatePanel . There is an iframe on the parent page that on page load executes some codebehind function in C# that happens to take a long time. (Quite a few lines of code get executed)

I was wondering how I could call out to the parent page from within the iframe s code behind and do Updates on the UpdatePanel at various times in the function.

Here is some of the html from the main page:

<asp:UpdatePanel ID="StatusPanel" ClientIDMode="Static" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
    <asp:TextBox ClientIDMode="Static" ID="txtStatus" runat="server" Width="99%" Enabled="False"></asp:TextBox>
  </ContentTemplate> 
</asp:UpdatePanel>    

And some of my c# codebehind from the iframe:

foreach (CorpLead lead in leadsPriority1)
{
    UpdateStatus(lead.name);
    xRMData.AssignCorpLead(agentProfiles, lead, service);
}

private void UpdateStatus(string lead)
{
    if (this.Parent.FindControl("txtStatus") != null)
    {
        ((TextBox)this.Parent.FindControl("txtStatus")).Text = lead;
        ((UpdatePanel)this.Parent.FindControl("StatusPanel")).Update();
    }    
}

Without some code examples it's just a guess for your specific problem but you can access controls on the parent page like so:

if (this.Parent.FindControl("ControlID") != null)
{
    ((Control)this.Parent.FindControl("ControlID")).Property = value;
}

Is this what you're looking for?

Since your IFRAME calls a function - it can call a function of the parent page (I am talking about JavaScript function). That parent function can use setInterval to programmatically "click" on a hidden LinkButton control which is set as a trigger for your UpdatePanel.

Result: UpdatePanel is refreshed at given intervals

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM