Deverill
Deverill

Reputation: 971

Responding to TextBox change done by JavaScript

I have a button that I want to open a calendar and then disappear until a calendar date is selected. The calendar is legacy code in ASP classic and updates a textbox on my ASP.NET form when the user picks a date via JavaScript. I already have everything working except the disappear/reappear of the button.

Button:

<asp:Button ID="AddToCartButton" runat="server" Text="Reserve" OnClick="AddToCartButton_Click"  />

TextBox:

<asp:TextBox ID="ReservationDate" style="padding-left:10px;" runat="server" AutoPostBack="true" ReadOnly="false" visible="true" CssClass="BlankTextBox" Columns="25" OnTextChanged="ReservationDateSelected"/>                      

The button opens a calendar, passing the identity of the textbox so the calendar can put the chosen date in it via JS. I want the button to disappear when clicked, which I can do with button.visible = false, but the TextBox obviously does not respond to OnTextChanged when JS fills it.

How can I make set button.visible = true when the calendar uses JS to fill the textbox?
Thanks!

Upvotes: 1

Views: 695

Answers (2)

Adam Tuliper
Adam Tuliper

Reputation: 30162

Use the

onchange
event right inline - this isn't known by asp.net and will be rendered out and called via javascript. Set your button visibility in that procedure

See:

http://connect.microsoft.com/VisualStudio/feedback/details/103428/textbox-onclientchange-property-addition

Upvotes: 1

rick schott
rick schott

Reputation: 21112

Add this in your js where appropriate:

<asp:Button ID="AddToCartButton" onclientclick="this.display='none';" 
      runat="server" Text="Reserve" OnClick="AddToCartButton_Click"  />

//show after calender click
document.getElementById('<% = AddToCartButton.ClientID').display = 'block'; 

Upvotes: 1

Related Questions