Monday, July 17, 2006

Got stuck with ASP.NET Popup Windows: With Return Values???

I am sure we have written so many Java scrpits to open a popup window and return values to the parent page. In my case I have used this line within the Java script to get values from the popup Window.
document.getElementById('txtDateValue').innerText=returnVal._date

This Code works perfect in normal forms but I got a javascript error when the Parent page uses a master page(wich is in VS2005), I was wondering. Got through.... ;)

Problem is because ASP adds the name of the content placeholder to the front of the text box when generating the html. If you do a right-click, 'view source' on the parent page, scroll down to where the html is for the text box and look at the ID. Thats what we have to specify as the name in the document.getelementbyid command.

For a Example :

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

For this ContentPlaceHolder, Your java script shold be:

document.getElementById('ctl00$ContentPlaceHolder1$txtDateValue').value = returnVal._date;

2 comments:

Anonymous said...

Do not hardcode the id of your textbox and containers.

Assuming that the Javascript is generated in the server side, you can use the txtDateValue.ClientID to get the id of the textbox after it renders.

Using this method you don't have to re write the javascript when you switch containers or use multiple instances of your control/user control.

cps2005lk said...

Tnx Buddy i will try on this method Toooo. Tnx a lot