简体   繁体   中英

Why changing text of Textbox by Javascript does not trigger OnTextChanged in Asp .Net

I am using Visual Studio 2012. It contains the following textbox:

<asp:TextBox ID="txtdate" runat="server" OnTextChanged="txtdate_TextChanged" AutoPostBack="true"></asp:TextBox>
<img src="../img/scw.gif" title='Click Here' alt='Click Here' onclick="scwShow(scwID('ContentPlaceHolder1_txtdate'),this); setcalender();" />

On clicking on the image a Calendar opens in which the user can select the date. Now if I enter the date manually by typing and then press the Enter key txtdate_TextChanged method is called but the change has to be done using the Calender. So I want to know why and how the browser/server is able to detect that the change is being done by Javascript.

And is there any way I can call the txtdate_TextChanged method in javascript.

Thanks in advance.

As you are saying that you click on the image and not the textbox it means that the textbox was never in focus and javascript functions do not trigger server side functions if they are called along with the server side functions like

  <asp:Button runat ="server" ID="btn" OnClick="btn_Click" OnClientClick="return check();" />

where in javascript function check() you do your validations and return true.

So you have to do this in javascript on the onclick eventof your Calender

__doPostBack("txt_sssn_dt", "TextChanged");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM