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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.