Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

How to Call/Reference a TextBox control on the client side

How do I call or reference a textbox control on the client side.  I have a JavaScript pop-up calendar and it works fine in my classic ASP application but now I cannot work out how to call the textbox, have tried so many combinations.

Here is the some of the code

<td valign="baseline">
<asp:textbox id="PreferredDateA" text='<%# rsViewBookingsDetail.FieldValue("PreferredDateA", Container) %>' TextMode="SingleLine" Columns="32" runat="server" ReadOnly="true" /></td>
<td valign="baseline"><img src="images/calendar.gif" width="22" height="17" border="0" onclick='showCalendar(this, document.all('PreferredDateA'),"dd/mm/yyyy",null,0,-1,305)'>
<asp:RequiredFieldValidator runat="server" ID="date1" ControlToValidate="PreferredDateA" ErrorMessage = "Please select a Preference Date "/></td>

I don't know why .NET does not conform to the DOM model 'document.form1.textbox1....... why do they make it harder not easier.  

I know maybe its b/c its all run at the server but why can't I reference the textbox easily.
  • 3
  • 3
1 Solution
You can use this to retrieve the textbox's client-side ID:

<%= this.PreferredDateA.ClientID %>

then you can grab the textbox from the popup using this:

window.opener.document.forms(0).[control's clientid].value = '[new value]';
simonettajAuthor Commented:
Okay so how could I integrate this into the below part I need it to be an onclick event of the image tag.

'showCalendar(this, document.all('PreferredDateA'),"dd/mm/yyyy",null,0,-1,305)'>

Could I put this in <%= this.PreferredDateA.ClientID %>

'showCalendar(this, document.all('<%= this.PreferredDateA.ClientID %>'),"dd/mm/yyyy",null,0,-1,305)'>


Ramesh SrinivasTechnical ConsultantCommented:
To reference an asp.net control you can use:




Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

If you want to pass the reference to the textbox, use this:

<img ... onclick='showCalendar(this, document.getElementById("<%= PreferredDateA.ClientID %>"),"dd/mm/yyyy",null,0,-1,305)'>
simonettajAuthor Commented:
Hi BurntSky

I copied and pasted your line of code and it came back with object expected error .

Is there something missing?

Here is the web page if you want to see what is happening.....

Very strange.  I saved the generated .aspx and the popcalendar.js files to my machine and opened it in IE.  It works fine.

This leads me to believe that there's some other problem... a confliction of some sort with another javascript function maybe?  Try making a copy of the page and eliminating pieces of it until the problem disappears.

If it wasn't 2:30am here and this question was worth more than 125 points I might be of more help.  If I think of something else, I'll let you know.
simonettajAuthor Commented:
Thanks burnt sky it works I have in include the JavaScript code within the page itself and not as a reference file for some reason.

James Simonetta.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now