OnServerClick不发射输入类型日期
我正在使用WebForms在ASP.NET中构建Web应用程序。
我有一个输入的HTML元素,我设置为在服务器上运行,并且只要更改日期时就想触发事件。
<input id="datePicker" class="form-control" style="display: inline; margin-left: 5px; width: 15%; text-align: center;" type="date" runat="server" onserverclick="Date_Changed"/>
我在CodeBehind中有活动:
protected void Date_Changed(object sender, EventArgs e) {}
但是,该事件从未被解雇。
I am building a web application in ASP.NET using webforms.
I have an input html element which I have set to run at server and I want to fire an event whenever the date is changed.
<input id="datePicker" class="form-control" style="display: inline; margin-left: 5px; width: 15%; text-align: center;" type="date" runat="server" onserverclick="Date_Changed"/>
I have the event in my codebehind:
protected void Date_Changed(object sender, EventArgs e) {}
However, the event is never fired.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要相信可以将服务器端点击事件连接到以这种方式的输入(使用OnServerClick)。
我会考虑放入HTML按钮,这样说:
甚至更好,请放入ASP.NET按钮。
如果您放入输入标签,那么我认为您无法获得ASP.NET系统来为您连接它。您可以想写以下内容:(
这是上面按钮的平面jane:
因此您可以尝试 - 但是使用“输入”标签我不相信会起作用,但是请尝试使用上述HTML按钮 - 单击”。
请记住,如果您在ASP.NET文本框中删除,并设置TextMode =“ date”
“
允许
? 。
上面是内置功能 - 您根本不需要JS,Bootstrap或任何内容
。 )运行您的点击事件。首先使用ASP.NET(这意味着要利用所有内置控件,并为您提供这些控件的预处理)。
Don't believe that server side click events can be wired up to a input that way (using the onserverclick).
I would consider dropping in a HTML button, say like this:
And even better yet, drop in a asp.net button.
If you drop in a input tag, then I don't think you can get the asp.net system to wire this up for you. You could I suppose write this:
(this is what a plane jane above button becomes:
So you could try above - but using a "input" tag I don't believe will work, but try a HTML button as per above - that does allow "on server click".
Do keep in mind that if you drop in a asp.net text box, and set textmode = "date"?
Say like this:
Then you see this:
So, above is a built in feature - you don't need any js, bootstrap, or anything at all.
but, you could add a "client" side click to your markup, as I posted a above the do post-back would (should) run your click event. However, it probably a whole lot better to not fight asp.net, since then you quite much hand coding a lot of HTML, and doing that means you quite much toss out most of the features of why you would use asp.net in the the first place (that means to take advantage of all the built in controls, and the pre-processing of those controls for you).