Javascript popup does not see parent page fields

Asked

Viewed 76 times

0

I have a query in a popup that the result is returned in a gridview. In gridview I have a button where I call a javascript function that inserts the result by correlating the return of the query with the fields of the main page. I’m getting into the job, but when I get to the part that makes the relationship, the mistake arises:

window.opener.Document.frm is Undefined

The excerpt:

 window.opener.document.frm.txtDS_PES.value = trim(pesnm);

In firebug I identified that from frm.txtDES_PES.value he from Undefined.

<form id="frm" runat="server">
  • Try to check if you can access opener with var opener = window.opener; if(opener) {//Test}

  • That’s not the case. Because I can access another page, just not the objects.

1 answer

0


Create a function on your normal page (not the popup) to update the values according to the ids.

function atualizaValor(id, value)
{
    document.getElementById(id).value = value;
}

And then in your popup just call:

window.opener.atualizaValor('txtDS_PES', trim(pesnm));
  • I have about 20 fields to do this update. It won’t get heavy?

  • I don’t think so, after all it’s 20 tags different right?

  • Error: Typeerror: Document.getElementById(...) is null, funny is that it recognizes the other page and still recognizes the function.

  • as you know who recognizes the other page?

  • Because I’m doing the fire bug Debug! Even I put a break point on the main page and it enters the updateValue.

  • so the problem is in your tags, you have some input with the ID txtDS_PES?

  • or this txtDS_PES is the name?

  • the problem is that in addition to passing the value to a Visible=false textbox, I was passing the ID name correctly. Because when the site is rendered, the components change their name. The solution was to pass the ContentPlaceHolder1_ in front of the field. Example: Contentplaceholder1_txtds_pes and on the page, instead of passing a Visible=false field, I used the Asp:Hiddenfield component. Now the problem is that when I close the popup the data that went to the main screen disappears.

  • When you close the popup is not doing some postback to previous screen, no?

  • Updates <span> tags but when I give a window.close() in the popup the information on the n parent screen remains. I don’t want the parent screen to refresh, because I have two more popup accesses to do before playing on the bench. I don’t want to have to go to the server to do this!

  • Try to use UpdatePanel not to force the update, if you want we can go chat

  • It worked with Updatepanel. Thank you!

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.