0

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

6
  • Please explain what you mean by "fired", if you need a change in the website without reloading, javascript is the only way.(As vbscript support has been dropped) Commented Apr 20, 2011 at 16:56
  • 4
    As soon as you say "onclick" you already are using javascript. Most ASP.NET server controls need javascript to support server side event triggering. Commented Apr 20, 2011 at 16:59
  • hhhmmm...so if I want to use JS. What do I need to do then? Commented Apr 20, 2011 at 17:08
  • Do you realize that you try to make post back on just click on the text box ? Commented Apr 20, 2011 at 17:13
  • 1
    Sounds like you might need to rethink this one. If you postback every time someone changes the value of the textbox, that is going to get really annoying really quickly. If you need something to happen each time some changes the value of a textbox, you should really be using JavaScript to handle everything associated with those changes... including whatever it is you are doing on the server-side. What is your ultimate goal? What are you doing on the textbox change? Commented Apr 20, 2011 at 18:19

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.