OnServerClick不发射输入类型日期

发布于 2025-01-25 07:19:53 字数 426 浏览 3 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海之角 2025-02-01 07:19:53

不要相信可以将服务器端点击事件连接到以这种方式的输入(使用OnServerClick)。

我会考虑放入HTML按钮,这样说:

<button id="datePicker" 
 class="form-control" 
 style="display: inline; margin-left: 5px; width: 15%; text-align: center;" 
 type="date" 
 runat="server" onserverclick="Date_Changed" />

甚至更好,请放入ASP.NET按钮。

如果您放入输入标签,那么我认为您无法获得ASP.NET系统来为您连接它。您可以想写以下内容:(

这是上面按钮的平面jane:

<input onclick="__doPostBack('Button11','')" 
 name="Button11" type="button" id="Button11" value="button">

因此您可以尝试 - 但是使用“输入”标签我不相信会起作用,但是请尝试使用上述HTML按钮 - 单击”。

请记住,如果您在ASP.NET文本框中删除,并设置TextMode =“ date”

        <asp:TextBox ID="MyDateTest" runat="server" TextMode="date">
        </asp:TextBox>

允许

? 。

​上面是内置功能 - 您根本不需要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:

<button id="datePicker" 
 class="form-control" 
 style="display: inline; margin-left: 5px; width: 15%; text-align: center;" 
 type="date" 
 runat="server" onserverclick="Date_Changed" />

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:

<input onclick="__doPostBack('Button11','')" 
 name="Button11" type="button" id="Button11" value="button">

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:

        <asp:TextBox ID="MyDateTest" runat="server" TextMode="date">
        </asp:TextBox>

Then you see this:

enter image description here

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文