简体   繁体   中英

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 ac# function that I need to run when the textbox is clicked:

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

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.

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!

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

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