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
and that gives the same error, while
gives me the error “The name 'Text2' does not exist in the current context”
How do I reference an ASP text box in the parent window like the above?
I would need to see the html in the aspx code.
In general if you have..
<asp:textbox id="foo" runat="server"/>
..you should be able to simply use..
..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..
<span id="myTextbox"><asp:textbox id="foo" runat="server"/></span>
You still need the id/runat for the web control, but the containing span is not amended by the .NET framework. With that you can do..
..to pick up the element.
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.
That would only work if the form had the name of "Form1". The .NET framework doesn't automatically add that.
Originally Posted by webdevmj
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.
The code was used in a user control that can be loaded in a web form with default id "Form1"
My textbox on parent form was readonly. Changing that solved the problem. Thanks.
Originally Posted by desai14
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)