简体   繁体   English

我无法弄清楚为什么我的文本框没有在asp.net中触发我的OnClick c#函数

[英]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. 我是asp.net的新手,我无法弄清楚为什么我的onClick函数没有触发。

Here is my aspx code: 这是我的aspx代码:

<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: 然后我有一个ac#函数,我需要在单击文本框时运行:

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. 您所要做的就是在javascript文件中编写任何内容并在客户端使用它。 To do this, you can dothe following steps: 为此,您可以执行以下步骤:

  1. In your aspx page inside the <head></head> tag include <head></head>标签内的aspx页面中包括

    <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). 在你的javascript文件中写一个函数来做任何你想做的事情(显示日历)。

  3. call that function on any event (onclick) in you aspx. 在你的aspx中的任何事件(onclick)上调用该函数。

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! 事件未触发,因为文本框没有服务器端onClick事件! Try to wire the event up on the client side! 尝试在客户端连接事件!

I'd suggest to go for Ajaxtoolkit calendar control. 我建议去Ajaxtoolkit日历控件。 Have a look at demo here 看看这里的演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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