Filling a textbox on a parent web user control from a child

This is a discussion on "Filling a textbox on a parent web user control from a child" within the ASP.NET Forum section. This forum, and the thread "Filling a textbox on a parent web user control from a child are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > ASP.NET Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 25th, 2004, 10:58
New Member
Join Date: Oct 2004
Location: United Kingdom
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Filling a textbox on a parent web user control from a child

Hi,

I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code:

function OpenChild()
{

var strImageFile;
var WinSettings = "height=580,width=630,status=yes,toolbar=no,menuba r=no,location=no";

window.open("pf_stockimage.aspx", null, WinSettings);

}

Which obviously open a child webform. From here the user can select something from a listbox and the click another button, which then hopefully passes back the selected value to the textbox on the parent user control. Code so far is:

function PassSelectedImage()
{

var lstImages = document.forms[0].lstImages;
var i = lstImages.selectedIndex;

window.opener.document.forms[0].txbSelectedImage.value = lstImages.options[i].value;
window.close();

}

My problem is that I get an erorr stating that above is null or not an object. How do I reference the textbox that is sitting inside the user control (ID is generated at runtime), which is also sittting in another usercontrol (I know the ID of this one) on a webform (default.aspx, which as a form called Form1).

  #2 (permalink)  
Old Oct 25th, 2004, 13:30
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Have you tried referencing your control via "getElementById"? E.G.,

window.opener.document.forms[0].getElementById("txbSelectedImage").value = lstImages.options[i].value;

HTH
  #3 (permalink)  
Old Oct 25th, 2004, 14:25
New Member
Join Date: Oct 2004
Location: United Kingdom
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Tried that... all I get then is an error message stating "Object doesn't support this property or method"...
  #4 (permalink)  
Old Oct 25th, 2004, 21:34
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
On your popup page, give the form tag a name:

Code: Select all
<form name="myform">
and then in your line of code:
Code: Select all
window.opener.document.forms[0].txbSelectedImage.value = lstImages.options[i].value;
alter to:
Code: Select all
window.opener.document.forms[0].txbSelectedImage.value = document.myform.lstImages.options[i].value;
I tried your above code and got nothing, I then referenced fully the source option and got a result.

If you are still having problems getting the value from your selected item in your popup, try this:
Code: Select all
var item = document.myform.lstImages.selectedIndex
window.opener.document.forms[0].txbSelectedImage.value = document.myform.lstImages.options[item].value;
Also just a remember point, if you are calling objects given an ID over a NAME, you will need to use getElementById("..."). But I bet you already know that from the previous posts
HTH
  #5 (permalink)  
Old Oct 26th, 2004, 08:55
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
This belongs in the javascript section...
  #6 (permalink)  
Old Oct 26th, 2004, 13:22
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
You sure this is not jscript.net?
  #7 (permalink)  
Old Oct 26th, 2004, 15:24
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
yeah fairly sure! what do you reckon?
  #8 (permalink)  
Old Oct 26th, 2004, 19:58
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
I am not sure I had a look at jscript.net and they looked very much the same. Either way, you are correct, because this would still not be asp.net, but jscript.net.

Ohh, how I love egg on my face .
  #9 (permalink)  
Old Oct 27th, 2004, 08:06
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
nah its cool mate, if its got .NET in it somewhere, then it belongs here!
Closed Thread

Tags
filling, textbox, parent, web, user, control, child

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Child div expand to fit parent? linchpin311 Web Page Design 5 Apr 20th, 2008 21:16
Javascript Parent and Child menu in Safari?? TR123 JavaScript Forum 3 Mar 8th, 2007 14:15
Submitting a parent form from a child window in IE 7 livehed JavaScript Forum 0 Feb 15th, 2007 16:23
parent child forms mrproggie ASP.NET Forum 1 Aug 12th, 2006 17:49
Parent Child accesssing greenkhan ASP.NET Forum 1 Jun 20th, 2005 09:21


All times are GMT. The time now is 22:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43