roshambo
roshambo

Reputation: 107

I can't figure out why my textbox isn't firing my OnClick c# function in asp.net

I'm new to asp.net and I can't figure out why my onClick function isn't firing.

Here is my aspx code:

<asp:TextBox ID="TextBox1" runat="server" OnClick="TextBox1_OnClick"></asp:TextBox>

I then have a c# function that I need to run when the textbox is clicked:

protected void TextBox1_OnClick(object sender, EventArgs e)
{
    //do stuff
}

Upvotes: 0

Views: 123

Answers (3)

stripthesoul
stripthesoul

Reputation: 360

The event is not firing because there is no server side onClick event for textbox! Try to wire the event up on the client side!

Upvotes: 0

antony.ouseph.k
antony.ouseph.k

Reputation: 907

You should really consider using client side coding for this scenario. why do you have to go to the server to display a calender on click of a text box. All you have to do is write whatever is to be done in a javascript file and use it in client side. To do this, you can dothe following steps:

  1. In your aspx page inside the <head></head> tag include

    <script type="text/javascript" language="javascript" src="YourJavaScriptFile.js"></script>

  2. In your javascript file write a function to do whatever you want (display the calender).

  3. call that function on any event (onclick) in you aspx.

I am not giving you the code as such because

  • you might need a custom code for your scenario.
  • you will have to do a bit more research.
  • the basics of what is to be done has been covered.

Enjoy coding.

Upvotes: 2

Karthick Raju
Karthick Raju

Reputation: 1

I'd suggest to go for Ajaxtoolkit calendar control. Have a look at demo here

Upvotes: 0

Related Questions