I am trying to reference a text box in a parent/opening window from a popup window using javascript. For a normal HTML input text box it works fine, but I cannot get it to work with an ASP Textbox.
I can use window.opener.document.getElementById("Text1").value to get the value from the normal HTML text box, but the same doesn't work for the ASP textbox. If I try it, I get the error “Object required”. Likewise, I have tried using
..to access the element on the page. Obviously you must do this lookup after the page has rendered the textbox otherwise it will error. (Make sure that isn't your problem before reading the rest.)
However if you have the textbox inside a component (ascx) that is then added to the aspx you will find that the id is altered by .NET due to it assuming you are too stupid to manage your own id's and make them unique. This means if you have a textbox that is part of a component that has the class name of "myComponent", you will find that while you use the same asp:textbox code as shown above, it is actually rendred on the client with an id of "myComponent_foo". Somewhat frustrating as you are expecting the id to be minus the prefix.
If this is the problem then there are several solutions to it. One of them is to provide the prefix to the client as well. You sort of do it already with your code via the .clientID property. Passing that down to the client will provide you with the runtime prefix that is applied.
Other than that you can wrap your textbox inside a non web control, like so..
This whole re-writing of the id is a right pain in the ass (if that is your problem) and can only be properly resolved by overwriting the HTML writer class and that raises problems itself.
Hope that helps.
Essential Links: DOM | JS | CSS
--- #javascript on EfNet:Direct Link
--- I've known you since you were a twenty, and I was twenty, and thought that some years from now, a purple little, little, lady will be perfect, for this dirty old and useless clown... Gogol Bordello
That would only work if the form had the name of "Form1". The .NET framework doesn't automatically add that.
There is also the debate about using name attributes on anything other than form elements, and not the form tag itself, but as VS2003 produces code that at best will validate xhtml 1.0 transitional it's probably a moot point.
Essential Links: DOM | JS | CSS
--- #javascript on EfNet:Direct Link
--- I've known you since you were a twenty, and I was twenty, and thought that some years from now, a purple little, little, lady will be perfect, for this dirty old and useless clown... Gogol Bordello
The value that gets passed using javascript between a popup window and parent opener window, cannot be recorded in the program on Submit button. The passed value reflects in the textbox in parent/opener window but when Submit button is clicked, the contents of the textbox posted onto the database show they are blank which means it just superficially shows that passed value in textbox but not recorded into it.
The value that gets passed using javascript between a popup window and parent opener window, cannot be recorded in the program on Submit button. The passed value reflects in the textbox in parent/opener window but when Submit button is clicked, the contents of the textbox posted onto the database show they are blank which means it just superficially shows that passed value in textbox but not recorded into it.
Thanks,
Dipti
My textbox on parent form was readonly. Changing that solved the problem. Thanks.
Bookmarks