TextBox OnClick event without Javascript

假装没事ソ 提交于 2019-12-13 04:44:50

问题


I have a textbox which I want it to be fired on Click. I read some forum in which I wrapped in LinkButton. Here is my mockup UI part:

 <asp:LinkButton runat = "server" OnClick = "txtAgentName_TextChanged"><asp:TextBox ID="txtAgentName" runat="server"></asp:TextBox></asp:LinkButton>

And this is my code behind:

  protected virtual void txtAgentName_TextChanged(object sender, EventArgs e)
    {

    }

And it seems like it is not firing up! I dont want to use Javascript :-P


回答1:


the asp textbox control does not have a server side click event. "OnClick" renders an html "OnClick" attribute for the textbox. Your code will result in a javascript error.

your best bet is to do an ajax call to a WebMethod when the textbox blur event is fired and do something to the textbox based on the result. this article will help you with the webmethod call. using jquery you can handle the blur event pretty easily.



来源:https://stackoverflow.com/questions/5733876/textbox-onclick-event-without-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!