Using popup window from control in DetailsView - problems assigning value to control

Posted on 2010-11-09
Medium Priority
Last Modified: 2012-05-10
Hi I'm calling a javascript Datepicker function from a TextBox control in DetailsView and after selecting a date I have to assign the date value to my TextBox control.  My controls are named as follows:
Form with ID="form1"
Details view with ID="dvRoute"
TextBox with ID="txtRouteDate"

My code is:
var ctl = "dvRoute_txtRouteDate";
window.opener.document.form1[ctl].value = dateValue;

This is not working - is there another way to do this or is my syntax wrong?

Question by:Lorna70
  • 3
  • 2
LVL 13

Accepted Solution

gamarrojgq earned 1000 total points
ID: 34093154

When you say "is not working" you mean that the date value is not assign or it gives you an error?

You can try with getElementById like this.

window.opener.document.getElementById(ctl).value = dateValue;

Just when your page is loaded, see the Source Code generated in your browser to confirm the name of your Textbox Control.


Author Comment

ID: 34093534
Thanks tried that and still get a similar errorL
Microsoft JScript runtime error: 'window.opener.document.getElementById(...)' is null or not an object

I think my problem is not knowing how to reference a TextBox which is inside a DetailsView which is inside a Form.  I tried:

ctl = "form1_dvRoute_txtRouteDate";
What is the correct syntax for doing this?  Should I be using [] instead of _??
LVL 13

Assisted Solution

gamarrojgq earned 1000 total points
ID: 34093766
That will depend on you page, are you using master pages?

Anyway, the best way to know the real name that is assigned to you textbox is view the Source Code of you page in your browser by right clicking on your page and selecte VIEW SOURCE, and search for you textbox name , in your case txtRouteDate, and you will se the real name.

Besides, if your textbox is inside  a DetailsView perhaps it will have a number somtehing like, txtRouteDate1, txtRouteDate2, etc, depending on the row.

Author Comment

ID: 34094207
OK - my text box is "dvRoute$txtRouteDate" in the source but it still doesn't work.  Should I add the form name to the ctl var before I run:

var ctl = "dvRoute$txtRouteDate"
window.opener.document.getElementById(ctl).value = dateValue;


Author Comment

ID: 34094260
It worked!

For anyone else struggling with this - I went back to using:

var ctl = "dvRoute$txtRouteDate"
window.opener.document.form1[ctl].value = dateValue;

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question