Passing variable back to parent page

Hi,
I am new to .NET and I am struggling with something quite simple.
Basically I have an ASPX page that calls a ASCX file. The ASCX file has a form field and a calendar button. The calendar button launches a popup window which passes back the selected date to the parent window,form field. The problem is: the form field name always changes because it's in a control. In the ASCX page I call the asp:textbox - txtSetupDate. If I view source after the page has been rendered in IE the form field name is name="_ctl0:txtSetupDate"

Because the name changes The javascript cannot pass the value back to the parent page. I can't even assume the name will be _ctl0:txtSetupDate because javascript does not loike the use of :

How can I overcome this????
keyparkerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TimCotteeConnect With a Mentor Commented:
Firstly, you should use:

document.getElementById('_ctl0_txtSetupDate')

Instead of referencing the Name property of the control. The ID property is more reliable and can be used in these situation.

Additionally you should determine the name of the control using the .ClientID property of the control. An example would be something like this (add a command button to your ascx control called cmdTest)

In the page_load event of your ascx control add:

cmdTest.Attributes.Add("onclick","window.alert('You clicked\n" & cmdTest.ClientID & "');return false;")

Then run it and click the button, you can see that it will give you the full ID of the button including any _ctl0 etc.

Using this you can send the relevant ID property to the popup window so that it can use document.getElementById method to set the relevant value back in the parent form.
0
All Courses

From novice to tech pro — start learning today.