• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Make a Change on a .NET Web Form from a Popup

I have a simple example but I look for a general principle in how to do.

I have a web form, webform1, with a lable control Lable1. From webform1 I open a popup, popup1, with e.g.

function PopupOpen()
{
    window.open('Test.aspx', '_blank', 'width=900,height=450,top=312,left=190,scrollbars=1')
}

in the script section:

<script type="text/javascript" language="javascript">

With the popup1 open and active, my question is how can I in popup1 make a change to Lable1 in webform1?
0
Kim Neesgaard
Asked:
Kim Neesgaard
  • 3
  • 2
1 Solution
 
Ryan McCauleyCommented:
I'm a bit unclear on the question, but just to be sure, are you trying to modify a value in the first form based on activity in the pop-up window? If so, I believe it's called a "cross-domain iFrame", and you can see a demo here:

http://www.codeproject.com/Tips/585663/Communication-with-Cross-Domain-IFrame-A-Cross-Bro

While not an exact demo of what you're looking for, it demonstrates communication across windows and should cover the concept you'll use to do this. If I've missed your question, please provide some additional details and I'll update my answer.
0
 
Kim NeesgaardAuthor Commented:
Hi ryanmccauley!

I have tried the solution in the link but as the demo is not exact and I never have worked with iFrames, I cannot complete the example.

However, I have actually found another solution that I can describe for you and possible coming readers!

I have a parent web form and a popup web form (.aspx).

In the parent form I open the popup with RegisterStartupScript in the codebehind and this javascript:

window.open('Popup.aspx', '_blank', 'width=440,height=250,top=312,left=190,scrollbars=0,resizeable=no,title=no')

In the popup I attach this to the button that closes the popup:

btn.Attributes.Add("onclick", "AdjustMotherControls();")

When the user closes the form, some controls on the parent form are changed with Javascript:

<script type="text/javascript">

    function AdjustMotherControls() {
        document.getElementById('lblInfo').innerHTML = 'Some text...'
        mother = opener.document;
        mother.getElementById('ctl00_ContentPlaceHolder1_lblInfo').innerHTML = 'Some other text…';
        mother.getElementById('ctl00_ContentPlaceHolder1_btnSave').disabled = true;
        mother.getElementById('ctl00_ContentPlaceHolder1_btnPrint').disabled = false;
    }

</script>

'ctl00_ContentPlaceHolder1_lblInfo' is the name that Windows assign to the controls in the parent form and I know that you should not use these but I have not been able to find a more correct alternative and these works very well.
0
 
Ryan McCauleyCommented:
Glad to hear it. Does this resolve your original question, or is there still something outstanding that you need addressed?
0
 
Kim NeesgaardAuthor Commented:
The described functionality solves the original question. The only 'outstanding' (though it works) is a better way to indicate 'ctl00_ContentPlaceHolder1_lblInfo'. I read on the web that Windows COULD change the name (I have not experienced it) but I could not make the proposals work. However, perhaps this belongs to another question.
0
 
Kim NeesgaardAuthor Commented:
Through another source it got information on how to solve this problem and I like to share this solution  with EE so therefore I selected 'my own' answer as the solution.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now