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

TextChanged Textbox event won't fire when text is changed programatically

I have a text box

<asp:textbox id="txtMyTextBox" onblur="return ValidateDate(this);" Autopostback="True" EnableViewState="True" tabIndex="2" runat="server" CssClass="DataEntry"></asp:textbox>

The server side textchanged event fires when I type text into this and then navigate away from the text box.  However, when I programatically insert text into the text box a postback does not occur.

In this case a date is placed in the textbox by a client side calendar control.  How can I get this event to fire and the form to postback when the date is placed in the textbox?

I'm running Microsoft Visual Studio .Net 2008.  Client side is ASP .Net, Server side is VB .Net.  Framework is V3.5.

Thanks in advance,

-R
0
RedneckWonderland
Asked:
RedneckWonderland
  • 5
  • 2
  • 2
1 Solution
 
souvik2008Commented:
Place the textbix with in an asp update panel.
0
 
RedneckWonderlandAuthor Commented:
nmarun,

That link would be helpful if I weren't for the fact that I am not trying to get the textchanged event to fire for each keystroke.  In a web based application that would be ludicrous.

I am perfectly happy for the textchanged event to fire when the textbox loses focus.  The problem is that it doesn't do that when the text is changed programatically.
0
Technology Partners: 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!

 
RedneckWonderlandAuthor Commented:
souvik2008,

Thanks for the suggestion souvik.  Can you explain how the asp updatepanel will help me with this problem?  Will placing the textbox inside the updatepanel automatically cause my server side textchanged event to fire when the text property of my text box is programatically changed?

Thanks,

-R
0
 
RedneckWonderlandAuthor Commented:
I'd be happy enough for a server side version of the onBlur event.
0
 
souvik2008Commented:
<asp:textbox id="txtMyTextBox" onblur="return ValidateDate(this);" Autopostback="True" EnableViewState="True" tabIndex="2" runat="server" CssClass="DataEntry"></asp:textbox>

For your code above , the onblur is not a recognised event and it doesn't get trigger to call the javascript function. Use the onTextChanged event to perform server side code and from that event is triggeres you can call the javascript function. But remember javascript doen't recognise asp controls like asp textbox . So try to call javascript function by this

string clid=txtMyTextBox.ClientID;
ValidateDate(clid);
 
//in javascript:
function validateDate(id)
{
      var value=document.getElementById(id).value;

Open in new window

0
 
RedneckWonderlandAuthor Commented:
OnBlur is a recognised client side event.  I managed to sort this out by adding a __doPostback() to the onblur event.

You're wrong about javascript not recognising the asptextbox.  The validation sitting on that onBlur event works fine and has for years.  I can see the value of the textbox simply by using document.all.txtMyTextBox.
0
 
RedneckWonderlandAuthor Commented:
Can this be closed given that I resolved it myself?
0
 
nmarunCommented:
Yes, just select one of your posts and mark it for PAQ.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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